コード例 #1
0
class RobotController:
    def __init__(self):
        self.controller = Controller()

        self.body = 0
        self.motor_move = 1
        self.motor_turn = 2
        self.head_vert = 3
        self.head_hor = 4

        self.low_range = 4000
        self.high_range = 5000
        self.kill = 6000

        # must kill motors before starting
        self.controller.setTarget(self.motor_move, self.kill)
        self.controller.setTarget(self.motor_turn, self.kill)

    def turn_body(self, pos):
        self.controller.setTarget(self.body, pos)
        print("Body: ", pos)
        sleep(1)

    def turn_head(self, pin, pos):
        self.controller.setTarget(pin, pos)
        print("Head: ", pin, pos)
        sleep(1)

    def move_motors(self, pin, direction, time, speed=1):
        for i in range(direction*self.low_range, direction*self.high_range, direction): #TODO: Implement speed
            self.controller.setTarget(pin, i)

        sleep(time)

        self.controller.setTarget(pin, self.kill)
コード例 #2
0
 def __init__(self, node, server):
     self.node = node
     self.server = server
     self.done = False
     self.hp = 100
     self.hasKey = False
     self.direction = "South"
     self.control = Controller()
     self.control.setTarget(1, 6000)
コード例 #3
0
ファイル: SetSpeed.py プロジェクト: Penchant/Robot-Movement
 def __init__(self, channel, timeout, speed, parallel=False):
     self.channel = channel
     self.controller = Controller()
     self.speed = speed
     self.controller.setTarget(1, 6000)
     self.controller.setTarget(2, 6000)
     super(SetSpeed, self).__init__(timeout)
     self.parallel = parallel
     return
コード例 #4
0
    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)
コード例 #5
0
 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')
コード例 #6
0
 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)
コード例 #7
0
 def __init__(self, rotateChannel, forwardChannel, controller):
     self._forwardChannel = forwardChannel
     self.controller = controller
     self.controller = Controller()
     self.rotate = 0
     self.forward = 0
     self.enable = False
     self.moveForward = False
     self.moveBackward = False
     self.rotateLeft = False
     self.rotateRight = False
     self.speed = Drivetrain.Slow
     self.stop = False
     self._rotateChannel = rotateChannel
コード例 #8
0
    def __init__(self):
        self.controller = Controller()

        self.body = 0
        self.motor_move = 1
        self.motor_turn = 2
        self.head_vert = 3
        self.head_hor = 4

        self.low_range = 4000
        self.high_range = 5000
        self.kill = 6000

        # must kill motors before starting
        self.controller.setTarget(self.motor_move, self.kill)
        self.controller.setTarget(self.motor_turn, self.kill)
コード例 #9
0
    def run(self):
        global rob
        rob = Controller()
        global q
        q = queue.Queue()
        global count
        count = 0

        win = tk.Tk()
        win.title("Tango Bot")

        moveButton = tk.Button(win,
                               width="12",
                               text="Move",
                               command=Button.createMove)
        turnButton = tk.Button(win,
                               width="12",
                               text="Turn",
                               command=Button.createTurn)
        bodyButton = tk.Button(win,
                               width="12",
                               text="Rotate Body",
                               command=Button.createBody)
        headButton = tk.Button(win,
                               width="12",
                               text="Move Head",
                               command=Button.createHead)
        listenButton = tk.Button(win,
                                 width="12",
                                 text="Listen",
                                 command=Button.createListen)
        speakButton = tk.Button(win,
                                width="12",
                                text="Speak",
                                command=Button.createSpeak)
        moveButton.grid(column=0, row=0, pady=10)
        turnButton.grid(column=1, row=0, pady=10)
        bodyButton.grid(column=2, row=0, pady=10)
        headButton.grid(column=3, row=0, pady=10)
        listenButton.grid(column=4, row=0, pady=10)
        speakButton.grid(column=5, row=0, pady=10)

        global frame
        frame = tk.Frame(win, width=750, height=300)
        frame.grid(columnspan=6, row=1, padx=15, pady=15)
        frame.grid_propagate(False)

        reset = tk.Button(win, width="20", text="Reset", command=Control.reset)
        run = tk.Button(win, width="20", text="Run", command=Control.run)
        reset.grid(columnspan=3, column=0, row=2, pady=10)
        run.grid(columnspan=3, column=2, row=2, pady=10)

        win.mainloop()
コード例 #10
0
ファイル: move.py プロジェクト: bryanplant/robotics
    def __init__(self):
        self.screen = curses.initscr()
        curses.cbreak()
        curses.noecho()
        curses.halfdelay(1)
        curses.endwin()
        self.screen.keypad(True)

        self.control = Controller()
        self.control.setTarget(1, 6000)
        self.control.setTarget(2, 6000)

        self.head_pos = 6000
        self.head_step = 1000
        self.head_tilt = 6000

        self.speed = 1250

        self.control.setTarget(0, 6000)
        self.control.setTarget(3, 6000)
        self.control.setTarget(4, 5000)
コード例 #11
0
    def __init__(self, canvas, x, y, width, height, color, text):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.clicked = False  # if the action is currently clicked
        self.color = color  # color of action rectangle
        self.setting = 0  # how long or how many degrees to do action for
        self.settingStep = 0  # how much to decrease or increase setting per button press
        self.settingType = None  # duration or degrees
        self.settingMin = 0  # minimum setting
        self.settingMax = 0  # maximum setting

        self.icon = canvas.create_rectangle(self.x - self.width / 2, self.y - self.height / 2, self.x + self.width / 2,
                                            self.y + self.height / 2, fill=color, width=5)
        self.text = canvas.create_text(self.x, self.y - 7, text=text)  # name of action
        self.label = None  # shows current setting
        self.buttonUp = canvas.create_polygon(self.x - 20, self.y - 20, self.x + 20, self.y - 20, self.x, self.y - 50,
                                              fill='black')  # up button for adjusting setting
        self.buttonDown = canvas.create_polygon(self.x - 20, self.y + 20, self.x + 20, self.y + 20, self.x, self.y + 50,
                                                fill='black')  # down button for adjusting setting
        self.control = Controller()
        self.control.setTarget(1,6000)
コード例 #12
0
ファイル: SetSpeed.py プロジェクト: Penchant/Robot-Movement
class SetSpeed(TimedCommand):
    def __init__(self, channel, timeout, speed, parallel=False):
        self.channel = channel
        self.controller = Controller()
        self.speed = speed
        self.controller.setTarget(1, 6000)
        self.controller.setTarget(2, 6000)
        super(SetSpeed, self).__init__(timeout)
        self.parallel = parallel
        return

    def _execute(self):
        self.controller.setTarget(self.channel, self.speed)

    def _end(self):
        self.controller.setTarget(self.channel, 6000)
コード例 #13
0
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
コード例 #14
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)
コード例 #15
0
    # Turn Right
    if (key == "d"):
        print("Turn Right")
        x.setSpeed(2, 50)
        x.setAccel(2, 150)
        x.setTarget(2, 5000)
        sleep(0.5)
        x.setTarget(2, 6000)


# Initialize key as starter
key = " "

# Create controller object
x = Controller()

# Reset position before starting
x.setTarget(0, 6000)
x.setTarget(3, 6000)
x.setTarget(4, 6000)

print("\nINSTRUCTIONS FOR USE:\n")
print(" W - Increment speed")
print(" S - Decrement speed")
print(" A - Turn left")
print(" D - Turn right\n")
print(" N - Turn torso left")
print(" M - Turn torso right\n")
print(" J - Turn head left")
print(" L - Turn head right")
コード例 #16
0
class Player:
    def __init__(self, node, server):
        self.node = node
        self.server = server
        self.done = False
        self.hp = 100
        self.hasKey = False
        self.direction = "South"
        self.control = Controller()
        self.control.setTarget(1, 6000)

    def move(self):
        valid = False
        while not valid:
            valid = True

            self.server.write_message("%listen")
            self.server.received = ""

            while self.server.received == "":
                pass

            selection = self.server.received

            if selection == "North":
                if self.node.north is not None:
                    self.node = self.node.north
                    if self.direction == "South":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(3)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "East":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 7000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "West":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                else:
                    valid = False
            elif selection == "East":
                if self.node.east is not None:
                    self.node = self.node.east
                    if self.direction == "South":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 7000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "North":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "West":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(3)
                        self.control.setTarget(2, 6000)
                else:
                    valid = False
            elif selection == "South" or selection == "self":
                if self.node.south is not None:
                    self.node = self.node.south
                    if self.direction == "North":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(3)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "East":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "West":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 7000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                else:
                    valid = False
            elif selection == "West":
                if self.node.west is not None:
                    self.node = self.node.west
                    if self.direction == "South":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "East":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 5000)
                        time.sleep(3)
                        self.control.setTarget(2, 6000)
                    elif self.direction == "North":
                        self.control.setTarget(1, 6000)
                        self.control.setTarget(2, 7000)
                        time.sleep(1.5)
                        self.control.setTarget(2, 6000)
                else:
                    valid = False
            else:
                valid = False

            if valid:
                self.control.setTarget(1, 4500)
                time.sleep(0.65)
                self.control.setTarget(1, 6000)
                self.direction = selection
            if not valid:
                print("I can't go that direction")
                self.server.write_message("I can't go that direction")
                time.sleep(1)

    def fight(self, enemyHp, enemyHasKey):
        print("\nFight!")
        self.server.write_message("Fight!")
        time.sleep(1)

        enemyHp -= 50
        self.hp -= 50
        if self.hp <= 0:
            print("\nI am dead")
            self.server.write_message("I am dead")
            time.sleep(1)

            self.done = True
        else:
            print("Enemy dead!")
            self.server.write_message("Enemy dead!")
            time.sleep(1)

            print("My hp is at " + str(self.hp))
            self.server.write_message("My hp is at " + str(self.hp))
            time.sleep(1.5)

            if enemyHasKey:
                print("I picked up a key")
                self.server.write_message("I picked up a key")
                time.sleep(1)

                self.hasKey = True

    def heal(self):
        print("\nI found a healing station!")
        self.server.write_message("I found a healing station!")
        time.sleep(1.5)

        print("I have healed to full health")
        self.server.write_message("I have healed to full health")
        time.sleep(1.5)

        self.hp = 100

    def openChest(self):
        if self.hasKey:
            print("\nAll of the treasures are mine!")
            self.server.write_message("All of the treasures are mine!")
            time.sleep(1.5)

            self.done = True
        else:
            print("\nI need a key to open this chest")
            self.server.write_message("I need a key to open this chest")
            time.sleep(2.0)
コード例 #17
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)
コード例 #18
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()
コード例 #19
0
def run():
    global part
    global direction
    global dur
    rob = Controller()

    if (part == 'wheels'):
        if (direction == 'forward'):
            rob.setTarget(1, 5000)
        elif (direction == 'back'):
            rob.setTarget(1, 7000)
        elif (direction == 'left'):
            rob.setTarget(2, 7000)
        elif (direction == 'right'):
            rob.setTarget(2, 5000)
        time.sleep(dur)
        rob.setTarget(1, 6000)
        rob.setTarget(2, 6000)

    elif (part == 'head'):
        if (direction == 'up'):
            rob.setTarget(4, 7500)
        elif (direction == 'down'):
            rob.setTarget(4, 4500)
        elif (direction == 'left'):
            rob.setTarget(3, 7500)
        elif (direction == 'right'):
            rob.setTarget(3, 4500)
        elif (direction == 'center'):
            rob.setTarget(4, 6000)
            rob.setTarget(3, 6000)

    elif (part == 'body'):
        if (direction == 'left'):
            rob.setTarget(0, 7500)
        elif (direction == 'right'):
            rob.setTarget(0, 4500)
        elif (direction == 'center'):
            rob.setTarget(0, 6000)

    time.sleep(1)
コード例 #20
0
 def __init__(self, win):
     ## init to work with alex's code
     #    def __init__(self):
     self.root = win
     self.x = Controller()
コード例 #21
0
ファイル: Game.py プロジェクト: Dieter103/Robots
from tkinter import *
from MotorAction import *
from PauseAction import *
from SpeakAction import *
from WaitForSpeechAction import *
from GameAction import *
from _thread import start_new_thread
from Action import *
import random
from aenum import Enum
import sys
import Server
from Maestro import Controller

controller = Controller()
connection = Server

global currentDirection


class Cell:
    def __init__(self):
        self.type = MazeType.NONE
        self.hidden = True


