CSC 161 Grinnell College Fall 2016
Scribbler 2
CSC 161:
Imperative Problem Solving and Data Structures
Scribbler 2
Course Home Syllabus Schedule MyroC Documentation Acknowledgments

Scribbler 2 Sensors and Motion

The Scribbler 2 robot includes equipment for a wide range of operations:

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:

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.

 

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


   /* Obtain sensor data for obstacles on the left of the Scribbler 2 robot */
   int sensorReading = rGetIRTxt ("left", 5);

   /* Check if obstacle present */
   if (sensorReading)

     {
       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);
     }

   else
     {
       printf ("no obstacle found\n");
       rBeep (1.5, 880);
       rBeep (1.5, 1760);
     }

  printf ("Processing completed\n");
  return 0;
}

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.

The rSetForwardness command allows a program to specify which direction to consider "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:

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, 1.0/3.0); rTurnRight (0.25, -1.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.

Although both rStop and rHardStop produce similar outcomes from a user's perspective, the internal details are slightly different.

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
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu .