コード例 #1
0
class Bot:
    def __init__(self):
        self.bot = Controller() # servo controller for the Tango bot

    # accelerate allows the gradual acceleration of the Tango bot, ensuring it does not fall over
    def accelerate(self, port, target, t):
        pos = self.position(port) # find the current speed of the wheels
        dist = target - pos # how far we have to accelerate
        direction = -1 if dist < 0 else 1 # the direction of acceleration

        # incrementally set the speed of the wheels to the target speed
        for _ in range(abs(dist)):
            pos += 1 * direction
            self.bot.setTarget(port, pos)
            time.sleep(t)

    # bendTurn allows the Tango bot to turn or bend at one of its' joints
    def bendTurn(self, port, target):
        self.bot.setTarget(port, target)

    def position(self, port):
        return self.bot.getPosition(port)

    def wait(time):
        time.sleep(time)
コード例 #2
0
 def __init__(self):
     self.tango = Controller()
     print(self.tango)
     self.body = 6000
     self.headTurn = 6000
     self.headTilt = 6000
     self.motors = 6000
     self.turn = 6000
コード例 #3
0
 def __init__(self):
     self.pololu_serial_communication = ''
     pololu_communication_port = ''
     for port in comports():
         if port[2].find('VID:PID=1ffb:0089') > -1:
             pololu_communication_port = port[0]
     try:
         self.pololu_serial_communication = Controller(pololu_communication_port)
     except Exception:
         raise PololuSerialConnectionFailed()
コード例 #4
0
class RPS:
    def __init__(self, port='dummy'):
        #define some targets
        self.OPEN = 7900
        self.CLOSED = 4900
        self.port = port
        self.open_controller(self.port)
        #straighten all the fingers
        self.paper()
        
        #make a fist
        self.rock()
    def rock(self,delay=0.01):
        #make a fist
        self.rps_controller.setTarget(0,self.CLOSED+300)
        self.rps_controller.setTarget(1,self.CLOSED)
        self.rps_controller.setTarget(3,self.CLOSED-200)
        time.sleep(delay)
    def paper(self,delay=0.01):
        #make an open palm
        self.rps_controller.setTarget(0,self.OPEN)
        self.rps_controller.setTarget(1,self.OPEN)
        self.rps_controller.setTarget(3,self.OPEN)
        time.sleep(delay)
    def scissors(self,delay=0.01):
        #make scissors
        self.rps_controller.setTarget(0,self.OPEN)
        self.rps_controller.setTarget(1,self.OPEN)
        self.rps_controller.setTarget(3,self.CLOSED-200)
        time.sleep(delay)
    def open_controller(self,port):
        if port=="dummy":
            self.rps_controller = dummyController()
        else:
            self.rps_controller = Controller(ttyStr=port)
    def close_controller(self):
        self.rps_controller.close()
コード例 #5
0
 def open_controller(self,port):
     if port=="dummy":
         self.rps_controller = dummyController()
     else:
         self.rps_controller = Controller(ttyStr=port)
コード例 #6
0
from maestro import Controller
import time

c0 = Controller()

for i in range(18):
    c0.setSpeed(i, 60)
    c0.setAccel(i, 30)

RIGHT_SHOULDER_UD = 6
RIGHT_SHOULDER_LR = 7
RIGHT_ELBOW = 8
RIGHT_WRIST_UD = 9
RIGHT_WRIST_ROTATE = 10
RIGHT_HAND = 11

LEFT_SHOULDER_UD = 12
LEFT_SHOULDER_LR = 13
LEFT_ELBOW = 14
LEFT_WRIST_UD = 15
LEFT_WRIST_ROTATE = 16
LEFT_HAND = 17

MIN = 3000
MID = 6000
MAX = 9000


def open_close(n):
    for i in range(n):
        c0.setTarget(RIGHT_HAND, MIN)
コード例 #7
0
class KeyControl():
    def __init__(self, win):
        self.root = win
        self.tango = Controller()
        print(self.tango)
        self.body = 6000
        self.headTurn = 6000
        self.headTilt = 6000
        self.motors = 6000
        self.turn = 6000

    def arrow(self, key):
        print(key.keycode)
        # Forward
        if int(key.keycode) in keys_dict["up"]:
            self.motors -= move_increment
            if (self.motors <= 1000):
                self.motors = 1000
            print("Forward")
            print(self.motors)
            self.tango.setTarget(MOTORS_FORWARD, self.motors)
        # Backward
        if key.keycode in keys_dict["down"]:
            self.motors += move_increment
            if (self.motors >= 8000):
                self.motors = 8000
            print("Backward")
            print(self.motors)
            self.tango.setTarget(MOTORS_FORWARD, self.motors)
        # Left
        if key.keycode in keys_dict["left"]:
            self.turn += turn_increment
            if (self.turn > 8000):
                self.turn = 8000
            print("Left")
            print(self.turn)
            self.tango.setTarget(MOTORS_TURN, self.turn)
        # Right
        if key.keycode in keys_dict["right"]:
            self.turn -= turn_increment
            if (self.turn < 1000):
                self.turn = 1000
            print("Right")
            print(self.turn)
            self.tango.setTarget(MOTORS_TURN, self.turn)
        # Stop
        if key.keycode in keys_dict["stop"]:
            print("Stop")
            self.motors = 6000
            self.turn = 6000
            self.tango.setTarget(MOTORS_FORWARD, self.motors)
            self.tango.setTarget(MOTORS_TURN, self.turn)
        # Turn-stop
        if key.keycode in keys_dict["turn-stop"]:
            print("Turn-stop")
            self.turn = 6000
            self.tango.setTarget(MOTORS_TURN, self.turn)
        # Waist left
        if key.keycode in keys_dict["waist-left"]:
            self.body += waist_increment
            if (self.body > 8000):
                self.body = 8000
            print(self.body)
            self.tango.setTarget(WAIST_TURN, self.body)
        # Waist right
        if key.keycode in keys_dict["waist-right"]:
            self.body -= waist_increment
            if (self.body < 1000):
                self.body = 1000
            print(self.body)
            self.tango.setTarget(WAIST_TURN, self.body)
        # Waist center
        if key.keycode in keys_dict["waist-center"]:
            self.body = 6000
            print(self.motors)
            self.tango.setTarget(WAIST_TURN, self.body)
        # Head left
        if key.keycode in keys_dict["head-left"]:
            self.headTurn += head_increment
            if self.headTurn > 8000:
                self.headTurn = 8000
            print(self.headTurn)
            self.tango.setTarget(HEAD_TURN, self.headTurn)
        # Head right
        if key.keycode in keys_dict["head-right"]:
            self.headTurn -= head_increment
            if self.headTurn < 1000:
                self.headTurn = 1000
            print(self.headTurn)
            self.tango.setTarget(HEAD_TURN, self.headTurn)
        # Head center
        if key.keycode in keys_dict["head-center"]:
            self.headTurn = 6000
            print(self.headTurn)
            self.tango.setTarget(HEAD_TURN, self.headTurn)
        # Head tilt up
        if key.keycode in keys_dict["head-tilt-up"]:
            self.headTilt += head_tilt_increment
            if self.headTilt > 8000:
                self.headTilt = 8000
            print(self.headTilt)
            self.tango.setTarget(HEAD_TILT, self.headTilt)
        # Head tilt down
        if key.keycode in keys_dict["head-tilt-down"]:
            self.headTilt -= head_tilt_increment
            if self.headTilt < 1000:
                self.headTilt = 1000
            print(self.headTilt)
            self.tango.setTarget(HEAD_TILT, self.headTilt)
        # Head tilt center
        if key.keycode in keys_dict["head-tilt-center"]:
            self.headTilt = 6000
            print(self.headTilt)
            self.tango.setTarget(HEAD_TILT, self.headTilt)
コード例 #8
0
from maestro import Controller
#from gui_control import stt_block
import time
import threading, socket

c0 = Controller()
stt_block = True

BODY = 0
FORWARD_BACK = 1
LEFT_RIGHT = 2
HEAD_TURN = 3
HEAD_TILT = 4

# Enumerate positions
MIN = 3000
MID = 6000
MAX = 9000

c0.setTarget(BODY, MID)

#Setting restrictions for all servos
c0.setRange(HEAD_TILT, MIN, MAX)
c0.setRange(HEAD_TURN, MIN, MAX)
c0.setRange(BODY, MIN, MAX)
c0.setRange(FORWARD_BACK, MIN, MAX)
c0.setRange(LEFT_RIGHT, MIN, MAX)

#Setting speeds for all servos
c0.setSpeed(HEAD_TILT, 60)
c0.setSpeed(HEAD_TURN, 60)
コード例 #9
0
 def __init__(self):
     self.bot = Controller() # servo controller for the Tango bot
コード例 #10
0
# main entry point
########################################################

# parse any commandline arguments
parser = argparse.ArgumentParser(description="flip mask and lamp control programme");

if (platform.uname()[0] == "Darwin"):
  parser.add_argument("serial_port", type=str, nargs='?', default=SERIAL_PORT, help='serial port name. Default: '+ SERIAL_PORT);

if(platform.uname()[0] == "Windows"):  
  parser.add_argument("serial_port", type=str, nargs='?', default=SERIAL_PORT, help='serial port name. Default: ' + SERIAL_PORT);
args = parser.parse_args();

# completed parsing the commandline arguments and let's open the serial port etc.
try:
  servo = Controller(args.serial_port);
except serial.SerialException:
  print("flipit.py: cannot open ", args.serial_port);
  exit();

servo.setSpeed(FLIP_MASK, MASK_SERVO_SPEED);
servo.setAccel(FLIP_MASK, MASK_SERVO_ACCEL);
servo.setSpeed(FLIP_LAMP, LAMP_SERVO_SPEED);
servo.setAccel(FLIP_LAMP, LAMP_SERVO_ACCEL);

# for some stupid reason the above speeds and accelerations
# don't seem to be executed until the first command is sent
servo.setTarget(FLIP_MASK, FLIP_MASK_OFF*4);
servo.setTarget(FLIP_LAMP, FLIP_LAMP_OFF*4);

# Print out the current state of the flip mask and lamp
コード例 #11
0
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
inx = 640
iny = 480
camPos = 4000
MOTORS = 1  # left motor
TURN = 2  # opposite
BODY = 0
HEADTILT = 4
HEADTURN = 3

# allow the camera to warmup
time.sleep(3)
myC = Controller()
#myC.setTarget(1,0)
#myC.setTarget(1, 6000)
#myC.setTarget(2, 6000)


def reset():
    camPos = 4000
    myC.setTarget(BODY, 6000)
    myC.setTarget(MOTORS, 6000)
    myC.setTarget(TURN, 6000)
    myC.setTarget(HEADTURN, 6000)
    myC.setTarget(HEADTILT, 4000)


def cog():