Esempio n. 1
0
 def brake(self, abTF):
     '''Brake the legs.'''
     lleg = body.getpart(body._LLEG)
     rleg = body.getpart(body._RLEG)
     lleg.brake(abTF)
     rleg.brake(abTF)
     sleep(0.2)
     lrleg.stop()
     rleg.stop()
Esempio n. 2
0
 def _fire(self, abTF):
     '''Fire gun by setting motor speed to 100%, stop by setting to 0%.'''
     p = body.getpart(body._GUN)
     p.value = p.minmax[abTF]
     #Turn smoke generator on/off.
     GPIO.output(sentrybot._SMOKEPIN, GPIO.HIGH if abTF else GPIO.LOW)
     self._gunon = abTF
     self._guntime = 0.0
     sm = body.getpart(body._SMOKE)
     sm.value = sm.minmax[1] if abTF else sm.minmax[0]
Esempio n. 3
0
 def setpartdata(self, aIndex, aRate, aTrim, aMinMax):
     '''Set the rate, trim and min/max values for given part.'''
     p = body.getpart(aIndex)
     if p:
         p.rate = aRate
         p.center = aTrim
         p.minmax = aMinMax
Esempio n. 4
0
    def _togglecombat(self):
        '''Toggle combat stance.'''

        self._stance = sentrybot._PEACE if self._stance != sentrybot._PEACE else sentrybot._COMBAT
        p = body.getpart(body._MISSILES)
        if self._stance == sentrybot._COMBAT:
            #      s = soundchain((sentrybot._combatsfx, 'engaging'), sentrybot._MACHINEGROUP)
            s = sound(sentrybot._combatsfx, sentrybot._MACHINEGROUP)
            s.play()
            p.value = p.minmax[1]
        else:
            p.value = 0.0
            s = soundchain(('sys/two', 'sys/one'), sentrybot._MACHINEGROUP)
            s.play()
Esempio n. 5
0
    def _updateparts(self, aDelta):
        '''Update all servos based on joystick input'''

        rx = -self._joy(gamepad._RX)  #Negate cuz servo is backwards.
        ry = self._joy(gamepad._RY)

        rx = deadzone(rx, 0.01)

        self.checktorso(rx)

        ry = deadzone(ry, 0.01)

        lx = self._joy(gamepad._LX)
        ly = self._joy(gamepad._LY)

        lx = deadzone(lx, 0.01)
        ly = deadzone(ly, 0.01)
        '''
      rx = head, torso, arm horizontal
      ry = right wheel front/back
      lx = Nothing at the moment
      ly = left wheel front/back
    '''

        #If we have a change limit, then use it.
        if self._rate > 0.0:
            if aDelta != 0.0:
                d = self._rate * aDelta
                v = self._rotx + (rx * d)
                self._rotx = min(max(v, -90.0), 90.0)
                v = self._roty + (
                    self._hy * d)  #Use _hy, which is adjusted by l/r triggers.
                self._roty = min(max(v, -90.0), 90.0)
        else:
            v = rx * 90.0
            self._rotx = min(max(v, -90.0), 90.0)
            v = self._hy * 90.0
            self._roty = min(max(v, -90.0), 90.0)

#    print(self._rotx, self._roty, '                ', end='\r')
#    print(rx, ry, '                ', end='\r')

#todo: Figure out how to disperse right stick movement into torso, head and arms.

        t = body.getpart(body._TORSO)
        v = self._rotx / 8.0
        t.value = v
        hh = body.getpart(body._HEAD_H)
        v = -self._rotx / 4.0
        hh.value = v
        hv = body.getpart(body._HEAD_V)
        hv.value = self._roty

        #Only update arms if they are on.  We can turn them off to keep them from overheating.
        if self._armson:
            rarmh = body.getpart(body._RARM_H)
            rarmv = body.getpart(body._RARM_V)
            larmh = body.getpart(body._LARM_H)
            larmv = body.getpart(body._LARM_V)

            #     clampedxy = self.clamparms(self._rotx, self._roty)

            #Rotate x,y by angle and apply to arms.
            armx, army = angle.rotate((self._rotx, self._roty), self._cossinl)
            larmh.value = armx
            larmv.value = army

            larmh.update(aDelta)
            larmv.update(aDelta)

            #     clampedxy = self.clamparms(self._rotx, -self._roty)

            #Note, to invert the right arm use _cossinr.
            armx, army = angle.rotate((self._rotx, -self._roty), self._cossinr)
            rarmh.value = armx
            rarmv.value = army

            rarmh.update(aDelta)
            rarmv.update(aDelta)

        lleg = body.getpart(body._LLEG)
        rleg = body.getpart(body._RLEG)

        lleg.speed = ly * lleg.maxspeed
        rleg.speed = ry * rleg.maxspeed

        lleg.update(aDelta)
        rleg.update(aDelta)

        #    self._gunbutton.update()
        #    if self._gunbutton.pressed:
        #      self._gunindex = 1 - self._gunindex
        #      self._gunsound[self._gunindex].stop()     #Make sure sound is stopped so we can play it again.
        #      self._gunsound[self._gunindex].play()

        g = body.getpart(body._GUN)
        g.update(aDelta)

        #Now play gun sound if gun is on.
        if self._gunon:
            self._guntime -= aDelta
            if self._guntime <= 0.0:
                self._gunindex = 1 - self._gunindex
                self._gunsound[self._gunindex].stop(
                )  #Make sure sound is stopped so we can play it again.
                self._gunsound[self._gunindex].play()
                self._guntime = self._gunrate

        m = body.getpart(body._MISSILES)
        m.update(aDelta)
Esempio n. 6
0
 def turnoff(apart):
     part = body.getpart(apart)
     part.off()
Esempio n. 7
0
 def _setspeed(self):
     '''Set the speed scale value on the legs to the current _speed setting.'''
     lleg = body.getpart(body._LLEG)
     rleg = body.getpart(body._RLEG)
     lleg.scale = rleg.scale = sentrybot._speeds[self._speed]
Esempio n. 8
0
 def partdefminmax(self, aIndex):
     '''Get min/max for given part.'''
     p = body.getpart(aIndex)
     return p._defminmax if p else (-100.0, 100.0)
Esempio n. 9
0
 def partcenter(self, aIndex):
     '''Get rate for given part.'''
     p = body.getpart(aIndex)
     return p.center if p else 0.0
Esempio n. 10
0
 def partrate(self, aIndex):
     '''Get rate for given part.'''
     p = body.getpart(aIndex)
     return p.rate if p else 0.0
Esempio n. 11
0
  def _updateparts( self, aDelta ):
    '''Update all servos based on joystick input'''

    rx = -self._joy(gamepad._RX)                #Negate cuz servo is backwards.
    ry = self._joy(gamepad._RY) * self._invert
    rx = deadzone(rx, 0.01)
    ry = deadzone(ry, 0.01)

    lx = self._joy(gamepad._LX)
    lx = deadzone(lx, 0.01)
    ly = self._joy(gamepad._LY)
    ly = deadzone(ly, 0.01)

    if self._rate > 0.0:
      if aDelta != 0.0:
        d = self._rate * aDelta
        v = self._rotx + (rx * d)
        self._rotx = min(max(v, -90.0), 90.0)
        v = self._roty + (ry * d)
        self._roty = min(max(v, -90.0), 90.0)
    else:
      v = rx * 90.0
      self._rotx = min(max(v, -90.0), 90.0)
      v = ry * 90.0
      self._roty = min(max(v, -90.0), 90.0)

#    print(self._rotx, self._roty, '                ', end='\r')
#    print(rx, ry, '                ', end='\r')

    #todo: Figure out how to disperse right stick movement into torso, head and arms.

    t = body.getpart(body._TORSO)
    t.value = self._rotx / 8.0
    hh = body.getpart(body._HEAD_H)
    hh.value = -self._rotx / 4.0
    hv = body.getpart(body._HEAD_V)
    hv.value = -self._roty
#    print('hh: ', hh.value, '        ', end='\r')
#    print('hv: ', hv.value, '        ', end='\r')

    rarmh = body.getpart(body._RARM_H)
    rarmv = body.getpart(body._RARM_V)
    larmh = body.getpart(body._LARM_H)
    larmv = body.getpart(body._LARM_V)

    #Rotate x,y by angle and apply to arms.
    armx, army = angle.rotate((self._rotx, -self._roty), self._cossinl)
    larmh.value = (armx)
    larmv.value =(army)

    armx, army = angle.rotate((self._rotx, self._roty), self._cossinr)
    rarmh.value = (armx)
    rarmv.value = (army)

    #todo: Update gun servo based on a button input.

#    vl, vr = legs.vels(lx, ly)
    vl = ly
    vr = ry
    lleg = body.getpart(body._LLEG)
    rleg = body.getpart(body._RLEG)

#    print(vl, '    ', end='\r')
    lleg.speed = vl * lleg.maxspeed
    rleg.speed = vr * rleg.maxspeed

    lleg.update(aDelta)
    rleg.update(aDelta)