-
Notifications
You must be signed in to change notification settings - Fork 1
Move Forward: Use case example
This document outlines what happens when a user opens the control page and uses the forward button.
-
Flask-Babel (the python webserver) prepares the template
control.html
by replacing any{%
%}
tagged elements with valid HTML. This includes config data and natural language translations. -
The page is sent to the client web browser and rendered on their screen (including the button with the id
id="b_forward"
). -
JavaScript code is tied to elements in the page
$(document).on("pagecreate",'#page-control', function(event) {}
as defined incontrol.js
-
For the button with
id="b_forward"
(and with a browser on a touch-capable device) the following JavaScript code events are attached to the button when the page loads:$('#b_forward') .on("touchstart", function (){bot.move(CODERBOT_CTRL_FW_SPEED,CODERBOT_CTRL_FW_ELAPSE);}) .on("touchend", function (){bot.stop();});
-
The
"touchstart"
event is fired and the anonymous function above is triggered. The function executesbot.move()
referring to an object calledbot
which is initialized at the top of the filecontrol.js
. -
The object bot is of type Coderbot whose definition is found in
coderbot.js
. The functionbot.move
, the one executed on the"touchstart"
event, actually translates toCoderBot.prototype.move = function(speed, amount) {...}
, which then refers tothis.command()
, which is defined byCoderBot.prototype.command = function(cmd, param1, param2) {...}
. (these are all contained incoderbot.js
) -
In the
command()
function definition, the line$.ajax({url: this.url, data: data, async: true, type: "GET"});
executes a python function on the server inmain.py
. The function that handles this kind of request is calledhandle_bot()
. Recall that the cmd parameter sent was 'move'. -
handle_bot()
results in execution ofbot.move(speed=int(param1), elapse=float(param2))
. Note that when the server was started viarun_server()
inmain.py
the objectbot
was initialized. -
The definition for
bot_move()
is located incoderbot.py
and finally results in servo actuation.