Scribbler 2 Sensors and Motion
The Scribbler 2 robot includes equipment for a wide range of operations:
-
a tone generator synthesizes musical tones
-
lights blink
-
several sets of sensors provide information about the robot's environment
-
motors turn wheels, allowing the robot to move
This reading introduces several MyroC capabilities for utilizing Scribbler 2 sensors and motion.
This reading discuses MyroC functions that are available for two important components of the Scribbler 2 robots.
Scribbler 2 Sensors
The Scribbler 2 and Fluke each contain several sensors:
-
Sensors on the Scribbler 2
-
Left, middle, and right light sensors, indicating the light intensity encountered near parts of the robot. (Values range from near 0 for bright light to near 65535 for very dark environments.)
-
IR sensors, with emitters on the left and right and a receiver in the middle, help determine the presence of obstacles nearby. The IR light from the emitters bounces off obstacles and can be detected the IR detector. (A sensor reading of 0 indicates no obstacle, whereas a reading of 1 indicates an obstacle has been detected.)
-
-
Sensors on the Fluke
-
IR emitters and a corresponding receiver on the Fluke report the amount of light that bounces off a nearby object. (Values near 0 indicate no obstacle (no reflected light) and values near 6000 indicate an obstacle (much detected light).)
-
Left and right virtual light sensors utilize parts of camera images to infer the amount of light in a region. (Values near 0 represent bright light, whereas values near 65535 represent a very dark region.)
-
Resources
The MyroC page on Scribbler 2 sensor documentation provides diagrams of various sensors, together with names of the corresponding MyroC functions.
MyroC documentation provides a detailed description of each function within MyroC, including parameters required and sensor values returned.
Accuracy: A Technical Issue
Since each sensor is an electro-mechanical device, values reported by a sensor can vary — sometimes substantially. Further, values may be influenced by such factors as the strength of the batteries or the amount of ambient light within a room.
To mitigate variability, use of the sensors typically involves a parameter, called sampleSize.
-
If sampleSize is 1, only one reading is obtained, and that value returned.
-
If sampleSize > 1, the robot takes this prescribed number of readings and returns the average.
In practice, setting sampleSize to 5 or 10 provides reasonably consistent reading. Some variability likely remains, but differences often are modest. Of course, taking multiple readings can take some time, slowing overall responsiveness of a program.
Using Sensor Data
Although obtaining sensor data may be of some interest by itself, the most common usage of this information involves controlling a robot's behavior.
To illustrate, the following program sensor-use.c beeps twice if the program detects no obstacle on the left of the Scribbler 2, but turns on a light for 3 seconds if an obstacle is present.
/* A program that responds to the presence of an obstacle. If an obstacle is not detected, the robot beeps twice. If an obstacle is detected, the robot turns on a light for 3 seconds. */ #include <stdio.h> #include <MyroC.h> int main () { printf ("Program to respond to a detected obstacle\n"); rConnect ("/dev/rfcomm0");
Program Notes
-
After a typical program header, the program includes the needed C and MyroC libraries.
-
Any use of a Scribbler 2 robot requires a Bluetooth connection, established with the rConnect function.
/* Obtain sensor data for obstacles on the left of the Scribbler 2 robot */ int sensorReading = rGetIRTxt ("left", 5);
-
The rGetIRTxt returns the reading of the left sensor of the Scribbler 2, averaged over 5 trials.
/* Check if obstacle present */ if (sensorReading)
-
In C, any non-zero value is considered to be true, and zero is considered false.
-
The rGetIRTxt function returns 1 if an obstacle is found and 0 otherwise. Therefore,
- If an obstacle is detected, rGetIRTxt returns 1, which is considered true.
- If no obstacle is detected, rGetIRTxt returns 0, which is considered false.
{ printf ("obstacle detected\n"); /* turn on light */ rSetLEDFront (1); /* wait 3 seconds by beeping with zero frequency */ rBeep (3.0, 0); /* turn off light */ rSetLEDFront (0); }
-
If the obstacle is found,
- Turn on the LED at the front of the Fluke
-
Wait 3 seconds by beeping with a frequency of 0 for the allocated
time.
(C also has a sleep command in the unistd.h library. However, the sleep command only allows durations to be non-negative integer values, whereas rBeep allows durations to be any positive real number. Thus, the rBeep option seems more versatile.)
- Turn off the LED at the front of the Fluke
else { printf ("no obstacle found\n"); rBeep (1.5, 880); rBeep (1.5, 1760); } printf ("Processing completed\n"); return 0; }
-
If the obstacle is not found, beep twice by beeping once with a frequency of 880 and a second time an octave higher.
Robot Motion
Turning to the possibilities for robot motion, the Scribbler 2 robot has three wheels. The small wheel below the fluke dongle is purely for balance. The two large wheels each have their own motor, which can be adjusted to move at separate speeds to turn the robot to the left or right. The speed of the motors ranges from -1 (backwards at full speed) to 1 (forwards at full speed). It is important to note that there is no built-in time limit for how long the motor can run, so if you call a command to move without specifying a time limit or commanding the robot to stop, the motors will keep running until the Scribbler 2 battery dies.
Acknowledgment
This section on robot motion was first drafted by April O'Neill. Henry M. Walker performed subsequent editing and text reorganization.
A second important feature of the Scribbler 2 robot is that it can have the "front" set as either direction. When the robot has its forwardness set as "scribbler-forward", the front of the robot is the direction without a wheel. When the forwardness is "fluke-forward", the front is the direction with the small wheel (below the green card-like fluke dongle). The command to change the forwardness of the robot is:
rSetForwardness (char * direction);
The options are "scribbler-forward" or "fluke-forward". By default, forwardness is set to "scribbler-forward" by rConnect.
That is, when the Scribbler 2 is turned on, the robot will consider "forward" so that the small wheel is at the back (under the fluke). Then the command
rSetForwardness ("fluke-forward");
will change forwardness, so that forward now means the end with the fluke. To change forwardness back, away from the fluke, use the command
rSetForwardness ("scribbler-forward");
Notes
As the robot moves, a program likely will use one collection of sensors to determine whether/when obstacles appear in the path of motion. As shown on the Scribbler 2 sensor documentation, some of these sensors are located on the Fluke, and some are on the Scribbler itself.
-
When using the sensors on the Fluke, a program typically will be looking for obstacles on that side of the robot and then moving in that direction. In this context, it is natural to refer to "forward" as specifying the part of the Fluke containing that device and those sensors. (E.g., rForward(1.0, 1.0) would naturally move the robot in the direction the Fluke is facing.)
-
When using sensors on the robot itself, a program will be checking sensors on that side of the robot (away from the Fluke), and movement will be in that direction. In this context, it is natural to refer to "forward" as moving in the direction of those Scribbler sensors. (e.g., rForward(1.0, 1.0) would naturally move the robot in the direction toward the Scribbler sensors and away from the Fluke.)
The rSetForwardness command allows a program to specify which direction to consider "forward".
-
The command rSetForwardness ("Fluke-forward") specifies that further motion commands (e.g., rForward(1.0, 1.0)) will consider the Fluke's sensors as pointing forward.
-
The command rSetForwardness ("Scribbler-forward") specifies that further motion commands (e.g., rForward(1.0, 1.0)) will consider the robot's sensors as pointing forward.
In the prototype for rSetForwardness, the parameter specification (char * direction) may seems peculiar. We'll talk about the details of this specification in a later module. For now, consider this specification as indicating a character string — often given as a sequence of characters, such as "scribbler-forward".
rConnect always sets the robot to "scribbler-forward". Thus, the rSetForwardness command is used most often to change the sense of direction to "fluke-forward". Thereafter, this command can change the forward direction of the robot, as desired.
Robot Commands
Scribbler robots respond to several motion commands that include moving forward, backward, or turning. These commands can be classified as blocking or non-blocking. Most motion commands can fall into either category, depending on the given parameters.
Blocking and non-blocking commands
A blocking command means that while the robot is executing this command, the program will not proceed until the command is completed. That is, while the Scribbler 2 is performing these commands, it cannot perform other actions (such as beeping). A non-blocking command is one that allows the robot to multi-task. For example, you could issue a non-blocking forward command and have the robot beep several times as it moves forward.
Motion Commands with Time and/or Speed Parameters
Many motion commands take two parameters:
-
A speed parameter specifies a real number between -1.0 and 1.0:
- The value -1.0 specifies full speed backward
- The value -0.5 specifies half speed backward
- The value 0.0 specifies no motion either forward or backward
- The value 0.5 specifies half speed forward
- The value 1.0 specifies full speed forward
-
A duration parameter specifies the amount of time for the action.
- The magnitude of the duration specifies the time for the action, in seconds. That is, durations of both -1.5 and 1.5 indicate that the action will continue for 1.5 seconds.
- If the duration is non-negative, the action is blocking. Once the action is started, the Scribbler 2 will not continue with another activity until the action is completed.
- If the duration is negative, the action is non-blocking. Once the action is started, the Scribbler 2 will continue with other actions while the action continues for the specified duration.
The following table identifies the available motion commands, together with examples and notes:
Procedure header | Blocking example | Non-blocking example | Notes |
---|---|---|---|
rTurnLeft (double speed, double time);
| rTurnLeft (0.5, 3.5);
| rTurnLeft (0.5, -3.5);
| Turn left at half speed for 3.5 seconds |
rTurnRight (double speed, double time);
| rTurnRight (0.25, 2.0/3.0);
| rTurnRight (0.25, -2.0/3.0);
| Turn right at quarter speed for 0.66666 seconds |
rTurnSpeed (double direction, double speed, double time);
| rTurnSpeed ("left", 0.5, 2.0);
| rTurnSpeed ("left", 0.5, -2.0);
| direction may be "left" or "right"; the examples turn left at half speed for two seconds |
rForward (double speed, double time);
| rForward (1.0, 3.7);
| rForward (1.0, -3.7);
| Move forward at roughly speed for 3.7 seconds; the -1.0 to 1.0 range is only approximate for this commend |
rBackward (double speed, double time);
| rBackward (0.5, 1.5);
| rBackward (0.5, -1.5);
| Move backward at full speed for half a second |
rFastForward (double time);
| rFastForward (2.7);
| rFastForward (-2.7);
| Move forward as fast as possible for 2.7 seconds. |
Summary: Most motion commands (i.e., commands with a time parameter) perform as blocking or non-blocking depending on their parameters. If the time given is greater than 0, the robot will move for that amount of time while blocking other commands. If the time parameter is negative, then it will be a non-blocking command that will continue until it is stopped, allowing subsequent commands to be processed in the meantime. A time of 0 will result in no motion. Also, remember that speed ranges from 0 (no movement) to 1 (full speed), and the unit of time is seconds.
A Command without a Time parameter
Continuous commands are commands that do not include time as a variable. Such commands are always non-blocking; that is, while the Scribbler 2 is performing these commands, it can perform other actions (such as beeping). The current MyroC.h specification includes only one continuous command:
rMotors (double leftSpeed, double rightSpeed);
For example, the command
rMotors (0.3, 0.7);
moves with the left wheel at 30% of full speed, and the right wheel at 70% of full speed, so the robot moves in a circular motion.
Stop Commands
These commands stop the continuous commands after they have been issued.
rStop();
rHardStop();
Although both rStop and rHardStop produce similar outcomes from a user's perspective, the internal details are slightly different.
-
rStop issues a command for the motors to turn at speed 0. Power may continue to flow to circuits controlling the motors, but no power flows to the motors themselves, and the robot's motors do not turn.
-
rHardStop kills all power to motor-related circuits. Not only does the motor start, but power to related circuits also is cut off.
Scribbler 2 documentation does not indicate what circuits might be involved with motors moving at speed 0, so the actual difference between these commands may be more abstract than real.
Created 20 July 2011 by April O'Neill Revised 27 July 2011 by April O'Neill Edited for new MyroC 21 January 2014 by Henry M. Walker Reorganized 4 November 2014 by Henry M. Walker Sensor material added, reformatted, and edited 11 July 2016 by Henry M. Walker |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu . |