Mission

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Servos)
(Servos)
Line 137: Line 137:
  
 
Example:
 
Example:
 +
 +
  label=20,servo=3,pservo=-300:time=1
 +
  servo=3,pservo=200:time=1
 +
  goto=20
 +
 +
This example will move servo 3 from position -300 to position 200 with 1 second interval.
  
 
====Threads====
 
====Threads====

Revision as of 11:32, 12 March 2020

Back to Regbot main page.

Contents

Mission

Missions are entered through the mission tab:

Gui mission.png

Figure 7. Missions are entered in the left (white) area and can be syntax tested with the button above. The result of the check is shown in the yellow area (right). The mission actually on the robot can be fetched to the right area. Missions (the left area) can be saved and loaded from text files with the buttons below.

If you copy-paste from another application, so make sure not to include any formatting, 7-bit ASCII characters are allowed only.

Missions are not saved to the robot before you press "save to robot".

The mission is lost for the robot after a power cycle unless you save the configuration to robot flash - using the "save to robot flash" to in the left pane.

Mission lines

Mission specification consists of mission lines, each line consist of two (lower case) parts divided by ':'

drive parameter: continue condition (conditions are OR'ed) 

e.g.:

vel=-0.2, acc=3.0 : dist=1, time=12

Drive backwards at a speed of 0.2m/s, accelerate with 3m/s2 for 1 meter (or max 12 seconds)


Extended Backus–Naur form (EBNF)

  • Full_mission = {[thread_id_line] mission};
  • thread_id_line = 'thread=' id ['event=' value] [: 'event=' value] '\n';
  • id = ? integer number ?
  • mission = { mission_line };
  • mission_line = [parameter], {',' prameter}, [':' , [continue_condition], {',' continue_condition}] '\n';
  • parameter = value_parameter | string_command;
  • value_parameter = parameter_name, '=', value;
  • string_command = 'cmd=', string_value;
  • string_value = string_delimiter, string, string_delimiter;
  • string_delimiter = "'" | '"';
  • string = ? any command string known by the firmware ?;
  • parameter_name = 'vel' | 'acc' | 'log' | 'tr' | 'bal' | 'head' | 'topos' | 'edgel' | 'edger' | 'white' | 'irsensor' | 'irdist' |'servo' | 'pservo' | 'label' | 'goto' | 'event';
  • value = ? float or integer ?;
  • continue_condition = condition_name compare_operator value;
  • compare_operator = '=' | '<' | '>' | '!'
  • condition_name = 'dist' | 'time' | 'turn' | 'count' | 'xl' | 'lv' | 'ir1' | 'ir2' | 'tilt' | 'event' | 'log' | 'head' | 'last';

(NB! string_command not implemented yet).

See Wikipedia for EBNF syntax.

Drive values

  • VEL is the velocity in m/s - positive is forward, 0=stop. uses last value if omitted.
  • ACC is acceleration limit in m/s2. Uses last value if omitted.
  • TR is turn radius in metre - positive, 0 is turn on the spot. straight if omitted. NB! in balance the minimum turn radius is about 0.07m, as balance requires that at least one wheel can give a forward acceleration.
  • BAL is balancing, uses last value if omitted, e.g.:
bal=1, vel=0: time = 2
vel=0.4 : dist = 0.5
tr=0.2 : turn=-90
bal=0, vel=0

This code starts getting into balance and set velocity to 0 for 2 seconds (it is a good idea to allow the robot to stabilize before continuing). Then runs 0.5m and turns 90 degrees to the right (CV) with a turning radius of 20cm - and while balancing. Then stop and go out of balance.

  • HEAD is reference heading in degrees (-180 .. 180), set as heading reference. This is primarily for small heading changes, else use the turn radius command "TR"
vel=0.3,acc=3 : dist=0.2
head = 30 : dist=0.3

This mission starts straight for 20cm (heading 0), then changes heading to 30 degrees (CCV) for another 30cm. This will make the left wheel slow down and potentially go backwards to get to the new angle as fast as acceleration allows (here 3m/s2).

  • TOPOS engages a position controller that runs to this position (forward or backwards) relative to current position, e.g.:
vel=0.3,topos=1 : time=5
vel=0.3,topos=-1 : time=5

This goes forward for 1 meter (starting with the maximum velocity the controller allows, here 0.3m/s) and keeps the position 1m from the start (of this line). And stays there until the 5 seconds have passed, then goes back to the start position. NB! velocity "vel=xx" must (pt) be specified on all lines that use "topos=yy".

Log

  • LOG is log interval in milliseconds. Once started it continues until the buffer is full.

To log a velocity step response, a mission could be:

vel=0.3,log=1:time=0.3
vel=0.5:log=0

The first line starts the robot with a velocity of 0.3m/s and starts logging (log=1) the log value is log interval in ms.

After 0.3 seconds velocity is stepped to 0.5m/s until the log is full (the log=0 after the ':' - see continue condition below)

Note that the log is generated in RAM on the robot with limited space (approximately 30kBytes - which gives from 40 (all points) to 2000 samples), so limit the interface points logged to get longer logging time.

GOTO

  • LABEL is a label number that can be used by GOTO.
  • GOTO is a jump to the label number given. This can be limited to COUNT use of goto, the count is then reset after the first skip. The goto can also be skipped if any other conditions are true when this line is reached. A line with a goto will never wait.

See a GOTO example below under threads.

Line edge sensor

If a line sensor is installed, then the following should work too:

  • EDGER is following Right edge of the line. Value can be in interval -2..2 (in cm). Edge=0 to follow directly over the edge, value edge=1 follows 1cm to the right of the line.
  • EDGEL is following Left edge of line at -2..2 (in cm), positive is right
  • WHITE set to 1 if the follow-line tape is white, else 0 to follow a black line. White is also needed when LV (line valid) or XL (crossing line) is used in the condition part of a line.

The edge follower can only be used when driving forward (line sensor must be in front of the wheel line).

Distance sensor

If IR distance sensors are installed, then these should work:

  • IRSENSOR is IR-sensor to use (1 is the distance to a wall, and 2 is the distance in front).
  • IRDist is IR-distance to hold.

Servos

Control of servos, there is support for up to 3 servos (version 3 only). There is 2 extra pins, one analog pin DAC (called servo 4) (real D/A converter) and one digital pin (24) called servo 5.

  • SERVO=N PSERVO=XXX where N is servo number (1..5) and XXX is servo position, for servo 1,2 and 3 value is in range +/- 1000, where 0 is 1.5 ms, +500 is 2ms, + 1000 is 2.5ms, -500 is 1ms and -1000 is 0.5ms pulse with with at pulse frequency of 333 Hz. For servo 4 value is analog value -1000 is minimum and +1000 is maximum. for servo 5 (digital pin) XXX=0 is Low (0V) and XXX=1 is High (3.3V).

Example:

  label=20,servo=3,pservo=-300:time=1
  servo=3,pservo=200:time=1
  goto=20

This example will move servo 3 from position -300 to position 200 with 1 second interval.

Threads

A command sequence may be divided into threads. The default thread has number 1.

  • THREAD=3 means that this and all following lines are handled by one thread (with number 3). All threads are activated at time 0.
  • THREAD=4, event=30 : event=31 means that this thread (4) is not activated until an event 30 has occurred, and is deactivated if an event 31 occurs.

When a thread is not active, then all lines in the thread is ignored. When a thread is activated, then the first line in the thread is implemented.

Example

thread=0
   log=20: log=0
   event=0
thread=2
   label=1
   vel=0.4: time=1.0
   vel=0.2: time=1.0
   vel=0.0: time=1.0
   event=3 : event=7
   vel=0.2, tr=0.15:turn=90
   goto=1
thread=9
   bal=0:event=3
   bal=1: time=2
   label=12
   event=7:time=0.1
   goto=12
thread=10
   label=20,servo=1,pservo=-300:time=1
   servo=1,pservo=200:time=1
   goto=20

Thread 0: This thread controls the logging function with the condition 'log=0' that is true when the log is full, then the mission is stopped. 'event=0' is a special event that stops the mission.

Thread 2: This thread controls velocity in three steps 0.4m/s, 0.2 m/s and 0m/s, then sends an event (event=3) and waits for event 7. When event 7 arrives then the robot turns 90 degrees and starts over.

Thread 9: This thread controls the balance. Starts with no balance, until event 3 occurs, then goes into balance mode and waits 2 seconds (to stabilize in balance). Then it enters a loop that emits event 7 every 0.1 seconds, to keep thread 2 going.

Thread 10: this is a servo control thread, that moves servo 1 between 2 positions.

The mission is finished when all threads have ended, in this case when the log is full.

The thread number is pt. not used to determine the execution order of the threads (uses script order).

Events

Events can be generated if an event=X command is entered in the parameter side of the colon. The event is activated when the line is activated. More than one event can be activated in the same line, e.g.:

vel=0.2,event=7,event=12:time=1
event=0

Here event 7 and 12 are activated at the same time as the velocity is set to 0.2.

Event 0 has a special meaning and will terminate mission NOW (all threads)!

Events are used in the examples above.

Continue conditions

':' is separation of parameters and continue condition.

  • DIST is driven distance in this mission line - positive meters
  • TURN is angle turned in this mission line - degrees, positive is Left (CCW if forward speed)
  • TIME is max time in this mission line - positive seconds
  • COUNT is used with GOTO and GOTO will be ignored, if this line is executed more than this count
  • XL,LV is conditions relevant for the line sensor (if implemented) - see below
  • IR1,IR2 is conditions relevant for IR distance sensors - se below
  • TILT is tilt angle (especially useful if not in balance.
  • EVENT is testing for events
  • LOG is true when log is full (value is ignored, but must be set to a number (e.g. 0))
  • HEAD is absolute heading test, head=175 is true if the actual heading is within 3 degrees of this value. head>XXX and head<YYY compares with the current value but is difficult to use when crossing the +/- 180 deg border.
  • LAST tests the triggering condition of the last drive line (goto lines excluded). last=X and last<x last>x, last!x can be used as equal, less, greater than or not the last set continue condition.

The equal (=) sign can for some values (dist, turn, xl and tilt) be replaced by '<' or '>', for most values (except xl and head) an equal sign means equal or greater. NB! '>=', '==', '<=' and '!=' are not valid.

Example: Drive 0.2m then turn 30 deg to the right (turn radius=0, but will be more with acceleration being only 1m/s2) then drive another 1 second at a higher speed (or maximum 0.4m).

vel=0.2,acc=1 : dist=0.2
tr=0 : turn = -30
vel=0.5 : dist=0.4,time=1

Example Zig-zag sideways: drive 0.2m backwards and then turn 45 deg left, 45 deg right and a bit forward, repeated 2 times more with a goto (to label=6).

vel=-0.2, acc=2.0: dist=0.2
label=6:
tr=0.15: turn=45.0
tr=0.15: turn=-45.0
vel=0.2:dist=0.18
vel=-0.2,goto=6: count=2

Line sensor

This section is valid if a line sensor is installed and calibrated. Use "Edge" tab for calibration (put edge sensor "ON" and on a dark background and press "Calibrate no reflection" and then on a bright background and press "Calibrate white reflection", then "save on robot").

  • XL is test for crossing line (in current colour (set WHITE=1 or WHITE=0), value is 0..20, 0 is true on no crossing, 1..20 is confidence in crossing (20 is highest). This crossing flag is set when the width of the line is above the value given in a settable parameter (typically 6.5cm is a good value - a new method may be implemented).
  • LV is test for valid line 0=true for no valid line, 1..5=for valid line confidence, 5 is maximum and indicated that at least 5 line detections (increase on detect, decrease on miss). Line is valid even during detection of a crossing line (but the robot will go straight while a crossing line is detected, see below).

A special detection scheme for crossing lines is used to avoid following the crossing line. Edge control is disabled if the edge is too wide or gets wide too fast. Control is resumed when the crossing line condition is no longer valid.

Example: Drive until a crossing black line is found or 2.5m is driven, then continue until the crossing line is gone (reached other side of the line) and stop

vel=0.2, log=5, acc=2, white=0: xl>16, dist=2.5
:xl < 4,dist=0.2
vel=0:time=0.1

Example find the white line and follow edge: Drive until a (white) line is found - as before - then turn to the right and follow the line for 0.5 m.

vel=0.2, log=5, acc=2: xl>16, dist=2.5
:xl < 4,dist=0.2
vel=0:time=0.3
tr=0,vel=0.2:turn=-90
edgel=0, white=1: dist=0.5

NB! Line sensor should be calibrated in balance if used in balance.

Distance sensor

IR1, IR2 is test for the distance measured by the IR sensor.

e.g.: drive until close to an object seen by IR sensor 2 with a measurement closer than 25cm.

thread=1
  vel=0.35 : ir2 < 0.25
  vel=0 : time=0.5

Tilt balance angle

TILT is test for tilt angle (0 is balance point)

Example:

@todo

Events

An event can be a test condition in a mission line and can be generated by a mission line. Up to 32 events can be used, they are named "event=N", where N is a number in the range [0..31]. An event is valid for one sample period only (1ms).

Events can be created from the communication interface with the command like

<event=5>

An example could be like this (a not very functional example)

thread=2
  vel=0.2:time=1          # driving at speed 0.2 m/s for 1 second
  vel=0,event=7:event=5   # set speed to 0 and generate event 7, then wait for event 5
  vel=0.2:time=1          # speed back to 0.2 m/s in 1 second
  vel=0                   # stop this thread
thread=8
  label=1:time=5,event=7  # wait for event 7 (generated after 1 second by thread 2) or for maximum 5 seconds (should never happen)
  event=12:time=1         # generate event 12 (and wait for 1 second)
  event=13:time=1         # generate event 13 (and wait for 1 second before ending this thread

The mission will not end before the user has generated event 5 (by sending "<event=5>"). Every time an event is generated a message is sent to the client line, for this mission the following messages will be generated:

# event 7
# event 12
# event 13
# event 5     (this in response to a user event)

Event 0 can't be tested, it will terminate the mission immediately.

LAST continue condition

(new in firmware version 599)

When a line ends, it is sometimes useful to know what triggered the line to finish, e.g.

thread=1
   vel=0.3,acc=1,log=1,white=1:time=12,dist=2,lv=1
   goto=4:last=6
   vel=-0.3:dist=0.2
   label=4,vel=0:time=1

In this case, the first line runs the robot at 0.3 m/s until either 12 seconds has passed or driven 2 meters or a line detection is valid.

The next line is a goto with a LAST=6 condition, and LAST is a continue condition based on what ended the last line, if it was a 6 (line edge valid), then the goto is skipped and the robot goes backwards 0.2 m, if the was no valid line edge, then the goto=4 is executed and the robot just stops.

The LAST conditions has the following meaning:

  • 0 dist condition
  • 1 time condition
  • 2 turn condition
  • 3 count condition
  • 4 (not used)
  • 5 xl - crossing line (of current color)
  • 6 lv - line edge valid condition
  • 7 ir1 distance condition
  • 8 ir2 distance condition
  • 9 tilt angle condition
  • 10 event condition
  • 11 log full condition
  • 12 head absolute heading condition
  • 13 vel velocity condition
  • 14 last condition

The last continue condition is set by all lines with a condition, except goto lines, that never sets the last condition flag.

Examples

Example drive-turn-drive-turn at 20cm/s:

vel=0.2, acc=1.5 : dist = 0.5, time=5
tr=0.15 : turn=90
: dist = 0.5
tr=0.15 : turn=90
vel=0 : time=1

Example wait 5 seconds:

vel=0 : time=5

Example balance and follow line: Go on balance and follow the left edge of the white line for 0.5m, then follow the line for another 0.5m without balance.

vel=0.2,edgel=0,white=1,bal=1: dist>0.5
bal=0,edgel=0,white=1:dist=0.5

NB! Most examples - and especially balance - requires valid controller parameters and calibrated sensors (tilt offset for balance).

Save

Transfer the mission to the robot RAM by pressing "Save" (top right), the mission will be lost by a reboot or power off, unless saved to flash!

Save the mission on the robot flash memory (EE-prom) by pressing "save to flash" (left panel). NB! The flash space is limited (2kB or about 50 lines)!

The mission can also be saved in a text-file using the bottom right save button

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox