views:

101

answers:

1

I've created a two wheeled robot based on the braitenberg vehicle. Our robots have two wheels and a PolygonDisk body(Much like kepera and e-puck robots). I would like to add a camera to the front of the robot. The problem then becomes how to control the camera and how to keep pointing it in the right direction(same direction as the robot). How can you make the camera point in the same direction as the robot ?

+1  A: 

After much trying and failing I finally made it work. So here is how I did it:

The general idea is to have an link or object linked to the vehicle and then measuring its rotation and location in order to find out in which direction the camera should be aimed.

1) Add an object that is linked to the robot:

def addVisualCam(self):
    joint = None
    cam = breve.createInstances(breve.Link,1)
    cam.setShape(breve.createInstances(breve.PolygonCone, 1).initWith(10,0.08,0.08))
    joint = breve.createInstances(breve.FixedJoint,1)
    # So ad-hoc it hurts. oh well...
    joint.setRelativeRotation(breve.vector(0,1,0), -3.14/2)
    joint.link(breve.vector(0,1.05,0), breve.vector(0,0,0), cam, self.vehicle.bodyLink, 0)
    joint.setDoubleSpring(300, 1.01000, -1.01000)
    self.vehicle.addDependency(joint)
    self.vehicle.addDependency(cam)
    cam.setColor(breve.vector(0,0,0))
    self.cam = cam

2) Add this postIterate:

def postIterate(self):
    look_at = self.cam.getLocation() + (self.cam.getRotation() * breve.vector(0,0,1))
    look_from = -(self.cam.getRotation()*breve.vector(0,0,1))
    self.vision.look(look_at, look_from)
Kjeld