HOW TO: Hack A VEX HexBug Robotic Arm With A Raspberry Pi II B+

All things Linux ...
User avatar
magicrat
Site Admin
Posts: 13
Joined: Sun Dec 14, 2014 12:33 pm
Location: Manassas, VA
Contact:

HOW TO: Hack A VEX HexBug Robotic Arm With A Raspberry Pi II B+

Postby magicrat » Sun Jan 17, 2016 3:45 pm

The VEX Motorized Robotic Arm Kit by HEXBUG is available at Target and on-line for about $80. It looks like the picture below and comes with 4 servo motors and a battery pack that puts out about 5V at 1A.

NOTE: Pictures can be viewed in "full size" by right-clicking on them and selecting the "open in new tab" option.
16946267.jpg
16946267.jpg (49.03 KiB) Viewed 13883 times
The standard controller is adequate, but I wanted to replace it with a software version. We did this using a Raspberry Pi II B, breadboard, two each L293D IC servo controller chips, and some Python code.

Video: https://www.youtube.com/watch?v=FJCU2Gi ... e=youtu.be

The finished GUI running on the Pi looks like this and gives much more precise control of arm movements:
ScreenController.jpg
ScreenController.jpg (17.18 KiB) Viewed 13881 times
GUI.jpg
GUI.jpg (74.66 KiB) Viewed 13881 times
Before You Start:

1) The basic robotic arm is pretty flimsy. In particular, some of the gears will pop-off if you push the edges of the range of motion (especially the gear on Motor #2). We fixed this by replacing the plastic pins with some home made metal ones - problem solved. The plastic pins that come with robotic arm are square in the middle. We found that using a "concrete nail" (which has raised spirals on it) could be cut to the appropriate length to fit snugly in the square hole on the gear ... and then pinned with a cotter pin to keep it from coming out. See picture below:
10_Spiral_shank_nail.jpg
10_Spiral_shank_nail.jpg (87.86 KiB) Viewed 13881 times
NailwPin.jpg
NailwPin.jpg (48.16 KiB) Viewed 13881 times
2) Do not connect a motor, no matter how small directly to the Raspberry Pi, it will damage your Raspberry Pi. The main processor can only supply enough power to light a LED, roughly 20mA. A motor will want at least 400mA of current to start turning. So, you are going to want a SEPARATE power supply of about 5V and 1 to 1.5 AMPS to power the motors - only use the Pi power for the logic circuitry. We had several power supplies laying around the house and commandeered one for this purpose. Picture below:
PowerSupply.jpg
PowerSupply.jpg (187.21 KiB) Viewed 13881 times
3) You are going to be cutting the wires on the controller that came with the robot (between the controller and the servo motors mounted on the robot). The order of the motors makes a difference if you want the buttons in the Python application to control the correct one. The diagram below shows how I have labeled the motors (1, 2, 3, and 4). When you cut the wires, you may find it helpful to attach connectors on them, that way you can easily disconnect from the Pi breadboard and connect back into the factory provided controller.
motors.jpg
motors.jpg (433.22 KiB) Viewed 13881 times
What You Need:
  • - Your VEX, HEXBUG Robotic Arm
    - A 5V 1Amp (or 1.5Amp) power supply
    - A Raspberry Pi II "B" with SD card preinstalled with Raspbian
    - A Breadboard to connect everything on
    - Two L293D motor driver chips
    - Jumper cables to connect everything up (Male to male and female to male)
    - Tkinter graphical framework for Python installed on your Pi (to install, open a terminal and type "sudo apt-get install python-tk"
Instructions:

1) Clip the wires between the factory provided controller and all 4 servo motors; about 4" down the wires from the controller. Affix female conectors to the controller side and male connectors to the motor side. Now you can reconnect the wires easily. Eventually, you will connect the Pi breadboard to the motors, so you will want male (breadboard side) to female (motor side) wires for that (8 of them, 2 per motor).

2) Go to the "tutsplace.com" website and connect the first L293D IC to the Pi by following the directions there, but take note that they show pictures of the older Raspberry Pi "one" ... which only had a 26-pin connector. The new Raspberry Pi II "B" has a 40-pin connector. See comparison photo below ...
Pi1vsPi2.jpg
Pi1vsPi2.jpg (854.54 KiB) Viewed 13880 times
Not to worry, the first 26-pins on the new Pi II "B" are the same. So, the pictures are fine for connecting breadboard power, ground, and output connections for the first two motors. The logic pin connections for motors 3 and 4, using the 40-pin Raspberry Pi II "B" connectors, are provided later in this post ...

Here's the link to "tutsplace.com": http://computers.tutsplus.com/tutorials ... -cms-20051

NOTE: For the sake of brevity, I have re-posted the most pertinent pictures from the thetutsplace.com website below. Remember that the Pi depicted is the OLD Raspberry Pi "one" (26 pin). Use these pictures as a guide for the connections to motors 1 and 2:
  • - Connect the power and grounds for the first motor as in the picture below.
Power pins.png
Power pins.png (91.94 KiB) Viewed 13881 times
  • - Connect the data pins for the first motor.
Data pins.png
Data pins.png (92.72 KiB) Viewed 13881 times
NOTE: Here are the logic pin connections and diagrams for all 4 motors using the Raspberry Pi II "B" 40-pin connector. This is the most important graphic in this instructional post.
PIns.jpg
PIns.jpg (485.27 KiB) Viewed 13881 times
  • - Connect the data pins for the second motor and the 5V EXTERNAL power supply.
2 motors full.png
2 motors full.png (114.86 KiB) Viewed 13881 times
  • - Ok. Now you are going to use the exact same steps you did for motors 1 and 2 ... to connect motors 3 and 4. The only differences are that you are going to connect different GPIO pins for motor logic control ... and of course the power-out cables will be connected to motors 3 and 4 (instead of 1 and 2). Sooo ... go ahead and connect motors 3 and 4 using the second L293D chip and the same processes; use the connections outlined in the table below for logic control circuitry:
PinsBigPic.jpg
PinsBigPic.jpg (132.63 KiB) Viewed 13881 times
3) It should look something like this:
20160117_153047.jpg
20160117_153047.jpg (2.25 MiB) Viewed 13880 times
NOTE: The red LED you see (with the 330 ohm resistor) on the bottom of the board is something I added as a power indicator ... you do not need this ... it's just a nice touch.

4) Now, time for the "secret sauce". Use this software to test the program:

***********************************

from Tkinter import *
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) # This turns off warning errors caused by changing signals between the motors too quickly

Global_interval_in_seconds = .1 # This is the global variable that sets the increments for the motors to move (in seconds)

# All Functions Are Defined Here
# START Functions
# ******************************

# Motor1 ClawIn(Seconds)
def FNTC_ClawIn(Seconds):
Motor1A = 16
Motor1B = 18
Motor1E = 22

GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)

# print "Claw In"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor1E,GPIO.LOW)


# Motor1 ClawOut(Seconds)
def FNTC_ClawOut(Seconds):
Motor1A = 16
Motor1B = 18
Motor1E = 22

GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)

# print "Claw Out"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor1E,GPIO.LOW)


# Motor2 MoveIn(Seconds)
def FNTC_MoveIn(Seconds):
Motor2A = 19
Motor2B = 21
Motor2E = 23

GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)

# print "Move In"
GPIO.output(Motor2A,GPIO.LOW)
GPIO.output(Motor2B,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor2E,GPIO.LOW)


# Motor2 MoveOut(Seconds)
def FNTC_MoveOut(Seconds):
Motor2A = 19
Motor2B = 21
Motor2E = 23

GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)

# print "Move Out"
GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
GPIO.output(Motor2E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor2E,GPIO.LOW)


# Motor3 MoveUp(Seconds)
def FNTC_MoveUp(Seconds):
Motor3A = 40
Motor3B = 38
Motor3E = 36

GPIO.setup(Motor3A,GPIO.OUT)
GPIO.setup(Motor3B,GPIO.OUT)
GPIO.setup(Motor3E,GPIO.OUT)

# print "Move Up"
GPIO.output(Motor3A,GPIO.LOW)
GPIO.output(Motor3B,GPIO.HIGH)
GPIO.output(Motor3E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor3E,GPIO.LOW)


# Motor3 MoveDown(Seconds)
def FNTC_MoveDown(Seconds):
Motor3A = 40
Motor3B = 38
Motor3E = 36

GPIO.setup(Motor3A,GPIO.OUT)
GPIO.setup(Motor3B,GPIO.OUT)
GPIO.setup(Motor3E,GPIO.OUT)

# print "Move Down"
GPIO.output(Motor3A,GPIO.HIGH)
GPIO.output(Motor3B,GPIO.LOW)
GPIO.output(Motor3E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor3E,GPIO.LOW)


# Motor4 RotateRight(Seconds)
def FNTC_RotateRight(Seconds):
Motor4A = 15
Motor4B = 13
Motor4E = 11

GPIO.setup(Motor4A,GPIO.OUT)
GPIO.setup(Motor4B,GPIO.OUT)
GPIO.setup(Motor4E,GPIO.OUT)

# print "Rotate Right"
GPIO.output(Motor4A,GPIO.HIGH)
GPIO.output(Motor4B,GPIO.LOW)
GPIO.output(Motor4E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor4E,GPIO.LOW)


# Motor4 RotateLeft(Seconds)
def FNTC_RotateLeft(Seconds):
Motor4A = 15
Motor4B = 13
Motor4E = 11

GPIO.setup(Motor4A,GPIO.OUT)
GPIO.setup(Motor4B,GPIO.OUT)
GPIO.setup(Motor4E,GPIO.OUT)

# print "Rotate Left"
GPIO.output(Motor4A,GPIO.LOW)
GPIO.output(Motor4B,GPIO.HIGH)
GPIO.output(Motor4E,GPIO.HIGH)

sleep(Seconds)

# print "Now stop"
GPIO.output(Motor4E,GPIO.LOW)


# Class definition for the main window
class App:

def __init__(self, master):

OverallFrame = Frame(master, padx=5, pady=5, height=2, bd=1, relief=SUNKEN)
OverallFrame.pack(fill=X, padx=5, pady=5)

# Row 1 Controls
frame = Frame(OverallFrame, padx=5, pady=3)
frame.pack()

self.Move_Up = Button(frame, text="Up", height=1, width=8, command=self.evt_up)
self.Move_Up.pack(side=LEFT)
self.Move_In = Button(frame, text="In", height=1, width=8, command=self.evt_in)
self.Move_In.pack(side=LEFT)
self.Claw_Open = Button(frame, text="Claw Open", height=1, width=8, command=self.evt_claw_open)
self.Claw_Open.pack(side=LEFT)
self.Rotate_Right = Button(frame, text="Rotate Right", height=1, width=8, command=self.evt_rotate_right)
self.Rotate_Right.pack(side=LEFT)

# Row 2 Controls
frame2 = Frame(OverallFrame, padx=5, pady=3)
frame2.pack()

self.Move_Down = Button(frame2, text="Down", height=1, width=8, command=self.evt_down)
self.Move_Down.pack(side=LEFT)
self.Move_Out = Button(frame2, text="Out", height=1, width=8, command=self.evt_out)
self.Move_Out.pack(side=LEFT)
self.Claw_Close = Button(frame2, text="Claw Close", height=1, width=8, command=self.evt_claw_close)
self.Claw_Close.pack(side=LEFT)
self.Rotate_Left = Button(frame2, text="Rotate Left", height=1, width=8, command=self.evt_rotate_left)
self.Rotate_Left.pack(side=LEFT)

separator3 = Frame(OverallFrame, padx=5, pady=7, height=2, bd=1, relief=SUNKEN)
separator3.pack(fill=X, padx=5, pady=5)

# Form Footer
frame3 = Frame(OverallFrame, padx=5, pady=5)
frame3.pack(side=RIGHT)

# frame3, text="QUIT", fg="red", command=OverallFrame.quit

self.button = Button(
frame3, text="QUIT", fg="red", command=self.evt_Quit
)
self.button.pack()

def evt_Quit(self):
# print "Quit"
GPIO.cleanup()
root.destroy()
def evt_up(self):
# print "Move Up"
FNTC_MoveUp(Global_interval_in_seconds)
def evt_down(self):
# print "Move Down"
FNTC_MoveDown(Global_interval_in_seconds)
def evt_in(self):
# print "Move In"
FNTC_MoveIn(Global_interval_in_seconds)
def evt_out(self):
# print "Move Out"
FNTC_MoveOut(Global_interval_in_seconds)
def evt_claw_open(self):
# print "Claw Open"
FNTC_ClawOut(Global_interval_in_seconds)
def evt_claw_close(self):
# print "Claw Close"
FNTC_ClawIn(Global_interval_in_seconds)
def evt_rotate_right(self):
# print "Rotate Right"
FNTC_RotateRight(Global_interval_in_seconds)
def evt_rotate_left(self):
# print "Rotate Left"
FNTC_RotateLeft(Global_interval_in_seconds)


# Function to center the main window
def center(win):
win.update_idletasks()
width = 450
height = 140
x = ((win.winfo_screenwidth() - 75) // 2) - (width // 2)
y = ((win.winfo_screenheight() - 100) // 2) - (height // 2)
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))

# Function to capture when [X] is clicked on the main window
def X_wasClicked():
GPIO.cleanup()
root.destroy()

# END Functions




# ***************************************************************************************



# The Program Code Begins Below Here
# START Program Code
# *****************************


# Open and set the main window (here we name it 'root')
root = Tk()
root.title('Robot Control Panel')
root.resizable(width=0, height=0)
center(root)

app = App(root)

# Capture if the [X] button on the main window is closed
root.protocol('WM_DELETE_WINDOW', X_wasClicked) # root is your main window

root.mainloop()

***********************************

That's it! It should work!

:D
-- Rat

Image

User avatar
magicrat
Site Admin
Posts: 13
Joined: Sun Dec 14, 2014 12:33 pm
Location: Manassas, VA
Contact:

Re: HOW TO: Hack A VEX HexBug Robotic Arm With A Raspberry Pi II B+

Postby magicrat » Sat Jan 30, 2016 5:02 pm

Robot #2 ...

5 motors and an LED.

Also, added an LCD screen to display the robots current motion.

Video: https://magicratproductions.com/videos/ ... ame=Robot2
20160130_165805.jpg
20160130_165805.jpg (1.95 MiB) Viewed 13801 times
20160130_165757.jpg
20160130_165757.jpg (1.9 MiB) Viewed 13801 times
-- Rat

Image

User avatar
magicrat
Site Admin
Posts: 13
Joined: Sun Dec 14, 2014 12:33 pm
Location: Manassas, VA
Contact:

Re: HOW TO: Hack A VEX HexBug Robotic Arm With A Raspberry Pi II B+

Postby magicrat » Sun Mar 06, 2016 7:24 pm

Built a circuit card for Robot #2.
Robot2.jpg
Robot #2 with Controller Card
Robot2.jpg (470.33 KiB) Viewed 13581 times
All you need is that card, tkinter, and this code:

Code: Select all

# Import all dependent libraries # ****************************** from Tkinter import * import tkMessageBox import RPi.GPIO as GPIO from time import sleep # Set GPIO Modes # ****************************** GPIO.setmode(GPIO.BCM) # This tells the system to use GPIO pins rather than pins on the plug (1 through 40); for that use GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) # This turns off warning errors caused by changing signals between the motors too quickly # Set Global variables (constants only) # ****************************** Global_interval_in_seconds = .1 # This is the global variable that sets the increments for the motors to move (in seconds). Use .03 for smallest possible increment. global Global_Motor1_claw_in_out_range # Max number of movments from position 0 Global_Motor1_claw_in_out_range = 12 global Global_Motor2_move_up_down_range # Max number of movments from position 0 Global_Motor2_move_up_down_range = 18 global Global_Motor3_move_in_out_range # Max number of movments from position 0 Global_Motor3_move_in_out_range = 24 global Global_Motor4_baseRotate_range # Max number of movments from position 0 Global_Motor4_baseRotate_range = 34 global Global_Motor6_WristRotate_range # Max number of movments from position 0 Global_Motor6_WristRotate_range = 3 # All Functions Are Defined Here # START Functions # ****************************** # Motor1 ClawIn(Limits, Position, Seconds) def FNTC_ClawIn(Limits, Position, Seconds): Motor1A = 13 Motor1B = 19 Motor1E = 26 GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) GPIO.setup(Motor1E,GPIO.OUT) ClawInMultiplier = .64 if Position > 0 and Limits == True: # print Position , ' is > 0 ' Position = Position - 1 # print "Claw In" GPIO.output(Motor1A,GPIO.LOW) GPIO.output(Motor1B,GPIO.HIGH) GPIO.output(Motor1E,GPIO.HIGH) sleep(Seconds * ClawInMultiplier) # print "Now stop" GPIO.output(Motor1E,GPIO.LOW) elif Limits == False: # print "Claw In" GPIO.output(Motor1A,GPIO.LOW) GPIO.output(Motor1B,GPIO.HIGH) GPIO.output(Motor1E,GPIO.HIGH) sleep(Seconds * ClawInMultiplier) # print "Now stop" GPIO.output(Motor1E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor1 ClawOut(Limits, Position, Seconds) def FNTC_ClawOut(Limits, Position, Seconds): Motor1A = 13 Motor1B = 19 Motor1E = 26 GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) GPIO.setup(Motor1E,GPIO.OUT) ClawOutMultiplier = .5 if Position < Global_Motor1_claw_in_out_range and Limits == True: # print Position, ' is < ' , Global_Motor1_claw_in_out_range Position = Position + 1 # print "Claw Out" GPIO.output(Motor1A,GPIO.HIGH) GPIO.output(Motor1B,GPIO.LOW) GPIO.output(Motor1E,GPIO.HIGH) sleep(Seconds * ClawOutMultiplier) # print "Now stop" GPIO.output(Motor1E,GPIO.LOW) elif Limits == False: # print "Claw Out" GPIO.output(Motor1A,GPIO.HIGH) GPIO.output(Motor1B,GPIO.LOW) GPIO.output(Motor1E,GPIO.HIGH) sleep(Seconds * ClawOutMultiplier) # print "Now stop" GPIO.output(Motor1E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor2 MoveUp(Limits, Position, Seconds) def FNTC_MoveUp(Limits, Position, Seconds): Motor2A = 22 Motor2B = 27 Motor2E = 17 GPIO.setup(Motor2A,GPIO.OUT) GPIO.setup(Motor2B,GPIO.OUT) GPIO.setup(Motor2E,GPIO.OUT) upMultiplier = 1.5 if Position < Global_Motor2_move_up_down_range and Limits == True: # print Position, ' is < ' , Global_Motor2_move_up_down_range Position = Position + 1 # print "Move Up" GPIO.output(Motor2A,GPIO.LOW) GPIO.output(Motor2B,GPIO.HIGH) GPIO.output(Motor2E,GPIO.HIGH) sleep(Seconds * upMultiplier) # print "Now stop" GPIO.output(Motor2E,GPIO.LOW) elif Limits == False: # print "Move Up" GPIO.output(Motor2A,GPIO.LOW) GPIO.output(Motor2B,GPIO.HIGH) GPIO.output(Motor2E,GPIO.HIGH) sleep(Seconds * upMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor2E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor2 MoveDown(Limits, Position, Seconds) def FNTC_MoveDown(Limits, Position, Seconds): Motor2A = 22 Motor2B = 27 Motor2E = 17 GPIO.setup(Motor2A,GPIO.OUT) GPIO.setup(Motor2B,GPIO.OUT) GPIO.setup(Motor2E,GPIO.OUT) downMultiplier = 1 if Position > 0 and Limits == True: # print Position , ' is > 0 ' Position = Position - 1 # print "Move Down" GPIO.output(Motor2A,GPIO.HIGH) GPIO.output(Motor2B,GPIO.LOW) GPIO.output(Motor2E,GPIO.HIGH) sleep(Seconds * downMultiplier) # print "Now stop" GPIO.output(Motor2E,GPIO.LOW) elif Limits == False: # print "Move Down" GPIO.output(Motor2A,GPIO.HIGH) GPIO.output(Motor2B,GPIO.LOW) GPIO.output(Motor2E,GPIO.HIGH) sleep(Seconds * downMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor2E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor3 MoveIn(Limits, Position, Seconds) def FNTC_MoveIn(Limits, Position, Seconds): Motor3A = 21 Motor3B = 20 Motor3E = 16 GPIO.setup(Motor3A,GPIO.OUT) GPIO.setup(Motor3B,GPIO.OUT) GPIO.setup(Motor3E,GPIO.OUT) InMultiplier = 1.06 if Position > 0 and Limits == True: # print Position , ' is > 0 ' Position = Position - 1 # print "Move In" GPIO.output(Motor3A,GPIO.LOW) GPIO.output(Motor3B,GPIO.HIGH) GPIO.output(Motor3E,GPIO.HIGH) sleep(Seconds * InMultiplier) # print "Now stop" GPIO.output(Motor3E,GPIO.LOW) elif Limits == False: # print "Move In" GPIO.output(Motor3A,GPIO.LOW) GPIO.output(Motor3B,GPIO.HIGH) GPIO.output(Motor3E,GPIO.HIGH) sleep(Seconds * InMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor3E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor3 MoveOut(Limits, Position, Seconds) def FNTC_MoveOut(Limits, Position, Seconds): Motor3A = 21 Motor3B = 20 Motor3E = 16 GPIO.setup(Motor3A,GPIO.OUT) GPIO.setup(Motor3B,GPIO.OUT) GPIO.setup(Motor3E,GPIO.OUT) outMultiplier = 1 if Position < Global_Motor3_move_in_out_range and Limits == True: # print Position, ' is < ' , Global_Motor3_move_in_out_range Position = Position + 1 # print "Move Out" GPIO.output(Motor3A,GPIO.HIGH) GPIO.output(Motor3B,GPIO.LOW) GPIO.output(Motor3E,GPIO.HIGH) sleep(Seconds * outMultiplier) # print "Now stop" GPIO.output(Motor3E,GPIO.LOW) elif Limits == False: # print "Move Out" GPIO.output(Motor3A,GPIO.HIGH) GPIO.output(Motor3B,GPIO.LOW) GPIO.output(Motor3E,GPIO.HIGH) sleep(Seconds * outMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor3E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor4 RotateCClockwise(Limits, Position, Seconds) def FNTC_RotateCClockwise(Limits, Position, Seconds): Motor4A = 18 Motor4B = 12 Motor4E = 4 GPIO.setup(Motor4A,GPIO.OUT) GPIO.setup(Motor4B,GPIO.OUT) GPIO.setup(Motor4E,GPIO.OUT) CCWMultiplier = 1 if Position < Global_Motor4_baseRotate_range and Limits == True: # print Position, ' is < ' , Global_Motor4_baseRotate_range Position = Position + 1 # print "Rotate C-Clockwise" GPIO.output(Motor4A,GPIO.HIGH) GPIO.output(Motor4B,GPIO.LOW) GPIO.output(Motor4E,GPIO.HIGH) sleep(Seconds * CCWMultiplier) # print "Now stop" GPIO.output(Motor4E,GPIO.LOW) elif Limits == False: # print "Rotate C-Clockwise" GPIO.output(Motor4A,GPIO.HIGH) GPIO.output(Motor4B,GPIO.LOW) GPIO.output(Motor4E,GPIO.HIGH) sleep(Seconds * CCWMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor4E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor4 RotateClockwise(Limits, Position, Seconds) def FNTC_RotateClockwise(Limits, Position, Seconds): Motor4A = 18 Motor4B = 12 Motor4E = 4 GPIO.setup(Motor4A,GPIO.OUT) GPIO.setup(Motor4B,GPIO.OUT) GPIO.setup(Motor4E,GPIO.OUT) CWMultiplier = .99 if Position > (-1 * Global_Motor4_baseRotate_range) and Limits == True: # print Position, ' is < ' , Global_Motor4_baseRotate_range Position = Position - 1 # print "Rotate Clockwise" GPIO.output(Motor4A,GPIO.LOW) GPIO.output(Motor4B,GPIO.HIGH) GPIO.output(Motor4E,GPIO.HIGH) sleep(Seconds * CWMultiplier) # print "Now stop" GPIO.output(Motor4E,GPIO.LOW) elif Limits == False: # print "Rotate Clockwise" GPIO.output(Motor4A,GPIO.LOW) GPIO.output(Motor4B,GPIO.HIGH) GPIO.output(Motor4E,GPIO.HIGH) sleep(Seconds * CWMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor4E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor5 FNTC_Motor5LightLED(self.__LED_On) def FNTC_Motor5LightLED(LedIndicator): Motor5A = 6 Motor5B = 25 Motor5E = 5 GPIO.setup(Motor5A,GPIO.OUT) GPIO.setup(Motor5B,GPIO.OUT) GPIO.setup(Motor5E,GPIO.OUT) if LedIndicator == True: GPIO.output(Motor5A,GPIO.HIGH) GPIO.output(Motor5B,GPIO.LOW) GPIO.output(Motor5E,GPIO.HIGH) else: # print "Turn off LED" GPIO.output(Motor5E,GPIO.LOW) # Motor6 WristUp(Limits, Position, Seconds) def FNTC_WristUp(Limits, Position, Seconds): Motor6A = 15 Motor6B = 7 Motor6E = 14 GPIO.setup(Motor6A,GPIO.OUT) GPIO.setup(Motor6B,GPIO.OUT) GPIO.setup(Motor6E,GPIO.OUT) WristUpMultiplier = 1.0 if Position < Global_Motor6_WristRotate_range and Limits == True: # print Position, ' is < ' , Global_Motor6_move_in_out_range Position = Position + 1 # print "Move Out" GPIO.output(Motor6A,GPIO.HIGH) GPIO.output(Motor6B,GPIO.LOW) GPIO.output(Motor6E,GPIO.HIGH) sleep(Seconds * WristUpMultiplier) # print "Now stop" GPIO.output(Motor6E,GPIO.LOW) elif Limits == False: # print "Move Out" GPIO.output(Motor6A,GPIO.HIGH) GPIO.output(Motor6B,GPIO.LOW) GPIO.output(Motor6E,GPIO.HIGH) sleep(Seconds * WristUpMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor6E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # Motor6 WristDown(Limits, Position, Seconds) def FNTC_WristDown(Limits, Position, Seconds): Motor6A = 15 Motor6B = 7 Motor6E = 14 GPIO.setup(Motor6A,GPIO.OUT) GPIO.setup(Motor6B,GPIO.OUT) GPIO.setup(Motor6E,GPIO.OUT) WristDownMultiplier = 1.0 if Position > 0 and Limits == True: # print Position , ' is > 0 ' Position = Position - 1 # print "Move In" GPIO.output(Motor6A,GPIO.LOW) GPIO.output(Motor6B,GPIO.HIGH) GPIO.output(Motor6E,GPIO.HIGH) sleep(Seconds * WristDownMultiplier) # print "Now stop" GPIO.output(Motor6E,GPIO.LOW) elif Limits == False: # print "Move In" GPIO.output(Motor6A,GPIO.LOW) GPIO.output(Motor6B,GPIO.HIGH) GPIO.output(Motor6E,GPIO.HIGH) sleep(Seconds * WristDownMultiplier) # * 1.75) # print "Now stop" GPIO.output(Motor6E,GPIO.LOW) else: tkMessageBox.showinfo( "Maximum Reached", "You have reached the maximum limit of motion." ) return Position # **************************************************************** # Class definition for the main window class App: # Set limit variable __Calibration = True __LED_On = False # Set home position __Motor1_position = 0 __Motor2_position = 0 __Motor3_position = 0 __Motor4_position = 0 __Motor5_position = 0 __Motor6_position = 0 def __init__(self, master): OverallFrame = Frame(master, padx=5, pady=5, height=2, bd=1, relief=SUNKEN) OverallFrame.pack(fill=X, padx=5, pady=5) # Row 1 Controls frame = Frame(OverallFrame, padx=5, pady=3) frame.pack() self.Claw_Open = Button(frame, text="Claw Open", height=1, width=10, command=self.evt_claw_open) self.Claw_Open.pack(side=LEFT) self.Wrist_Up = Button(frame, text="Wrist Up", height=1, width=10, command=self.evt_wrist_up) self.Wrist_Up.pack(side=LEFT) self.Move_Up = Button(frame, text="Up", height=1, width=10, command=self.evt_up) self.Move_Up.pack(side=LEFT) self.Move_In = Button(frame, text="In", height=1, width=10, command=self.evt_in) self.Move_In.pack(side=LEFT) self.Rotate_Clockwise = Button(frame, text="Clockwise", height=1, width=10, command=self.evt_rotate_clockwise) self.Rotate_Clockwise.pack(side=LEFT) # Row 2 Controls frame2 = Frame(OverallFrame, padx=5, pady=3) frame2.pack() self.Claw_Close = Button(frame2, text="Claw Close", height=1, width=10, command=self.evt_claw_close) self.Claw_Close.pack(side=LEFT) self.Wrist_Down = Button(frame2, text="Wrist Down", height=1, width=10, command=self.evt_wrist_down) self.Wrist_Down.pack(side=LEFT) self.Move_Down = Button(frame2, text="Down", height=1, width=10, command=self.evt_down) self.Move_Down.pack(side=LEFT) self.Move_Out = Button(frame2, text="Out", height=1, width=10, command=self.evt_out) self.Move_Out.pack(side=LEFT) self.Rotate_CClockwise = Button(frame2, text="C-Clockwise", height=1, width=10, command=self.evt_rotate_cclockwise) self.Rotate_CClockwise.pack(side=LEFT) separator3 = Frame(OverallFrame, padx=5, pady=7, height=2, bd=1, relief=SUNKEN) separator3.pack(fill=X, padx=5, pady=5) # Form Footer frame3 = Frame(OverallFrame, padx=5, pady=5) frame3a = Frame(OverallFrame, padx=5, pady=3) frame3a.pack(side=LEFT) self.buttonLight = Checkbutton( frame3a, text="Light", command=self.evt_Light ) self.buttonLight.pack(side=LEFT) self.buttonCalibration = Checkbutton( frame3a, text="Calibration", command=self.evt_SetCalibration ) self.buttonCalibration.pack(side=LEFT) frame3c = Frame(OverallFrame, padx=5, pady=3) frame3c.pack(side=RIGHT) self.buttonQuit = Button( frame3c, text="QUIT", fg="red", command=self.evt_Quit ) self.buttonQuit.pack(side=RIGHT) # self.buttonExercise = Button( # frame3c, text="Exercise", command=self.evt_Exercise # ) # self.buttonExercise.pack(side=RIGHT) self.buttonProgram = Button( frame3c, text="Program", command=self.evt_Program ) self.buttonProgram.pack(side=RIGHT) frame3.pack() # End Form Footer def evt_Quit(self): # print "Quit" GPIO.cleanup() root.destroy() def evt_SetCalibration(self): if self.__Calibration == True: self.__Calibration = False else: self.__Calibration = True def evt_claw_open(self): # print "Claw Open" self.__Motor1_position = FNTC_ClawOut(self.__Calibration, self.__Motor1_position, Global_interval_in_seconds) def evt_claw_close(self): # print "Claw Close" self.__Motor1_position = FNTC_ClawIn(self.__Calibration, self.__Motor1_position, Global_interval_in_seconds) def evt_up(self): # print "Move Up" self.__Motor2_position = FNTC_MoveUp(self.__Calibration, self.__Motor2_position, Global_interval_in_seconds) def evt_down(self): # print "Move Down" self.__Motor2_position = FNTC_MoveDown(self.__Calibration, self.__Motor2_position, Global_interval_in_seconds) def evt_in(self): # print "Move In" self.__Motor3_position = FNTC_MoveIn(self.__Calibration, self.__Motor3_position, Global_interval_in_seconds) def evt_out(self): # print "Move Out" self.__Motor3_position = FNTC_MoveOut(self.__Calibration, self.__Motor3_position, Global_interval_in_seconds) def evt_rotate_clockwise(self): # print "Rotate Clockwise" self.__Motor4_position = FNTC_RotateClockwise(self.__Calibration, self.__Motor4_position, Global_interval_in_seconds) def evt_rotate_cclockwise(self): # print "Rotate Counter Clockwise" self.__Motor4_position = FNTC_RotateCClockwise(self.__Calibration, self.__Motor4_position, Global_interval_in_seconds) def evt_Light(self): # print "Light" if self.__LED_On == False: self.__LED_On = True else: self.__LED_On = False FNTC_Motor5LightLED(self.__LED_On) def evt_wrist_up(self): # print "Wrist Up" self.__Motor6_position = FNTC_WristUp(self.__Calibration, self.__Motor6_position, Global_interval_in_seconds) def evt_wrist_down(self): # print "Wrist Down" self.__Motor6_position = FNTC_WristDown(self.__Calibration, self.__Motor6_position, Global_interval_in_seconds) def evt_Program(self): # print "Move Up" incToMove = 18 while incToMove > 0: incToMove = incToMove -1 self.__Motor2_position = FNTC_MoveUp(False, self.__Motor2_position, Global_interval_in_seconds) # print "Rotate CCW" incToMove = 35 while incToMove > 0: incToMove = incToMove -1 self.__Motor4_position = FNTC_RotateCClockwise(False, self.__Motor4_position, Global_interval_in_seconds) # print "Wrist Up" incToMove = 31 while incToMove > 0: incToMove = incToMove -1 self.__Motor6_position = FNTC_WristUp(False, self.__Motor6_position, Global_interval_in_seconds) # print "Claw Out" incToMove = 12 while incToMove > 0: incToMove = incToMove -1 self.__Motor1_position = FNTC_ClawOut(False, self.__Motor1_position, Global_interval_in_seconds) # Turn on light FNTC_Motor5LightLED(True) # print "Wrist Down" incToMove = 31 while incToMove > 0: incToMove = incToMove -1 self.__Motor6_position = FNTC_WristDown(False, self.__Motor6_position, Global_interval_in_seconds) # print "Move Out" incToMove = 27 while incToMove > 0: incToMove = incToMove -1 self.__Motor3_position = FNTC_MoveOut(False, self.__Motor3_position, Global_interval_in_seconds) # print "Claw In" incToMove = 10 while incToMove > 0: incToMove = incToMove -1 self.__Motor1_position = FNTC_ClawIn(False, self.__Motor1_position, Global_interval_in_seconds) # Turn off light FNTC_Motor5LightLED(False) # print "Move In" incToMove = 31.25 while incToMove > 0: incToMove = incToMove -1 self.__Motor3_position = FNTC_MoveIn(False, self.__Motor3_position, Global_interval_in_seconds) # print "Rotate CW" incToMove = 34.5 while incToMove > 0: incToMove = incToMove -1 self.__Motor4_position = FNTC_RotateClockwise(False, self.__Motor4_position, Global_interval_in_seconds) # print "Claw Out" incToMove = 5 while incToMove > 0: incToMove = incToMove -1 self.__Motor1_position = FNTC_ClawOut(False, self.__Motor1_position, Global_interval_in_seconds) # print "Claw In" incToMove = 7 while incToMove > 0: incToMove = incToMove -1 self.__Motor1_position = FNTC_ClawIn(False, self.__Motor1_position, Global_interval_in_seconds) # print "Move Down" incToMove = 18 while incToMove > 0: incToMove = incToMove -1 self.__Motor2_position = FNTC_MoveDown(False, self.__Motor2_position, Global_interval_in_seconds) def evt_Exercise(self): # Move Up To Limiit while (self.__Motor2_position < Global_Motor2_move_up_down_range): self.__Motor2_position = FNTC_MoveUp(False, self.__Motor2_position, Global_interval_in_seconds) # Rotate CCW To Limiit while (self.__Motor4_position < Global_Motor4_baseRotate_range): self.__Motor4_position = FNTC_RotateCClockwise(True, self.__Motor4_position, Global_interval_in_seconds) # Wrist Up To Limiit while (self.__Motor6_position < Global_Motor6_WristRotate_range): self.__Motor6_position = FNTC_WristUp(True, self.__Motor6_position, Global_interval_in_seconds) # Open Claw To Limit while (self.__Motor1_position < Global_Motor1_claw_in_out_range): self.__Motor1_position = FNTC_ClawOut(True, self.__Motor1_position, Global_interval_in_seconds) # Turn on light FNTC_Motor5LightLED(True) # Wrist Down To Limiit while (self.__Motor6_position > 0): self.__Motor6_position = FNTC_WristDown(True, self.__Motor6_position, Global_interval_in_seconds) # Move Out To Limit while (self.__Motor3_position < Global_Motor3_move_in_out_range): self.__Motor3_position = FNTC_MoveOut(True, self.__Motor3_position, Global_interval_in_seconds) # Close Claw To Limit while (self.__Motor1_position > 0): self.__Motor1_position = FNTC_ClawIn(True, self.__Motor1_position, Global_interval_in_seconds) # Turn off light FNTC_Motor5LightLED(False) # Move In To Limit while (self.__Motor3_position > 0): self.__Motor3_position = FNTC_MoveIn(True, self.__Motor3_position, Global_interval_in_seconds) # Rotate CW To Home while (self.__Motor4_position > 0): self.__Motor4_position = FNTC_RotateClockwise(True, self.__Motor4_position, Global_interval_in_seconds) # Move Down To Limit while (self.__Motor2_position > 0): self.__Motor2_position = FNTC_MoveDown(True, self.__Motor2_position, Global_interval_in_seconds) # Function to center the main window def center(win): win.update_idletasks() width = 590 height = 140 x = ((win.winfo_screenwidth() - 75) // 2) - (width // 2) y = ((win.winfo_screenheight() - 100) // 2) - (height // 2) win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # Function to capture when [X] is clicked on the main window def X_wasClicked(): GPIO.cleanup() root.destroy() # END Functions # *************************************************************************************** # The Program Code Begins Below Here # START Program Code # ***************************** # Open and set the main window (here we name it 'root') root = Tk() root.title('Robot Control Panel') root.resizable(width=0, height=0) center(root) app = App(root) # Capture if the [X] button on the main window is closed root.protocol('WM_DELETE_WINDOW', X_wasClicked) # root is your main window root.mainloop()
-- Rat

Image


Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest

cron

© 2008 MAGIC RAT PRODUCTIONS
SEE ME ON FACEBOOK
Facebook