Beispiel #1
0
    def __init__(self, position=(0, 0), name="simple", d=1, bHand=0, collisionGroup=None):
        """Init using IR class."""
        global bDebug
        self.name = name
        self.ini_pos = position
        self.salientMode = "all"
        self.circle = createCircle(position, r=d * 0.6, bDynamic=True, density=1, name="wheel")
        self.box = createBox((position[0], position[1] + d * 1.9), d * 0.2, d * 2, bDynamic=True, density=1)
        self.joint = myCreateRevoluteJoint(self.circle, self.box, position, iswheel=True)
        self.bHand = bHand

        self.IR = IR(1)
        self.box.userData["name"] = name
        self.box.userData["nIR"] = 1

        if(name == "cartLeft"):
            self.IR.IRAngles = [0]
        else:
            self.IR.IRAngles = [np.pi]

        self.box.userData["IRAngles"] = self.IR.IRAngles
        self.box.userData["IRValues"] = self.IR.IRValues

        if(bHand > 0):
            body = self.box
            h = d * 0.15
            w = d * 0.4
            pos = (2 * w - d * 0.2, 0)
            if(bHand == 2):
                pos = (-2 * w + d * 0.2, 0)
            fixtureDef = createBoxFixture(pos, width=w, height=h, collisionGroup = collisionGroup)
            body.CreateFixture(fixtureDef)

        self.motor_speed = 0
        self.angle = 0
    def iniThreeObjects(self, pos_obj, obj_type):
        self.objs.append(createCircle(pos_obj, r=0.45))
        self.objs.append(createTri(pos_obj, r=0.45))
        self.objs.append(createBox(pos_obj, wdiv=1, hdiv=1, w=0.35, h=0.35))

        self.target_objs = []
        self.target_objs.append(createCircle(pos_obj, r=0.45))
        self.target_objs.append(createTri(pos_obj, r=0.45))
        self.target_objs.append(
            createBox(pos_obj, wdiv=1, hdiv=1, w=0.35, h=0.35))
        for t in self.target_objs:
            t.active = False
            t.position = [2, 4]

        x = -2
        for o in self.objs:
            o.position, x = (x, 4), x + 1

        if (obj_type == "circle"):
            self.obj, self.target_obj = self.objs[0], self.target_objs[0]
        elif (obj_type == "box"):
            self.obj, self.target_obj = self.objs[2], self.target_objs[2]
Beispiel #3
0
def addCircle(who,
              pos=(0, 0),
              vel=(0, 0),
              bDynamic=False,
              bCollideNoOne=False):
    r = 1.06  # PREVIOUSLY WAS 0.75
    obj = createCircle(position=pos,
                       bDynamic=bDynamic,
                       bCollideNoOne=bCollideNoOne,
                       density=0,
                       r=r)
    obj.userData["energy"] = 1.0
    obj.userData["visible"] = 1.0
    obj.linearVelocity = vel
    def iniConstrainedObject(self, pos_obj):
        obj = createCircle(pos_obj, r=0.3, density=0.01, name="ball")
        self.objs.append(obj)
        obj.position = [0, 1.5]
        self.obj = self.objs[0]
        obj.userData["name"] = "toy"

        bar = createBox(obj.position,
                        w=1,
                        h=0.001,
                        bDynamic=False,
                        bCollideNoOne=True)
        bar.userData["name"] = "bar"

        self.joint = myCreateLinearJoint(bar,
                                         obj,
                                         force=0,
                                         lowerTranslation=-0.82,
                                         upperTranslation=0.82)
Beispiel #5
0
def addReward(who,
              pos=(0, 0),
              vel=(0, 0),
              reward_type=0,
              bDynamic=True,
              bCollideNoOne=False):
    if (reward_type == 0):
        name, r = "reward", 0.27
    else:
        name, r = "reward_small", 0.2

    obj = createCircle(position=pos,
                       bDynamic=bDynamic,
                       bCollideNoOne=bCollideNoOne,
                       density=10,
                       name=name,
                       r=r)
    obj.userData["energy"] = 1.0
    obj.userData["visible"] = 1.0
    obj.linearVelocity = vel
    who.objs.append(obj)
Beispiel #6
0
    def __init__(self, position=(0, 0), angle=np.pi / 2, r=0.48, bHorizontal=False, frontIR=6, nother=0, nrewsensors=0):
        """Init of userData map with relevant values."""

        self.ini_pos = position
        self.body = createCircle(position, r=r, bDynamic=True, restitution=0, name="epuck")
        self.body.angle = angle
        self.r = r
        # self.body = createBox(position, w=0.2,h=0.2,bDynamic=True)
        self.motors = [0, 0]
        self.bHorizontal = bHorizontal
        self.bForceMotors = True

        self.frontIR = frontIR
        self.IR = IR(frontIR)

        self.body.userData["nIR"] = frontIR
        self.body.userData["IRAngles"] = self.IR.IRAngles
        self.body.userData["IRValues"] = self.IR.IRValues

        self.GradSensors = []

        self.body.userData["nOtherSensors"] = nother
        self.nother = nother
        if(nother > 0):
            otherGrad = GradSensor(nother, name="other")
            self.GradSensors.append(otherGrad)
            self.body.userData["OtherAngles"] = otherGrad.GradAngles
            self.body.userData["OtherValues"] = otherGrad.GradValues

        self.nrewardsensors = nrewsensors
        self.body.userData["nRewardSensors"] = nrewsensors
        if(nrewsensors > 0):
            rewGrad = GradSensor(nrewsensors, name="reward")
            self.GradSensors.append(rewGrad)
            self.body.userData["RewardAngles"] = rewGrad.GradAngles
            self.body.userData["RewardValues"] = rewGrad.GradValues

        self.userData = self.body.userData
Beispiel #7
0
    def __init__(self,
                 position=(0, 0),
                 angle=np.pi / 2,
                 r=0.48,
                 bHorizontal=False,
                 frontIR=6,
                 nother=0,
                 nrewsensors=0,
                 RGB=[255, 0, 0],
                 bodyType='circle',
                 categoryBits=0x0001,
                 name='epuck',
                 maskBits=0x0009):
        """Init of userData map with relevant values."""

        self.ini_pos = position
        if bodyType == 'circle':
            self.body = createCircle(position,
                                     r=r,
                                     bDynamic=True,
                                     restitution=0,
                                     name=name,
                                     categoryBits=categoryBits,
                                     maskBits=maskBits)
        elif bodyType == 'square':
            self.body = createBox(position,
                                  w=r,
                                  h=r,
                                  wdiv=1,
                                  hdiv=1,
                                  bDynamic=True,
                                  restitution=0,
                                  name=name,
                                  categoryBits=categoryBits,
                                  maskBits=maskBits)
        self.body.angle = angle
        self.r = r

        self.motors = [0, 0]
        self.bHorizontal = bHorizontal
        self.bForceMotors = True

        self.frontIR = frontIR
        self.IR = IR(frontIR)

        self.RGB = RGB

        self.body.userData["nIR"] = frontIR
        self.body.userData["IRAngles"] = self.IR.IRAngles
        self.body.userData["IRValues"] = self.IR.IRValues
        self.body.userData["RGB"] = self.RGB
        self.body.userData["radius"] = self.r

        self.GradSensors = []

        self.body.userData["nOtherSensors"] = nother
        self.nother = nother
        if (nother > 0):
            otherGrad = GradSensor(nother, name="other")
            self.GradSensors.append(otherGrad)
            self.body.userData["OtherAngles"] = otherGrad.GradAngles
            self.body.userData["OtherValues"] = otherGrad.GradValues

        self.nrewardsensors = nrewsensors
        self.body.userData["nRewardSensors"] = nrewsensors
        if (nrewsensors > 0):
            rewGrad = GradSensor(nrewsensors, name="reward")
            self.GradSensors.append(rewGrad)
            self.body.userData["RewardAngles"] = rewGrad.GradAngles
            self.body.userData["RewardValues"] = rewGrad.GradValues

        self.userData = self.body.userData