我基于braitenberg车辆创造了一个两轮机器人。我们的机器人有两个轮子和一个PolygonDisk机身(很像kepera和e-puck机器人)。我想在机器人前面添加一个摄像头。问题就变成了如何控制相机以及如何将其指向正确的方向(与机器人相同的方向)。如何让相机指向与机器人相同的方向?
答案 0 :(得分:1)
经过多次努力和失败后,我终于成功了。 所以我就是这样做的:
一般的想法是将链接或对象链接到车辆然后进行测量 它的旋转和位置,以便找出相机应该瞄准的方向。
1)添加链接到机器人的对象:
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)添加此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)