Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EV3WebController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Science Festival 2015
EV3WebController
Commits
3066b3fd
Unverified
Commit
3066b3fd
authored
Nov 05, 2015
by
Cédric Bonhomme
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop the action when hit a wall.
parent
fad80e16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
17 deletions
+33
-17
README.md
README.md
+9
-1
web/lib/movements.py
web/lib/movements.py
+18
-0
web/views/views.py
web/views/views.py
+6
-16
No files found.
README.md
View file @
3066b3fd
...
...
@@ -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>
...
...
web/lib/movements.py
View file @
3066b3fd
...
...
@@ -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"
web/views/views.py
View file @
3066b3fd
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment