Stop the action when hit a wall.

parent fad80e16
......@@ -57,18 +57,26 @@ Acceptable values for *direction*:
### Examples
#### Action successfully completed
$ GET http://192.168.1.16:5000/move/forward/50
{"message": "OK", "direction": "forward", "action": "move"}
In this case the HTTP status code returned is 200.
#### Unable to understand the request
$ GET http://192.168.1.16:5000/move/nowhere
{"message": "Unknown direction", "direction": "nowhere", "action": "move"}
In this case the HTTP status code returned is 400.
#### Hit a wall
$ GET http://192.168.1.16:5000/move/forward?blocks=25
{"action": "move", "direction": "forward", "message": "hit_wall"}
## Retrieve values from sensors
## Retrieve values from sensors (not yet implemented)
$ GET http://192.168.1.16:5000/sensor/<sensor_name>
......
......@@ -17,8 +17,18 @@ __revision__ = "$Date: 2015/11/05 $"
__copyright__ = "Copyright (c) 2014-2015 Cédric Bonhomme"
__license__ = ""
import time
from ev3.ev3dev import Motor
from web import button
def stop(motorA, motorB):
"""
Stop the motors.
"""
motorA.stop()
motorB.stop()
def run_position_limited(motorA, motorB, position):
"""
Run for a limitied position.
......@@ -31,3 +41,11 @@ def run_position_limited(motorA, motorB, position):
motorB.run_position_limited(position_sp=position, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE, ramp_up_sp=1000,
amp_down_sp=1000)
# Wait for the completion of the command before sending the result
while "running" in motorA.state.split(" ") and \
"running" in motorB.state.split(" "):
time.sleep(0.1)
if button.is_pushed:
stop(motorA, motorB)
return "hit_wall"
return "OK"
......@@ -17,6 +17,7 @@ __revision__ = "$Date: 2015/11/04 $"
__copyright__ = "Copyright (c) 2014-2015 Cédric Bonhomme"
__license__ = ""
import time
from flask import render_template, current_app, request, session, \
url_for, redirect, g, send_from_directory, make_response, abort, Markup
from flask.ext.login import LoginManager, login_user, logout_user, \
......@@ -26,6 +27,7 @@ from ev3.ev3dev import Motor
import conf
from web.decorators import to_response
from web.lib import movements
from web import app
from web.lib import movements
from web import right_wheel, left_wheel, button, ir_sensor, color_sensor
......@@ -69,14 +71,8 @@ def move(direction="forward", speed=800):
nb_blocks = request.args.get("blocks", None)
if None is not nb_blocks:
position = int(nb_blocks) * 360
left_wheel.position = 0
left_wheel.run_position_limited(position_sp=position, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE, ramp_up_sp=1000,
ramp_down_sp=1000)
right_wheel.position = 0
right_wheel.run_position_limited(position_sp=position, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE, ramp_up_sp=1000,
amp_down_sp=1000)
result["message"] = movements.run_position_limited(left_wheel,
right_wheel, position)
else:
left_wheel.run_forever(speed * 1, regulation_mode=False)
right_wheel.run_forever(speed * 1, regulation_mode=False)
......@@ -85,14 +81,8 @@ def move(direction="forward", speed=800):
nb_blocks = request.args.get("blocks", None)
if None is not nb_blocks:
position = int(nb_blocks) * -360
left_wheel.position = 0
left_wheel.run_position_limited(position_sp=position, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE, ramp_up_sp=1000,
ramp_down_sp=1000)
right_wheel.position = 0
right_wheel.run_position_limited(position_sp=position, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE, ramp_up_sp=1000,
amp_down_sp=1000)
result["message"] = movements.run_position_limited(left_wheel,
right_wheel, position)
else:
left_wheel.run_forever(speed * -1, regulation_mode=False)
right_wheel.run_forever(speed * -1, regulation_mode=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment