|
|
@ -93,7 +93,7 @@ class Hexapod(Thread):
|
|
|
|
|
|
|
|
|
|
|
|
self.calibration_mode = False
|
|
|
|
self.calibration_mode = False
|
|
|
|
|
|
|
|
|
|
|
|
with open('/home/cole/Downloads/hexapod/software/raspberry pi/config.json', 'r') as read_file:
|
|
|
|
with open('config.json', 'r') as read_file:
|
|
|
|
self.config = json.load(read_file)
|
|
|
|
self.config = json.load(read_file)
|
|
|
|
|
|
|
|
|
|
|
|
# legs' coordinates
|
|
|
|
# legs' coordinates
|
|
|
@ -116,40 +116,40 @@ class Hexapod(Thread):
|
|
|
|
self.mount_position[:, 1] = self.mount_y
|
|
|
|
self.mount_position[:, 1] = self.mount_y
|
|
|
|
|
|
|
|
|
|
|
|
# Objects
|
|
|
|
# Objects
|
|
|
|
self.pca_right = ServoKit(channels=18, address="/dev/ttyUSB0", frequency=0x0c)
|
|
|
|
self.pca_right = ServoKit(channels=18, address="/dev/ttyACM0", frequency=0x0c)
|
|
|
|
self.pca_left = ServoKit(channels=18, address="/dev/ttyUSB0", frequency=0x0d)
|
|
|
|
#self.pca_left = ServoKit(channels=18, address="/dev/ttyACM0", frequency=0x0c)
|
|
|
|
|
|
|
|
self.pca_left = self.pca_right
|
|
|
|
self.legs = [
|
|
|
|
self.legs = [
|
|
|
|
# front right
|
|
|
|
# front right
|
|
|
|
Leg(0,
|
|
|
|
Leg(0,
|
|
|
|
[self.pca_left.servo[15], self.pca_left.servo[14],
|
|
|
|
[self.pca_left.servo[2], self.pca_left.servo[1],
|
|
|
|
self.pca_left.servo[13]],
|
|
|
|
self.pca_left.servo[0]],
|
|
|
|
correction=self.config.get('leg0Offset', [0, 0, 0])),
|
|
|
|
correction=self.config.get('leg0Offset', [0, 0, 0]), scale=self.config.get('leg0Scale', [1, 1, 1])),
|
|
|
|
# center right
|
|
|
|
# center right
|
|
|
|
Leg(1,
|
|
|
|
Leg(1,
|
|
|
|
[self.pca_left.servo[8], self.pca_left.servo[4],
|
|
|
|
[self.pca_left.servo[6], self.pca_left.servo[7],
|
|
|
|
self.pca_left.servo[11]],
|
|
|
|
self.pca_left.servo[8]],
|
|
|
|
correction=self.config.get('leg1Offset', [0, 0, 0])),
|
|
|
|
correction=self.config.get('leg1Offset', [0, 0, 0]), scale=self.config.get('leg1Scale', [1, 1, 1])),
|
|
|
|
# rear right
|
|
|
|
# rear right
|
|
|
|
Leg(2,
|
|
|
|
Leg(2,
|
|
|
|
[self.pca_left.servo[0], self.pca_left.servo[1],
|
|
|
|
[self.pca_left.servo[12], self.pca_left.servo[13],
|
|
|
|
self.pca_left.servo[2]],
|
|
|
|
self.pca_left.servo[14]],
|
|
|
|
correction=self.config.get('leg2Offset', [0, 0, 0])),
|
|
|
|
correction=self.config.get('leg2Offset', [0, 0, 0]), scale=self.config.get('leg2Scale', [1, 1, 1])),
|
|
|
|
# rear left
|
|
|
|
# rear left
|
|
|
|
Leg(3,
|
|
|
|
Leg(3,
|
|
|
|
[self.pca_right.servo[15], self.pca_right.servo[14],
|
|
|
|
[self.pca_right.servo[15], self.pca_right.servo[16],
|
|
|
|
self.pca_right.servo[13]],
|
|
|
|
self.pca_right.servo[17]],
|
|
|
|
correction=self.config.get('leg3Offset', [0, 0, 0])),
|
|
|
|
correction=self.config.get('leg3Offset', [0, 0, 0]), scale=self.config.get('leg3Scale', [1, 1, 1])),
|
|
|
|
# center left
|
|
|
|
# center left
|
|
|
|
Leg(4,
|
|
|
|
Leg(4,
|
|
|
|
[self.pca_right.servo[7], self.pca_right.servo[11],
|
|
|
|
[self.pca_right.servo[9], self.pca_right.servo[10],
|
|
|
|
self.pca_right.servo[6]],
|
|
|
|
self.pca_right.servo[11]],
|
|
|
|
correction=self.config.get('leg4Offset', [0, 0, 0])),
|
|
|
|
correction=self.config.get('leg4Offset', [0, 0, 0]), scale=self.config.get('leg4Scale', [1, 1, 1])),
|
|
|
|
# front left
|
|
|
|
# front left
|
|
|
|
Leg(5,
|
|
|
|
Leg(5,
|
|
|
|
[self.pca_right.servo[0], self.pca_right.servo[2],
|
|
|
|
[self.pca_right.servo[5], self.pca_right.servo[4],
|
|
|
|
self.pca_right.servo[5]],
|
|
|
|
self.pca_right.servo[3]],
|
|
|
|
correction=self.config.get('leg5Offset', [0, 0, 0]))]
|
|
|
|
correction=self.config.get('leg5Offset', [0, 0, 0]), scale=self.config.get('leg5Scale', [1, 1, 1]))]
|
|
|
|
|
|
|
|
|
|
|
|
# self.leg_0.reset(True)
|
|
|
|
# self.leg_0.reset(True)
|
|
|
|
# self.leg_1.reset(True)
|
|
|
|
# self.leg_1.reset(True)
|
|
|
@ -263,7 +263,7 @@ class Hexapod(Thread):
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
cmd_string = self.cmd_queue.get(block=False)
|
|
|
|
cmd_string = self.cmd_queue.get(block=False)
|
|
|
|
print('interrput')
|
|
|
|
print('interrupt')
|
|
|
|
except Empty:
|
|
|
|
except Empty:
|
|
|
|
# time.sleep(self.interval)
|
|
|
|
# time.sleep(self.interval)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -300,7 +300,6 @@ class Hexapod(Thread):
|
|
|
|
|
|
|
|
|
|
|
|
angles[:, 1] = 90-((ar + a1) * 180 / np.pi)
|
|
|
|
angles[:, 1] = 90-((ar + a1) * 180 / np.pi)
|
|
|
|
angles[:, 2] = (90 - ((a1 + a2) * 180 / np.pi))+90
|
|
|
|
angles[:, 2] = (90 - ((a1 + a2) * 180 / np.pi))+90
|
|
|
|
|
|
|
|
|
|
|
|
return angles
|
|
|
|
return angles
|
|
|
|
|
|
|
|
|
|
|
|
def cmd_handler(self, cmd_string):
|
|
|
|
def cmd_handler(self, cmd_string):
|
|
|
@ -352,7 +351,7 @@ class Hexapod(Thread):
|
|
|
|
def save_config(self):
|
|
|
|
def save_config(self):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
json.dump(self.config, open(
|
|
|
|
json.dump(self.config, open(
|
|
|
|
'/home/pi/hexapod/software/raspberry pi/config.json', 'w+'), indent=4)
|
|
|
|
'/home/amelia/hexapod/software/raspberry pi/config2.json', 'w+'), indent=4)
|
|
|
|
except PermissionError as err:
|
|
|
|
except PermissionError as err:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
@ -362,7 +361,7 @@ class Hexapod(Thread):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
cmd_string = self.cmd_queue.get(block=False)
|
|
|
|
cmd_string = self.cmd_queue.get(block=False)
|
|
|
|
except Empty:
|
|
|
|
except Empty:
|
|
|
|
# time.sleep(self.interval)
|
|
|
|
#time.sleep(self.interval)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.cmd_handler(cmd_string)
|
|
|
|
self.cmd_handler(cmd_string)
|
|
|
|