From 7461f653e1caf677b24250cab80140d7c8557c7c Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Fri, 11 Mar 2022 18:44:54 -0500 Subject: [PATCH] Update hexapod.py --- software/raspberry pi/hexapod.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/software/raspberry pi/hexapod.py b/software/raspberry pi/hexapod.py index 140abff..120aa00 100644 --- a/software/raspberry pi/hexapod.py +++ b/software/raspberry pi/hexapod.py @@ -328,12 +328,13 @@ class Hexapod(Thread): data_array = cmd_string.split(',') if len(data_array) == 4: op = data_array[0].lstrip() + leg_idx = int(data_array[1]) - if leg_idx <0 or leg_idx >5: + if leg_idx < 0 or leg_idx > 5: return joint_idx = int(data_array[2]) - if joint_idx <0 or joint_idx >2: + if joint_idx < 0 or joint_idx > 2: return angle = float(data_array[3]) @@ -345,6 +346,13 @@ class Hexapod(Thread): config_str = 'leg'+str(leg_idx)+'Offset' self.config[config_str] = self.legs[leg_idx].correction + self.save_config() + + def save_config(self): + try: + json.dump(self.config, open('config.json', 'w+'), indent=4) + except PermissionError as err: + pass def run(self): while True: