Пример #1
0
class ButtonController():
    def __init__(self,win):
        self.root = win
        self.tango = Controller()
        self.body = default_pos
        self.headturn = default_pos
        self.headtilt = default_pos
        self.motors = 0
        self.turn = 0
        self.tango.setAccel(motors, default_accel)
        self.tango.setAccel(full_turn,default_accel)
        for i in range(1,6):
                self.tango.setTarget(i,default_pos)

                
    def t1(self):                               # Head Tilt
        self.tango.setTarget(h_tilt, 7000)
        self.tango.setTarget(h_tilt, 5000)
        self.tango.setTarget(h_tilt, 6000)


    def t2():                                   # Head Turn
        self.tango.setTarget(h_turn, 7000)
        self.tango.setTarget(h_turn, 5000)
        self.tango.setTarget(h_turn, 6000)


    def t3():                                   # Torso Turn
        self.tango.setTarget(body, 7000)
        self.tango.setTarget(body, 5000)
        self.tango.setTarget(body, 6000)


    def t4():                                   # Forward (7000) for 1.5s
        self.tango.setTarget(motors, 7000)
        time.sleep(1.5)
        self.tango.setTarget(motors, 6000)


    def t5():                                   # Backwards(5000) for 1.5s
        self.tango.setTarget(motors, 5000)
        time.sleep(1.5)
        self.tango.setTarget(motors, 6000)


    def t6():                                   # Turn clockwise
        self.tango.setTarget(full_turn, 7000)
        time.sleep(0.1)


    def t7():                                   # Turn counter-clockwise
        self.tango.setTarget(full_turn, 7000)
        time.sleep(0.1)
Пример #2
0
class Korby():

    ## initialize a Korby object with an instance of the Maestro controller
    ## init to work with cam's code
    def __init__(self, win):
        ## init to work with alex's code
        #    def __init__(self):
        self.root = win
        self.x = Controller()

    ## set body, head, wheels to middle/not moving
    def reset(self):
        self.x.setTarget(0, 6000)
        self.x.setTarget(1, 6000)
        self.x.setTarget(2, 6000)
        self.x.setTarget(3, 6000)
        self.x.setTarget(4, 6000)

        self.x.setTarget(6, 4500)  #right shoulder up and down
        self.x.setTarget(7, 7000)  #right shoulder in and out
        self.x.setTarget(8, 5000)  #right elbow
        self.x.setTarget(9, 4500)  #right wrist up and down
        self.x.setTarget(10, 6000)  #right wrist left and right
        self.x.setTarget(11, 1000)  #right hand open and close

        self.x.setTarget(12, 5500)  #left shoulder up and down
        self.x.setTarget(13, 7500)  #left shoulder in and out
        self.x.setTarget(14, 6000)  #left elbow
        self.x.setTarget(15, 5500)  #left wrist up and down
        self.x.setTarget(16, 6000)  #left wrist left and right
        self.x.setTarget(17, 6000)  #left hand open and close

    def runArms(self):
        self.x.setTarget(6, 9000)
        self.x.setTarget(8, 9000)
        time.sleep(float(1))
        self.x.setTarget(10, 8000)
        time.sleep(float(0.5))
        self.x.setTarget(10, 4000)
        time.sleep(float(0.5))
        self.x.setTarget(10, 6000)
        time.sleep(float(0.7))
        self.reset()

    def fightArm(self):
        #self.x.setTarget(0, 4000)
        #self.x.setTarget(3, 7000)

        self.x.setAccel(6, 5)
        self.x.setAccel(7, 5)
        self.x.setAccel(8, 5)

        self.x.setTarget(6, 9000)
        self.x.setTarget(8, 9000)
        self.x.setTarget(7, 9000)

        time.sleep(float(1.3))

        self.x.setAccel(6, 255)
        self.x.setAccel(7, 255)
        self.x.setAccel(8, 255)

        time.sleep(float(0.5))

        self.x.setTarget(7, 7000)
        self.x.setTarget(8, 4000)
        time.sleep(float(0.1))
        self.x.setTarget(6, 8000)

    ## set body, head, wheels to middle/not moving
    def middle(self, key):
        self.x.setTarget(0, 6000)
        self.x.setTarget(1, 6000)
        self.x.setTarget(2, 6000)
        self.x.setTarget(3, 6000)
        self.x.setTarget(4, 6000)

        self.x.setTarget(6, 4500)  #right shoulder up and down
        self.x.setTarget(7, 7000)  #right shoulder in and out
        self.x.setTarget(8, 7000)  #right elbow
        self.x.setTarget(9, 4500)  #right wrist up and down
        self.x.setTarget(10, 6000)  #right wrist left and right
        self.x.setTarget(11, 6000)  #right hand open and close

        self.x.setTarget(12, 5500)  #left shoulder up and down
        self.x.setTarget(13, 7500)  #left shoulder in and out
        self.x.setTarget(14, 4000)  #left elbow
        self.x.setTarget(15, 5500)  #left wrist up and down
        self.x.setTarget(16, 6000)  #left wrist left and right
        self.x.setTarget(17, 6000)  #left hand open and close

    ## move body to the left a little
    def moveBodyLeft(self, key):
        change = 900
        position = x.getPosition(0)
        if position < 8000:
            self.x.setTarget(0, position + change)

    ## move body to the right a little
    def moveBodyRight(self, key):
        change = 900
        position = self.x.getPosition(0)
        if position > 3000:
            self.x.setTarget(0, position - change)

    def moveBody(self, position):
        print('body at Korb position is', position)
        self.x.setTarget(0, position)

    def nodHead(self, position):
        self.x.setTarget(4, position)

    def turnHead(self, position):
        self.x.setTarget(3, position)

    ## move head to the right a little
    def moveHeadRight(self, key):
        change = 900
        position = self.x.getPosition(3)
        if position > 2500:
            self.x.setTarget(3, position - change)

    ## move head to the left a little
    def moveHeadLeft(self, key):
        change = 900
        position = self.x.getPosition(3)
        if position < 8000:
            self.x.setTarget(3, position + change)

    ## move head up a little
    def moveHeadUp(self, key):
        change = 900
        position = self.x.getPosition(4)
        if position < 8000:
            self.x.setTarget(4, position + change)

    ## move head down a little
    def moveHeadDown(self, key):
        change = 900
        position = self.x.getPosition(4)
        if position > 2800:
            self.x.setTarget(4, position - change)

    def moveWheels(self, speed):
        self.x.setTarget(1, speed)

    def turnWheels(self, speed):
        self.x.setTarget(2, speed)

    ## change wheels to move forward faster
    def moveForward(self, key):
        change = 300
        position = self.x.getPosition(1)
        if position > 4800:
            self.x.setTarget(1, position - change)

    ## change wheels to move backward faster
    def moveBackward(self, key):
        change = 300
        position = self.x.getPosition(1)
        if position < 7200:
            self.x.setTarget(1, position + change)

    ## change wheels to turn left
    def turnLeft(self, key):
        position = self.x.getPosition(2)
        if position == 6000:
            self.x.setTarget(2, 7000)
        elif position == 5000:
            self.x.setTarget(2, 6000)

    ## change wheels to turn right
    def turnRight(self, key):
        position = self.x.getPosition(2)
        if position == 6000:
            self.x.setTarget(2, 5000)
        elif position == 7000:
            self.x.setTarget(2, 6000)

    ## stop wheels
    def stop(self, key):
        self.x.setTarget(1, 6000)
        self.x.setTarget(2, 6000)

    def endProgram(self, key):
        sys.exit()
Пример #3
0
# 0 <- body
# 1 <- wheel
# 2 <- wheel
# 3 <- head left/right
# 4 <- head up/down
# forward 2400 - 1800
# reverse 6300 - 7100

x.setTarget(1, 6000)
x.setTarget(2, 6000)

x.setSpeed(1, 30)
x.setSpeed(2, 30)

x.setAccel(1, 150)

low_range = 4000
high_range = 5000


def take_instr(direction):
    global low_range
    global high_range

    if direction == '8':
        curr_pos = x.getPosition(4)
        x.setTarget(4, curr_pos + 800)
    elif direction == '2':
        curr_pos = x.getPosition(4)
        x.setTarget(4, curr_pos - 800)
Пример #4
0
class Move:
    def __init__(self):
        self.servo = Controller()
        #self.root = tk.Tk()
        os.system('xset r off')
        #set targets to neutral
        for i in range(17):
            self.servo.setTarget(i, neutral)
            self.servo.setSpeed(i, 0)
            self.servo.setAccel(i, 60)

        self.servo.setAccel(drive_target, 6)

    #move head up
    def w_pressed(self):
        global head_angle
        if head_angle < 9000:
            head_angle += 1500
        self.servo.setTarget(head_target, head_angle)

    #move head down
    def s_pressed(self):
        global head_angle
        if head_angle > 3000:
            head_angle -= 1500
        self.servo.setTarget(head_target, head_angle)

    #move neck left
    def a_pressed(self):
        global neck_angle
        if neck_angle < 9000:
            neck_angle += 1500
        self.servo.setTarget(neck_target, neck_angle)

    #move neck right
    def d_pressed(self):
        global neck_angle
        if neck_angle > 3000:
            neck_angle -= 1500
        self.servo.setTarget(neck_target, neck_angle)

    #body turn left
    def q_pressed(self):
        self.servo.setTarget(body_target, 8600)

    def q_released(self):
        self.servo.setTarget(body_target, neutral)

    #body turn right
    def e_pressed(self):
        self.servo.setTarget(body_target, 3400)

    def e_released(self):
        self.servo.setTarget(body_target, neutral)

    #drive forward
    def one_forward(self, seconds):
        self.servo.setTarget(drive_target, one_forward)
        time.sleep(seconds)
        self.servo.setTarget(drive_target, neutral)

    #drive backwards
    def one_backward(self, seconds):
        self.servo.setTarget(drive_target, one_backward)
        time.sleep(seconds)
        self.servo.setTarget(drive_target, neutral)

    #turn left
    def turn_left(self, seconds):
        self.servo.setTarget(turn_target, 7000)
        time.sleep(seconds)
        self.servo.setTarget(turn_target, neutral)

    #turn right
    def turn_right(self, seconds):
        self.servo.setTarget(turn_target, 5000)
        time.sleep(seconds)
        self.servo.setTarget(turn_target, neutral)

    def fight(self):
        self.servo.setTarget(head_target, head_angle)
        self.servo.setTarget(6, 3000)
        self.servo.setTarget(12, 3000)
        time.sleep(.5)
        self.servo.setTarget(head_target, neutral)
        self.servo.setTarget(head_target, 3000)
        self.servo.setTarget(6, 8000)
        self.servo.setTarget(12, 8000)
        time.sleep(.5)
        self.servo.setTarget(head_target, neutral)
        self.servo.setTarget(head_target, head_angle)
        self.servo.setTarget(6, 3000)
        self.servo.setTarget(12, 3000)
        time.sleep(.5)
        self.servo.setTarget(head_target, neutral)
        self.servo.setTarget(head_target, 3000)
        self.servo.setTarget(6, 8000)
        self.servo.setTarget(12, 8000)
        time.sleep(.5)
        self.servo.setTarget(head_target, neutral)
        self.servo.setTarget(head_target, head_angle)
        self.servo.setTarget(6, neutral)
        self.servo.setTarget(12, neutral)

    def recharge(self):
        self.servo.setTarget(neck_target, head_angle)
        self.servo.setTarget(9, 3000)
        self.servo.setTarget(16, 3000)
        time.sleep(.5)
        self.servo.setTarget(neck_target, neutral)
        self.servo.setTarget(neck_target, 3000)
        self.servo.setTarget(9, 8000)
        self.servo.setTarget(16, 8000)
        time.sleep(.5)
        self.servo.setTarget(neck_target, neutral)
        self.servo.setTarget(neck_target, head_angle)
        self.servo.setTarget(9, 3000)
        self.servo.setTarget(16, 3000)
        time.sleep(.5)
        self.servo.setTarget(neck_target, neutral)
        self.servo.setTarget(neck_target, 3000)
        self.servo.setTarget(9, 8000)
        self.servo.setTarget(16, 8000)
        time.sleep(.5)
        self.servo.setTarget(neck_target, neutral)
        self.servo.setTarget(neck_target, head_angle)
        self.servo.setTarget(9, neutral)
        self.servo.setTarget(16, neutral)

    #set all servos/motors to neutral
    def space_pressed(self):
        for i in range(5):
            self.servo.setTarget(i, neutral)

    def executeMotion(self, mid, direction, seconds):
        #HEAD
        if mid == 1:
            #if up
            if direction == 1:
                #move head up
                self.w_pressed()
            else:
                #move head down
                self.s_pressed()
        #NECK
        elif mid == 2:
            if direction == 1:
                #neck turn left
                self.a_pressed()
            else:
                #neck turn right
                self.d_pressed()
        #BODY
        elif mid == 3:
            if direction == 1:
                #body turn left
                self.q_pressed()
            else:
                #body turn right
                self.e_pressed()
        #DRIVE
        elif mid == 4:
            if direction == 1:
                #drive forward
                self.one_forward(seconds)
            else:
                #drive backward
                self.one_backward(seconds)
        #TURN
        elif mid == 5:
            if direction == 1:
                self.turn_left(seconds)
            else:
                self.turn_right(seconds)
        #PAUSE
        elif mid == 6:
            time.sleep(seconds)
Пример #5
0
from Maestro import Controller
from tkinter import *
import time
import os
import socket
import threading
import random

# Maestro instantiation
controller = Controller()
for chan in range(len(controller.Targets)):
    controller.setTarget(chan, 6000)
controller.setAccel(0, 10)
controller.setAccel(1, 10)
controller.setAccel(2, 30)
controller.setAccel(3, 20)
controller.setAccel(4, 20)
controller.setAccel(6, 20)
controller.setAccel(7, 20)
controller.setAccel(8, 20)
controller.setAccel(9, 20)
controller.setAccel(10, 20)
controller.setAccel(11, 20)
os.system('xset r off')

# Global Variables
port = 7777

# Socket setup
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.close()
from Maestro import Controller
from tkinter import *
import time
import os
import socket
import threading

# Maestro instantiation
controller = Controller()
for chan in range(len(controller.Targets)):
    controller.setTarget(chan, 6000)
controller.setAccel(0, 10)
controller.setAccel(1, 10)
controller.setAccel(2, 30)
controller.setAccel(3, 20)
controller.setAccel(3, 20)
os.system('xset r off')

# Global Variables
xpos = 0
ypos = 0
actions = []
actions_inv = []
pic_size = 40
port = 7777

# Main Tk window instantiation
root = Tk()
root.title('Robot Control GUI')

# Socket setup
Пример #7
0
class Mover:
    def __init__(self):
        # Maestro instantiation
        self.controller = Controller()
        for chan in range(len(self.controller.Targets)):
            self.controller.setTarget(chan, 6000)
            self.controller.setAccel(0, 10)
            self.controller.setAccel(1, 10)
            self.controller.setAccel(2, 30)
            self.controller.setAccel(3, 20)
            self.controller.setAccel(3, 20)
        os.system('xset r off')

    def move(self, prevOrientation, newOrientation):
        if (prevOrientation == newOrientation):
            self.controller.setTarget(1, 5000)
            time.sleep(.5)
            self.controller.setTarget(1, 6000)

        elif (self.getAxis(prevOrientation) != self.getAxis(prevOrientation)):
            # TODO turn 180 and move forward
            pass

        else:
            leftRight = self.getLeftRight(prevOrientation, newOrientation)
            if (leftRight == "left"):
                # TODO turn 90 left and move forward
                pass
            else:
                # TODO turn 90 right and move forward
                pass

    # get axis of a direction
    def getAxis(self, direction):
        if (direction == "north" or direction == "south"):
            return "ns"
        else:
            return "ew"

    # should robot turn right or left?
    def getLeftRight(self, prevDirection, nextDirection):
        directions = {"north": 0, "east": 1, "south": 2, "west": 3}
        if (prevDirection != "north"):
            if (prevDirection > nextDirection):
                return "left"
        # prevDirection == "north"
        else:
            if (nextDirection == "east"):
                return "right"
            else:
                return "left"

        if (prevDirection != "west"):
            if (prevDirection < nextDirection):
                return "right"
        # prevDirection == "west"
        else:
            if (nextDirection == "north"):
                return "right"
            else:
                return "left"