Example #1
0
 def update(self, pos, angle, r=0.1):
     """Udpate casting ray."""
     for k in range(self.nir):
         v = vrotate((1, 0), angle + self.IRAngles[k])
         c = pos + [0.9 * r * v[0], 0.9 * r * v[1]]
         cdist = pos + [self.maxdist * v[0], self.maxdist * v[1]]
         self.callback.fixture = None
         world.RayCast(self.callback, c, cdist)
         if(self.callback.fixture is not None):
             self.IRValues[k] = dist(c, self.callback.point) / self.maxdist
         else:
             self.IRValues[k] = 1
Example #2
0
 def update(self, pos, angle, r=0.1):
     """Udpate casting ray."""
     for k in range(self.retinaSize):
         v = vrotate((1, 0), angle + self.VSAngles[k])
         c = pos + [0.9 * r * v[0], 0.9 * r * v[1]]
         cdist = pos + [self.maxdist * v[0], self.maxdist * v[1]]
         self.callback.fixture = None
         world.RayCast(self.callback, c, cdist)
         if (self.callback.fixture is not None):
             if 'RGB' in self.callback.fixture.body.userData.keys():
                 self.RGB[k] = self.callback.fixture.body.userData['RGB']
             else:
                 self.RGB[k] = [255, 255, 255]
         else:
             self.RGB[k] = [0, 0, 0]
Example #3
0
    def update(self, pos, angle, centers=[], extremes=0):
        """Update passing agnet pos, angle and list of positions of gradient emmiters."""
        maxd = 6.5
        sensors = range(self.ngrad)
        if(extremes):
            sensors = [0, self.ngrad - 1]

        for k in sensors:
            v = vrotate((1, 0), angle + self.GradAngles[k])
            vals = [0, 0]
            for i, c in enumerate(centers):
                vc = (c[0] - pos[0], c[1] - pos[1])
                d = dist(pos, c)
                if(d > maxd):
                    d = maxd
                vals[i] = ((maxd - d) / maxd) * (1 - abs(vangle(v, vc)) / np.pi)
            self.GradValues[k] = 1 - max(vals)
Example #4
0
 def update(self, pos, angle, r=0.1):
     """Udpate casting ray."""
     for k in range(self.nir):
         v = vrotate((1, 0), angle + self.IRAngles[k])
         c = pos + [0.9 * r * v[0], 0.9 * r * v[1]]
         cdist = pos + [self.maxdist * v[0], self.maxdist * v[1]]
         self.callback.fixture = None
         world.RayCast(self.callback, c, cdist)
         if (self.callback.fixture is not None):
             if 'ignore' in self.callback.fixture.body.userData.keys():
                 self.IRValues[k] = 1
             elif any([
                     ig in self.callback.fixture.body.userData['name']
                     for ig in self.ignoreList
             ]):
                 self.IRValues[k] = 1
             else:
                 self.IRValues[k] = dist(c,
                                         self.callback.point) / self.maxdist
         else:
             self.IRValues[k] = 1
Example #5
0
    def update(self):
        # update the reactive functions
        self.avoid_epuck()
        self.seek_rewards()
        self.apply_forces()
        """update of position applying forces and IR."""
        body, angle, pos = self.body, self.body.angle, self.body.position
        mLeft, mRight = self.motors
        fangle, fdist = 50 * (mRight - mLeft), 1000 * (mLeft + mRight)
        d = (fdist * np.cos(angle), fdist * np.sin(angle))

        if (self.bHorizontal):
            d = vrotate(d, np.pi / 2)

        if (self.bForceMotors):
            body.ApplyTorque(fangle, wake=True)
            body.ApplyForce(force=d, point=body.worldCenter, wake=False)

        if (self.bHorizontal):
            body.angularVelocity = 0
            body.angle = np.pi / 2