-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinematicFrameWorkTest.py
210 lines (206 loc) · 8.06 KB
/
KinematicFrameWorkTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
# Author :Mr.Chanapai Chuadchum
# Project name :RoboticArm Kinematic Sim Con 'RKSC system'
# Describetion: Use with Jetson Tk1 and Vision System function on the CUDA
import numpy as np # Numpy function for the math and matrix calculation function
import matplotlib.pyplot as plt
from nanpy import (ArduinoApi,SerialManager)
from nanpy import Servo
from nanpy import serial_manager
from nanpy import CapacitiveSensor # Capacitive sensor input
from nanpy import DHT,DallasTemperature
from nanpy.arduinotree import ArduinoTree # Arduino Tree function
import time # Time control delaytion
#Connection of the System on the serial communication system
connection = SerialManager('/dev/ttyACM0',115200) # Serial communication via MCU function
a = ArduinoApi(connection=connection) # Connection with the serial magnager
connectionBody = SerialManager('/dev/ttyACM1',115200) # Serial sensing and control
b = ArduinoApi(connection=connectionBody) # The Body and sensing connection for the system of therobotic arm
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Servo part for the robotic arm
servo3e = Servo(3)
servo3u = Servo(4)
servo1u = Servo(5)
servo1e = Servo(8)
servo2u = Servo(9)
servo2e = Servo(10)
# Servo for the robotic wrist of the arm
servoWrist= Servo(43) # Wrist servo
servowristrotate = Servo(44) # Wrist rotate servo
# Stepper motor at the finger
#Finger 1
a.pinMode(11,a.OUTPUT) #dir
a.pinMode(12,a.OUTPUT) #step
#Finger 2
a.pinMode(2,a.OUTPUT) #dir
a.pinMode(6,a.OUTPUT) #step
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Stepper motor at the Body arm
#Elbow
a.pinMode(23,a.OUTPUT) #dir
a.pinMode(24,a.OUTPUT) #step
#Shoulder
a.pinMode(25,a.OUTPUT) #dir
a.pinMode(26,a.OUTPUT) #step
#Base
a.pinMode(27,a.OUTPUT) #dir
a.pinMode(28,a.OUTPUT) #step
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Stepper motor Motor power cotrol function
a.pinMode(29,a.OUTPUT) #Stepper motor Base power on/off
a.pinMode(30,a.OUTOUT) #Stepper motor Shoulder power on/off
a.pinMode(31,a.OUTPUT) #Stepper motor Elbow power on/off
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
a.pinMode(32,a.INPUT)
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Function of the i2c Address communication
def ItwoCmain():
connection = SerialManager(sleep_after_connect=2)
connection.open()
print(connection.device)
a = ArduinoTree(connection=connection)
master = I2C_Master(a.wire)
master.send(I2C_ADDRESS,[0b00001000])
def BaseJoint(dir,step,speed,timing): # Robotic Base Joint control
if dir == 1 :
a.digitalWrite(27,a.HIGH)
for move in range(0,step,1):
a.digitalWrite(28,a.HIGH)
time.sleep(speed)
a.digitalWrite(28,a.LOW)
if dir == 0:
a.digitalWrite(27,a.LOW)
for move in range(0,step,1):
a.digitalWrite(28,a.HIGH)
time.sleep(speed)
a.digitalWrite(28,a.LOW)
time.sleep(speed)
def ElbowJoint(dir,step,speed,timing): # Robotic Elbow Joint control
if dir == 1:
a.digitalWrite(23,a.HIGH) #Forward
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.ditialWrite(24,a.LOW)
time.sleep(speed)
if dir == 0:
a.digitalWrite(23,a.LOW) # Inverse
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.digitalWrite(24,a.LOW)
time.sleep(speed)
def ShouelderJoint(dir,step,speed,timing): # Robotic Shoulder Joint control
if dir == 1:
a.digitalWrite(25,a.HIGH) #Forward
for move in range(0,step,1):
a.digitalWrite(26,a.HIGH)
time.sleep(speed)
a.ditialWrite(26,a.LOW)
time.sleep(speed)
if dir == 0:
a.digitalWrite(25,a.LOW) # Inverse
for move in range(0,step,1):
a.digitalWrite(26,a.HIGH)
time.sleep(speed)
a.digitalWrite(26,a.LOW)
time.sleep(speed)
def Wrist_servo(dir,AngleF,AngleI,speed):
if dir == 1:
for move in range(AngleF,AngleI,1):
servoWrist.write(move)
time.sleep(speed)
if dir == 0:
for move in range(AngleI,AngleF,-1):
servoWrist.write(move)
time.sleep(speed)
def Wristrotate_servo(dir,AngleF,AngleI,speed):
if dir == 1:
for move in range(AngleF,AngleI,speed):
servoWrist.write(move)
time.sleep(speed)
if dir == 0:
for move in range(AngleI,AngleF,speed):
servoWrist.write(move)
time.sleep(speed)
def StepperFinger2(dir,step,speed,timing): # Robotic Finger joint control
if dir == 1:
a.digitalWrite(23,a.HIGH) #Forward
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.ditialWrite(24,a.LOW)
time.sleep(speed)
if dir == 0:
a.digitalWrite(23,a.LOW) # Inverse
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.digitalWrite(24,a.LOW)
time.sleep(speed)
def StepperFinger3(dir,step,speed,timing):
if dir == 1:
a.digitalWrite(23,a.HIGH) #Forward
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.ditialWrite(24,a.LOW)
time.sleep(speed)
if dir == 0:
a.digitalWrite(23,a.LOW) # Inverse
for move in range(0,step,1):
a.digitalWrite(24,a.HIGH)
time.sleep(speed)
a.digitalWrite(24,a.LOW)
time.sleep(speed)
def Hand_SensoryFunction(x,y,z,State):
if State == 1 : #Catch
if State == 0 : #Catch
def BarrettFingercontrol(dir1,dir2,dir3,dir4,dir5,AngleI1,AngleI2,AngleI3,AngleF1,AnngleF2,AngleF3,Speed,step2,step3,timing):
#Finger 1 functional positioning control
Finger1(dir1,AngleI1,AngleF1,Speed)
#Finger 2 functional position control
Finger2(dir2,AngleI2,AngleF2,Speed)
#Finger 3 funtional position control
Finger3(dir3,AngleI3,AngleF3,Speed)
#Finger 3 rotator
StepperFinger3(dir5,step3,speed,timing)
#Finger 2 rotator
StepperFinger2(dir4,step2,speed,timing)
# Finger control for the robot barrett hand
def Finger1(dir,AngleI,AngleF,speed):
if dir == 1:
for move in range(AngleF,AngleI,1): #Finger move catch
servo1u.write(4+move)
servo1e.write(5+move) #Finger 1 move catch
time.sleep(speed) # Speed control function for the servo motor
else if dir == 0 :
for move in range(AngleI,AngleF,-1):
servo1u.write(4+move)
servo1e.write(5+move)
time.sleep(speed) #Speed control function for the servo motor
def Finger2(dir,AngleI,AngleF,speed):
if dir == 1:
for move in range(AngleF,AngleI,1): #Finger move catch
servo2u.write(170-move)
servo2e.write(move)
time.sleep(speed) # Speed control function for the servo motor
else if dir == 0 :
for move in range(AngleI,AngleF,-1):
servo2u.write(180-move)
servo2e.write(move)
time.sleep(speed) #Speed control function for the servo motor
def Finger3(dir,AngleI,AngleF,speed):
if dir == 1:
for move in range(AngleF,AngleI,1):
servo3e.write(10-move)
servo3u.write(move)
time.sleep(speed) # speed control function for the servo motor
else if dir == 0:
for move in range(AngleI,AngleF,-1):
servo3e.write(move)
servo3u.write(move)
time.sleep(speed) #Speed control function for the servo motor
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if __name__ = '__manin__': # Working and End not the loop
#ItwoCmain()