Skip to content

Commit 3fe1a79

Browse files
committed
Direct control fix
1 parent 80fe9b9 commit 3fe1a79

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@ def stop():
117117
return 200
118118

119119
def move(data):
120-
bot.move(speed=data["speed"], elapse=data["elapse"], distance=data["distance"])
120+
try:
121+
bot.move(speed=data["speed"], elapse=data["elapse"], distance=data["distance"])
122+
except Exception as e:
123+
bot.move(speed=data["speed"], elapse=data["elapse"], distance=0)
121124
return 200
122125

123126
def turn(data):
124-
bot.turn(speed=data["speed"], time_elapse=data["elapse"])
127+
try:
128+
bot.turn(speed=data["speed"], elapse=data["elapse"])
129+
except Exception as e:
130+
bot.turn(speed=data["speed"], elapse=-1)
125131
return 200
126132

127133
def exec(data):
@@ -136,7 +142,7 @@ def status():
136142
try:
137143
with open('/home/pi/coderbot/logs/reset_trigger_service.log', 'r') as log_file:
138144
data = [x for x in log_file.read().split('\n') if x]
139-
except Exception:
145+
except Exception: # direct control case
140146
data = [] # if file doesn't exist, no restore as ever been performed. return empty data
141147

142148

rotary_encoder/wheelsaxel.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ def control_time(self, power_left=100, power_right=100, time_elapse=0):
8686
self._is_moving = True
8787

8888
# moving for desired time
89-
sleep(time_elapse)
90-
self.stop()
89+
# fixed for direct control that uses time_elapse -1 and stops manually
90+
if(time_elapse > 0):
91+
sleep(time_elapse)
92+
self.stop()
9193

9294
""" Motor distance control allows the motors
9395
to run for a certain amount of distance (mm) """
@@ -123,14 +125,17 @@ def stop(self):
123125

124126
# trying to fix distance different than zero after
125127
# wheels has stopped by re-resetting state after 0.5s
126-
sleep(0.5)
128+
sleep(0.1)
127129
self._left_motor.reset_state()
128130
self._right_motor.reset_state()
129131

130132
# updating state
131133
self._is_moving = False
132134
# restoring callback
133-
self._wheelsAxle_lock.release()
135+
try:
136+
self._wheelsAxle_lock.release()
137+
except Exception as e:
138+
pass
134139

135140
# CALLBACK
136141
def cancel_callback(self):

0 commit comments

Comments
 (0)