class PathCell(Cell):
    def __init__(self):
        Cell.__init__(self)
        self.type = MazeType.PATH
        self.hidden = False
コード例 #22
0
ファイル: InputHandler.py プロジェクト: seancrwhite/CSCI455
import tty
import sys
import termios
from Maestro import Controller

x = Controller()

# 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
コード例 #23
0
class Drivetrain:
    Fast = 1500
    Medium = 950
    Slow = 650

    def __init__(self, rotateChannel, forwardChannel, controller):
        self._forwardChannel = forwardChannel
        self.controller = controller
        self.controller = Controller()
        self.rotate = 0
        self.forward = 0
        self.enable = False
        self.moveForward = False
        self.moveBackward = False
        self.rotateLeft = False
        self.rotateRight = False
        self.speed = Drivetrain.Slow
        self.stop = False
        self._rotateChannel = rotateChannel

    def loop(self):
        while (self.enable):
            self.execute()
            time.sleep(.02)

    def execute(self, rotation=None, forward=None):
        if rotation is not None:
            self.rotate = rotation
        if forward is not None:
            self.forward = forward
        tempForward = 6000
        tempRotate = 6000
        if self.moveForward:
            tempForward += self.speed
            print(str(tempForward))
        if self.moveBackward:
            tempForward -= self.speed
        if self.rotateLeft:
            tempRotate += self.speed
        if self.rotateRight:
            tempRotate -= self.speed

        if self.stop:
            print("Stopping drivetrain")
            tempForward = 6000
            tempRotate = 6000

        self.forward = tempForward
        self.rotate = tempRotate
        self.controller.setSpeed(self._rotateChannel, self.rotate)
        self.controller.setSpeed(self._forwardChannel, self.forward)

    def run(self):
        self.enable = True
        # Create new thread here
        self.thread = threading.Thread(None, self.loop)
        self.thread.start()

    def disable(self):
        self.enable = False
        # When disabled, set movement values to 0 and update
        self.controller.setSpeed(self._rotateChannel, 0)
        self.controller.setSpeed(self._forwardChannel, 0)
コード例 #24
0
ファイル: control.py プロジェクト: brettshelley/TangoBot
class commands:
    rob = Controller()

    def fight(self):

        targetR = 6
        targetL = 12
        targetRR = 8
        targetLL = 14

        self.rob.setTarget(targetR, 0)
        self.rob.setTarget(targetL, 0)
        self.rob.setTarget(targetRR, 0)
        self.rob.setTarget(targetLL, 0)

        for i in range(0, 2):
            self.rob.setTarget(targetR, 8000)
            self.rob.setTarget(targetL, 2000)
            self.rob.setTarget(targetRR, 8000)
            self.rob.setTarget(targetLL, 8000)
            time.sleep(.5)
            self.rob.setTarget(targetR, 0)
            self.rob.setTarget(targetL, 0)
            self.rob.setTarget(targetRR, 0)
            self.rob.setTarget(targetLL, 0)
            time.sleep(.5)

    def randomFight(self):
        for i in range(0, 20):
            target = int(random.uniform(6, 17))
            amount = int(random.uniform(0, 10))
            self.rob.setTarget(target, amount)
            self.rob.setTarget(target, amount)

    def reset(self):
        zeroVal = [6, 12]
        sizVal = [8, 9, 10, 11, 15, 16, 17]
        for i in range(2):
            target = zeroVal[i]
            self.rob.setTarget(target, 0)
        for i in range(7):
            target = sizVal[i]
            self.rob.setTarget(target, 6000)
            time.sleep(1)
        for i in range(2):
            target = 7
            target2 = 13
            self.rob.setTarget(target, 7000)
            self.rob.setTarget(target2, 6000)
        target = 14
        self.rob.setTarget(target, 7000)
        body = 0
        head = 3
        head2 = 4
        self.rob.setTarget(body, 6000)
        self.rob.setTarget(head, 6000)
        self.rob.setTarget(head2, 6000)

    def superReset(self):
        headUP = 4
        headLR = 3
        body = 0
        upperRight = 6
        upperLeft = 12
        middleRight = 7
        middleLeft = 13
        self.rob.setTarget(headUP, 6000)
        self.rob.setTarget(headLR, 6000)
        self.rob.setTarget(body, 6000)
        self.rob.setTarget(upperRight, 0)
        self.rob.setTarget(upperLeft, 0)
        self.rob.setTarget(middleRight, 7000)
        self.rob.setTarget(middleLeft, 6000)

    def die(self):
        targetUpArmR = 6
        targetUpArmL = 12
        targetout = 13
        targetoutR = 7
        body = 0
        head = 3
        headUp = 4
        for i in range(0, 10000):
            self.rob.setTarget(targetUpArmR, 9000)

        self.rob.setTarget(targetUpArmL, 1000)
        self.rob.setTarget(body, 6000)
        self.rob.setTarget(head, 6000)
        time.sleep(2)
        self.rob.setTarget(targetout, 2000)
        self.rob.setTarget(targetoutR, 8000)
        self.rob.setTarget(headUp, 8000)
        time.sleep(2)
        self.rob.setTarget(targetUpArmR, 0)
        self.rob.setTarget(targetUpArmL, 0)
        self.rob.setTarget(targetout, 6000)
        self.rob.setTarget(targetoutR, 7000)
        self.rob.setTarget(head, 6000)
        self.rob.setTarget(headUp, 4000)
        time.sleep(3)

    def look(self):
        headUD = 4
        headLR = 3

        self.rob.setTarget(headUD, 6000)
        self.rob.setTarget(headLR, 6000)
        time.sleep(1)
        self.rob.setTarget(headLR, 4000)
        time.sleep(2)
        self.rob.setTarget(headLR, 8000)
        time.sleep(2)
        self.rob.setTarget(headLR, 6000)

    def corn(self):
        target2 = 12
        target3 = 14
        target4 = 15
        target5 = 16
        target6 = 17

        self.rob.setTarget(target2, 5000)
        self.rob.setTarget(target3, 8000)
        time.sleep(.5)
        self.rob.setTarget(target4, 4000)
        self.rob.setTarget(target3, 4000)
        time.sleep(.5)
        self.rob.setTarget(target4, 8000)
        self.rob.setTarget(target3, 8000)
        time.sleep(.5)
        self.rob.setTarget(target4, 4000)
        self.rob.setTarget(target3, 4000)
        time.sleep(.5)
        self.rob.setTarget(target4, 8000)
        self.rob.setTarget(target3, 8000)
        time.sleep(.5)
        self.rob.setTarget(target4, 4000)
        self.rob.setTarget(target3, 4000)
        time.sleep(.5)
        self.rob.setTarget(target4, 8000)
        self.rob.setTarget(target3, 8000)
        time.sleep(.5)
        self.rob.setTarget(target4, 4000)
        self.rob.setTarget(target3, 4000)
        time.sleep(.5)

        time.sleep(3)

    def wtf(self):
        target = 6
        self.rob.setTarget(target, 2000)
        target = 12
        self.rob.setTarget(target, 2000)

    def forward(self):
        target = 1
        self.rob.setTarget(target, 5000)
        time.sleep(1)
        self.rob.setTarget(target, 6000)

    def backward(self):
        target = 1
        self.rob.setTarget(target, 7000)
        time.sleep(1)
        self.rob.setTarget(target, 6000)

    def left(self):
        target = 2
        self.rob.setTarget(target, 7000)
        time.sleep(2)
        self.rob.setTarget(target, 6000)
        target = 1
        self.rob.setTarget(target, 5000)
        time.sleep(1)
        self.rob.setTarget(target, 6000)

    def right(self):
        target = 2
        self.rob.setTarget(target, 5000)
        time.sleep(2)
        self.rob.setTarget(target, 6000)
        target = 1
        self.rob.setTarget(target, 5000)
        time.sleep(1)
        self.rob.setTarget(target, 6000)

    def runAway(self):
        target = 2
        self.rob.setTarget(target, 3000)
        time.sleep(5)
        self.rob.setTarget(target, 6000)
        target = 1
        self.rob.setTarget(target, 5000)
        time.sleep(2)
        self.rob.setTarget(target, 6000)

    def think(self):
        target = 12
        self
コード例 #25
0
class Action:
    def __init__(self, canvas, x, y, width, height, color, text):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.clicked = False  # if the action is currently clicked
        self.color = color  # color of action rectangle
        self.setting = 0  # how long or how many degrees to do action for
        self.settingStep = 0  # how much to decrease or increase setting per button press
        self.settingType = None  # duration or degrees
        self.settingMin = 0  # minimum setting
        self.settingMax = 0  # maximum setting

        self.icon = canvas.create_rectangle(self.x - self.width / 2, self.y - self.height / 2, self.x + self.width / 2,
                                            self.y + self.height / 2, fill=color, width=5)
        self.text = canvas.create_text(self.x, self.y - 7, text=text)  # name of action
        self.label = None  # shows current setting
        self.buttonUp = canvas.create_polygon(self.x - 20, self.y - 20, self.x + 20, self.y - 20, self.x, self.y - 50,
                                              fill='black')  # up button for adjusting setting
        self.buttonDown = canvas.create_polygon(self.x - 20, self.y + 20, self.x + 20, self.y + 20, self.x, self.y + 50,
                                                fill='black')  # down button for adjusting setting
        self.control = Controller()
        self.control.setTarget(1,6000)

    # move the action to the specified location
    def move(self, canvas, x, y):
        canvas.move(self.icon, x - self.x, y - self.y)
        canvas.move(self.text, x - self.x, y - self.y)
        canvas.move(self.label, x - self.x, y - self.y)
        canvas.move(self.buttonUp, x - self.x, y - self.y)
        canvas.move(self.buttonDown, x - self.x, y - self.y)
        self.x = x
        self.y = y

    # return if and where the action was clicked
    # 0 = not clicked
    # 1 = up arrow
    # 2 = down arrow
    # 3 = rest of box
    def click_location(self, x, y):
        if self.x - 20 < x < self.x + 20 and self.y - 50 < y < self.y - 20:  # if up arrow clicked
            return 1
        elif self.x - 20 < x < self.x + 20 and self.y + 20 < y < self.y + 50:  # if down arrow clicked
            return 2
        elif self.x - self.width / 2 < x < self.x + self.width / 2 and \
                                        self.y - self.height / 2 < y < self.y + self.height / 2:  # if rest clicked
            return 3

        return 0  # if not clicked

    # change the setting for this action
    # if direction = 0 => decrease
    # if direction = 1 => increase
    def change_setting(self, direction, canvas):
        if direction == 0 and self.setting - self.settingStep >= self.settingMin:
            self.setting -= self.settingStep  # decrease setting
        elif direction == 1 and self.setting + self.settingStep <= self.settingMax:
            self.setting += self.settingStep  # increase setting

        canvas.delete(self.label)  # delete old label
        # create new label
        self.label = canvas.create_text(self.x, self.y + 7, text=str("{0:.2f}".format(self.setting)) + " " + self.settingType)

    # set border color to yellow or black
    def set_active(self, canvas, flag):
        canvas.delete(self.icon)  # delete old icon
        # create new icon
        if flag:  # if active set border to yellow
            self.icon = canvas.create_rectangle(self.x - self.width / 2, self.y - self.height / 2,
                                                self.x + self.width / 2, self.y + self.height / 2,
                                                fill=self.color, outline="#ffd700", width=5)
        else:  # if inactive set border to black
            self.icon = canvas.create_rectangle(self.x - self.width / 2, self.y - self.height / 2,
                                                self.x + self.width / 2, self.y + self.height / 2,
                                                fill=self.color, outline="black", width=5)
        canvas.tag_raise(self.text)  # move other parts of action to top of icon
        canvas.tag_raise(self.label)
        canvas.tag_raise(self.buttonUp)
        canvas.tag_raise(self.buttonDown)
        canvas.update_idletasks()

    def destroy(self, canvas):
        canvas.delete(self.icon)  # delete action if not in box
        canvas.delete(self.text)
        canvas.delete(self.label)
        canvas.delete(self.buttonUp)
        canvas.delete(self.buttonDown)
コード例 #26
0
ファイル: move.py プロジェクト: bryanplant/robotics
class Move:
    def __init__(self):
        self.screen = curses.initscr()
        curses.cbreak()
        curses.noecho()
        curses.halfdelay(1)
        curses.endwin()
        self.screen.keypad(True)

        self.control = Controller()
        self.control.setTarget(1, 6000)
        self.control.setTarget(2, 6000)

        self.head_pos = 6000
        self.head_step = 1000
        self.head_tilt = 6000

        self.speed = 1250

        self.control.setTarget(0, 6000)
        self.control.setTarget(3, 6000)
        self.control.setTarget(4, 5000)

    def turn_head(self, direction):
        if (direction == 1 and self.head_pos > 6000 - 2 * self.head_step):
            self.head_pos -= self.head_step
        elif (direction == 0 and self.head_pos < 6000 + 2 * self.head_step):
            self.head_pos += self.head_step
        self.control.setTarget(3, self.head_pos)

    def tilt_head(self, direction):
        if (direction == 1 and self.head_tilt > 5000 - 2 * self.head_step / 2):
            self.head_tilt -= self.head_step / 2
        elif (direction == 0 and self.head_tilt < 5000 + 2 * self.head_step / 2):
            self.head_tilt += self.head_step / 2
        self.control.setTarget(4, self.head_tilt)

    def change_speed(self, direction):
        if (direction == 0 and self.speed > 1000):
            self.speed -= 250
        elif (direction == 1 and self.speed < 1500):
            self.speed += 250

    def run(self):
        try:
            while True:
                self.screen.clear()
                char = self.screen.getch()
                if char == ord('z'):
                    break
                elif char == ord(' '):  # reset entirely
                    self.control.setTarget(0, 6000)
                    self.control.setTarget(3, 6000)
                    self.control.setTarget(4, 5000)
                    self.head_pos = 6000
                    self.head_tilt = 6000
                elif char == ord('s'):  # reset body
                    self.control.setTarget(0, 6000)
                elif char == ord('w'):  # reset head
                    self.control.setTarget(4, 6000)
                    self.control.setTarget(3, 6000)
                    self.head_pos = 6000
                    self.head_tilt = 5000
                elif char == ord('r'):  # head up
                    self.tilt_head(0)
                elif char == ord('f'):  # head down
                    self.tilt_head(1)
                elif char == ord('q'):  # head left
                    self.turn_head(0)
                elif char == ord('e'):  # head right
                    self.turn_head(1)
                elif char == ord('a'):  # body left
                    self.control.setTarget(0, 7500)
                elif char == ord('d'):  # body right
                    self.control.setTarget(0, 5000)
                elif char == ord('='):
                    self.change_speed(1)
                elif char == ord('-'):
                    self.change_speed(0)

                if char == curses.KEY_UP:  # forward
                    self.control.setTarget(1, 6000 - self.speed)
                elif char == curses.KEY_DOWN:  # backward
                    self.control.setTarget(1, 6000 + self.speed)
                elif char == curses.KEY_RIGHT:  # right
                    self.control.setTarget(1, 6000)
                    self.control.setTarget(2, 6000 - self.speed)
                elif char == curses.KEY_LEFT:  # left
                    self.control.setTarget(1, 6000)
                    self.control.setTarget(2, 6000 + self.speed)
                else:
                    self.control.setTarget(1, 6000)
                    self.control.setTarget(2, 6000)

                    # 3 - head (left right)
                    # 4 - head (up down)
                    # 0 - body

        finally:
            # shut down
            curses.nocbreak()
            self.screen.keypad(0)
            curses.echo()
            curses.endwin()
コード例 #27
0
ファイル: RobotMap.py プロジェクト: Penchant/Robot-Movement
	def init():
		RobotMap.controller = Controller()
コード例 #28
0
#	if key.keycode==79:

	#Right
#	if key.keycode==81:


## Main
#con = tk.Tk()
#con.bind('<KP_Enter>',stop)
#con.bind('<Up>',move)
#con.bind('<Down>',move)
#con.bind('<Left>',turn)
#con.bind('<Right>',turn)
#con.bind('<KP_1>',tilt)
#con.bind('<KP_0>',tilt)
#con.bind('<KP_4>',body)
#con.bind('<KP_5>',body)
#con.bind('<KP_6>',body)
#con.bind('<KP_7>',head)
#con.bind('<KP_8>',head)
#con.bind('<KP_9>',head)

#lab = tk.Label(con, text="Hello Tkinter!")

#lab.pack()

x = Controller()
x.setTarget(0, 7800)

con.mainloop()
コード例 #29
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()
コード例 #30
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"