From 6ba63d71608ea283bbd8e49538ec5bbf8339a6dd Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Sun, 6 Mar 2022 22:09:50 -0500 Subject: [PATCH] Update hexapod.py --- software/raspberry pi/hexapod.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/software/raspberry pi/hexapod.py b/software/raspberry pi/hexapod.py index b7856fa..7f873ce 100644 --- a/software/raspberry pi/hexapod.py +++ b/software/raspberry pi/hexapod.py @@ -81,12 +81,17 @@ class Hexapod(Thread): CMD_TWIST = 'twist' + CMD_CALIBRATION = 'calibration' + CMD_NORMAL = 'normal' + def __init__(self, in_cmd_queue): Thread.__init__(self) self.cmd_queue = in_cmd_queue self.interval = 0.005 + self.calibration_mode = False + with open('/home/pi/hexapod/software/raspberry pi/config.json', 'r') as read_file: self.config = json.load(read_file) @@ -298,7 +303,14 @@ class Hexapod(Thread): def cmd_handler(self, cmd_string): data = cmd_string.split(':')[-2] - self.current_motion = self.cmd_dict.get(data, self.standby_posture) + + if data == self.CMD_CALIBRATION: + self.calibration_mode = True + elif data == self.CMD_NORMAL: + self.calibration_mode = False + + if not self.calibration_mode: + self.current_motion = self.cmd_dict.get(data, self.standby_posture) self.cmd_queue.task_done() @@ -313,10 +325,11 @@ class Hexapod(Thread): else: self.cmd_handler(cmd_string) - if self.current_motion['type'] == 'motion': - self.motion(self.current_motion['coord']) - elif self.current_motion['type'] == 'posture': - self.posture(self.current_motion['coord']) + if not self.calibration_mode: + if self.current_motion['type'] == 'motion': + self.motion(self.current_motion['coord']) + elif self.current_motion['type'] == 'posture': + self.posture(self.current_motion['coord']) def main():