|
MyroC
MyroC.3.1b
C-based infrastructure for controlng Scribbler 2 robots
|
Header for a C-based, my-robot package for the Scribbler 2. More...
Go to the source code of this file.
Data Structures | |
| struct | Pixel |
| Struct for a pixel. More... | |
| struct | Picture |
| Struct for a picture object. More... | |
Functions | |
| int | rConnect (const char *address) |
| connects program to Scribbler More... | |
| void | rDisconnect () |
| stop Scribbler motion and close Bluetooth More... | |
| void | rSetConnection (int new_socket_num) |
| set current connection to the socket number More... | |
| void | rFinishProcessing () |
| all timed motions/image displays completed, all robots stopped, and all robot Bluetooth connections closed More... | |
| void | rSetVolume (char highMute) |
| Set sound to high volume (H) or mute (M) highMute set volume of Scribbler. More... | |
| void | rBeep (double duration, int frequency) |
| Beeps with the given duration and frequency. More... | |
| void | rBeep2 (double duration, int freq1, int freq2) |
| Generates two notes for the prescribed duration. More... | |
| void | rSetName (const char *name) |
| Change name stored in the robot to the 16-byte name given. More... | |
| const char * | rGetName () |
| Get the name of the robot. More... | |
| void | rSetForwardness (char *direction) |
| specifies which end of the Scribbler is considered the front More... | |
| void | rSetForwardnessTxt (char *direction) |
| alternative to rSetForwardness for compatibility with earlier MyroC | |
| char * | rGetForwardness () |
| Gets the forwardness of the Scribbler. More... | |
| void | rSetLEDFront (int led) |
| Set the front [fluke] LED on or off. More... | |
| void | rSetLEDBack (double led) |
| Set the the intensity of the back fluke LED. More... | |
| double | rGetBattery () |
| Get the current voltage from the Scribbler batteries; Maximum charge from 6 batteries could be up to 6 volts; Manufacturer suggests batteries should be changed below 4.1 volts. More... | |
| int | rGetStall (int sampleSize) |
| void | rSetBluetoothEcho (char onOff) |
| Turn on and off echoing of Bluetooth transmissions All robot commands involve the transmission of a command over Bluetooth Scribbler commands are always 9 bytes Fluke commands have varying lengths The fluke echos most, but not all, of the commands For many commands, the fluke also echos 11 bytes of sensor data. More... | |
| void | rGetLightsAll (int lightSensors[3], int sampleSize) |
| Get the average values of each of the three light sensors in an array. Values of each light sensor can somewhat (typically under 5%-10%). To even out variability, the sensor can be queried sampleSize times and an average obtained. More... | |
| int | rGetLightTxt (const char *sensorName, int sampleSize) |
| Get the average values of a specified light sensor. Values of each light sensor can somewhat (typically under 5%-10%). To even out variability, the sensor can be queried sampleSize times and an average obtained. More... | |
| void | rGetIRAll (int irSensors[2], int sampleSize) |
| Get an array of true/false values regarding the presence of obstacle based on the average values of each of the three IR sensors. Since readings of each light sensor can vary substantially, each sensor can be queried sampleSize times and an average obtained. More... | |
| int | rGetIRTxt (const char *sensorName, int sampleSize) |
| Use specified IR sensor to determine if obstacle is present. Since values of each light sensor can vary substantially, the sensor can be queried sampleSize times and an average obtained. More... | |
| void | rGetLine (int lineSensors[2], int sampleSize) |
| Use Scribbler 2 line sensors of Scribbler to check for a black line on a white surface under the robot. Since values of each light sensor can vary substantially, the sensor can be queried sampleSize times and an average obtained. More... | |
| void | rSetIRPower (int power) |
| Set the amount of power for the dongle's IR sensors. More... | |
| void | rGetObstacleAll (int obstSensors[3], int sampleSize) |
| Get the average values of the three obstacle sensors in an array. Since readings of each obstacle sensor can vary substantially (successive readings may differ by several hundred or more), each sensor can be queried sampleSize times and an average obtained. More... | |
| int | rGetObstacleTxt (const char *sensorName, int sampleSize) |
| Get the average values of a specified obstacle (IR) sensor. Since values of each obstacle sensor can vary substantially (successive readings may differ by several hundred or more), the sensor can be queried sampleSize times and an average obtained. More... | |
| void | rGetBrightAll (int brightSensors[3], int sampleSize) |
| Read the Fluke's virtual light sensors. Since readings of each brightness sensor can vary substantially (successive readings may differ by 5000-10000), each sensor can be queried sampleSize times and an average obtained. More... | |
| int | rGetBrightTxt (char *sensorName, int sampleSize) |
| Reads one of the Fluke's virtual light sensors. Each sensor reports a total intensity in the left, middle, or right of the Fluke's camera Since values of each obstacle sensor can vary substantially (successive readings may differ by 5000-10000), the sensor can be queried sampleSize times and an average obtained. More... | |
| void | rGetInfo (char *infoBuffer) |
| returns information about the robot's dongle, firmware, and communication mode as a 60 character array in infoBuffer. More... | |
| void | rTurnLeft (double speed, double time) |
| turn Scribbler left for a specified time and speed More... | |
| void | rTurnRight (double speed, double time) |
| turn Scribbler right for a specified time and speed More... | |
| void | rTurnSpeed (char *direction, double speed, double time) |
| turn Scribbler in direction for a specified time and speed More... | |
| void | rForward (double speed, double time) |
| moves Scribbler forward for a specified time and speed More... | |
| void | rFastForward (double time) |
| moves Scribbler forward at the largest possible speed for a specified time More... | |
| void | rBackward (double speed, double time) |
| moves Scribbler backward for a specified time and speed More... | |
| void | rMotors (double leftSpeed, double rightSpeed) |
| move robot with given speeds for the left and right motors continues until given another motion command or disconnected (non-blocking) More... | |
| void | rStop () |
| directs robot to stop movement | |
| void | rHardStop () |
| cuts power to the motor of the robot | |
| Picture | rTakePicture () |
| Use the camera to take a photo. More... | |
| void | rSavePicture (Picture *pic, char *filename) |
| Save a Picture to a .jpeg. More... | |
| Picture | rLoadPicture (char *filename) |
| Load a picture from a .jpeg file. More... | |
| void | rDisplayPicture (Picture *pic, double duration, const char *windowTitle) |
| Display a picture in a new window. More... | |
| void | rWaitTimedImageDisplay () |
| Wait until all timed, non-blocking image window timers are complete. More... | |
Header for a C-based, my-robot package for the Scribbler 2.
Revision History
Version 1.0 based on a C++ package by April O'Neill, David Cowden, Dilan Ustek, Erik Opavsky, and Henry M. Walker
Developers of the C package for Linux: Creators Version 2.0 (C functions for utilities,general,sensors,movement): Spencer Liberto Dilan Ustek Jordan Yuan Henry M. Walker Contributors Version 2.2-2.3: (C functions for image processing) Anita DeWitt Jason Liu Nick Knoebber Vasilisa Bashlovkina Revision for Version 2.4: (image row/column made to match matrix notation) Henry M. Walker
Revisions for Version 3.0 Henry M. Walker
C ported to Macintosh Linux/Mac differences required for connections — otherwise same code OpenGL used to display images, replacing ImageMagick same [new] code used for both Linux and Macintosh 1 process for robot control 1 process needed for each titled window (not each image, as in 2.2-2.4) Blocking options (negative duration parameter) utilize separate thread timer MyroC implementation files organized by user function as follows:
Revisions for Version 3.1 Henry M. Walker
Picture struct and image functions revised to allow 192 by 256 images from origial Fluke camera 266 x 427 low-resolution images from Fluke 2 (high-resolution (800 x 1280) too large for more than 2-4 variables on run-time stack) storage, retrieval, and display of any images up to 266 x 427
This program and all MyroC software is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Details available at http://creativecommons.org/licenses/by-nc-sa/3.0/us/
This program and all MyroC software is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Details may be found at http://creativecommons.org/licenses/by-nc-sa/3.0/us/
| void rBackward | ( | double | speed, |
| double | time | ||
| ) |
moves Scribbler backward for a specified time and speed
| speed | the rate at which the robot should move backward linear range: -1.0 specifies move forward at full speed 0.0 specifies no forward/backward movement 1.0 specifies move backward at full speed |
| time | specifies the duration of the turn if negative: the robot starts backward (non-blocking) other processing proceeds, and the robot continues backward until given another motion command or disconnected (non-blocking) if zero: robot starts moving backward (non-blocking) other processing proceeds if positive: robot moves backward for the given duration, in seconds |
| void rBeep | ( | double | duration, |
| int | frequency | ||
| ) |
Beeps with the given duration and frequency.
| duration | length of note in seconds |
| frequency | frequency of pitch in cycles per second (hertz) |
| void rBeep2 | ( | double | duration, |
| int | freq1, | ||
| int | freq2 | ||
| ) |
Generates two notes for the prescribed duration.
| duration | length of note in seconds |
| freq1 | frequency of first pitch in cycles per second (hertz) |
| freq2 | frequency of second pitch in cycles per second (hertz) |
| int rConnect | ( | const char * | address | ) |
connects program to Scribbler
| address | string, giving name of workstation port or a Scribbler Bluetooth designation |
several string formats are possible
Linux and Mac:
a communications port, such as "/dev/rfcomm0"
a Scribbler 2 fluke serial number, such as "245787"
a full IPRE serial number, such as "IPRE245787"
a Fluke 2 serial number (hexadecimal), such as "021F"
a full Fluke 2 serial number, such as "Fluke2-021F"
Linux only:
a MAC address, such as "00:1E:19:01:0E:13"
Mac only:
any substring of a complete device file name,
as long as the resulting device is unique
some possibilities include
a complete device file name, such as
uniqueness is ensured by requiring 4 hex digits
or 6 decimal digits
| void rDisconnect | ( | ) |
stop Scribbler motion and close Bluetooth
| void rDisplayPicture | ( | Picture * | pic, |
| double | duration, | ||
| const char * | windowTitle | ||
| ) |
Display a picture in a new window.
| pic | pointer to an RGB picture struct from Scribbler 2 camera |
| duration | if duration > 0, operation is blocking if duration <= 0, operation is non-blocking for duration != 0, picture displayed for abs(duration) seconds or until picture closed manually or until the program terminates if duration == 0, picture displayed until closed manually |
| windowTitle | The title of the window that appears. white spaces will be replaced with underscores. |
| void rFastForward | ( | double | time | ) |
moves Scribbler forward at the largest possible speed for a specified time
| time | specifies the duration of the turn if negative: the robot starts forward (non-blocking) other processing proceeds, and the robot continues forward until given another motion command or disconnected (non-blocking) if zero: robot starts moving forward (non-blocking); other processing proceeds if positive: robot moves forward for the given duration, in seconds |
| void rFinishProcessing | ( | ) |
all timed motions/image displays completed, all robots stopped, and all robot Bluetooth connections closed
same result as rDisconnect for all robots plus rComleteImageDisplay
| void rForward | ( | double | speed, |
| double | time | ||
| ) |
moves Scribbler forward for a specified time and speed
| speed | the rate at which the robot should move forward linear range: -1.0 specifies move backward at full speed 0.0 specifies no forward/backward movement 1.0 specifies move forward at full speed |
| time | specifies the duration of the turn if negative: the robot starts forward (non-blocking) other processing proceeds, and the robot continues forward until given another motion command or disconnected (non-blocking) if zero: robot starts moving forward (non-blocking); other processing proceeds if positive: robot moves forward for the given duration, in seconds |
| double rGetBattery | ( | ) |
Get the current voltage from the Scribbler batteries; Maximum charge from 6 batteries could be up to 6 volts; Manufacturer suggests batteries should be changed below 4.1 volts.
| void rGetBrightAll | ( | int | brightSensors[3], |
| int | sampleSize | ||
| ) |
Read the Fluke's virtual light sensors. Since readings of each brightness sensor can vary substantially (successive readings may differ by 5000-10000), each sensor can be queried sampleSize times and an average obtained.
| brightSensors | array to store intensity values |
| sampleSize | how many readings are taken for each sensor |
| int rGetBrightTxt | ( | char * | sensorName, |
| int | sampleSize | ||
| ) |
Reads one of the Fluke's virtual light sensors. Each sensor reports a total intensity in the left, middle, or right of the Fluke's camera Since values of each obstacle sensor can vary substantially (successive readings may differ by 5000-10000), the sensor can be queried sampleSize times and an average obtained.
| sensorName | name of the bright sensor |
| sampleSize | how many readings are taken for the sensor |
| char* rGetForwardness | ( | ) |
Gets the forwardness of the Scribbler.
| void rGetInfo | ( | char * | infoBuffer | ) |
returns information about the robot's dongle, firmware, and communication mode as a 60 character array in infoBuffer.
| infoBuffer | a pre-defined, 60-character array |
| void rGetIRAll | ( | int | irSensors[2], |
| int | sampleSize | ||
| ) |
Get an array of true/false values regarding the presence of obstacle based on the average values of each of the three IR sensors. Since readings of each light sensor can vary substantially, each sensor can be queried sampleSize times and an average obtained.
| irSensors | array to store intensity values |
| sampleSize | how many readings are taken for each sensor |
| int rGetIRTxt | ( | const char * | sensorName, |
| int | sampleSize | ||
| ) |
Use specified IR sensor to determine if obstacle is present. Since values of each light sensor can vary substantially, the sensor can be queried sampleSize times and an average obtained.
| sensorName | name of the light sensor |
| sampleSize | how many readings are taken for the sensor |
| void rGetLightsAll | ( | int | lightSensors[3], |
| int | sampleSize | ||
| ) |
Get the average values of each of the three light sensors in an array. Values of each light sensor can somewhat (typically under 5%-10%). To even out variability, the sensor can be queried sampleSize times and an average obtained.
| lightSensors | array to store intensity values |
| sampleSize | how many readings are taken for each sensor |
| int rGetLightTxt | ( | const char * | sensorName, |
| int | sampleSize | ||
| ) |
Get the average values of a specified light sensor. Values of each light sensor can somewhat (typically under 5%-10%). To even out variability, the sensor can be queried sampleSize times and an average obtained.
| sensorName | name of the light sensor |
| sampleSize | how many readings are taken for the sensor |
| void rGetLine | ( | int | lineSensors[2], |
| int | sampleSize | ||
| ) |
Use Scribbler 2 line sensors of Scribbler to check for a black line on a white surface under the robot. Since values of each light sensor can vary substantially, the sensor can be queried sampleSize times and an average obtained.
| lineSensors | array to store line values detected |
| sampleSize | how many readings are taken for each sensor |
| const char* rGetName | ( | ) |
Get the name of the robot.
| void rGetObstacleAll | ( | int | obstSensors[3], |
| int | sampleSize | ||
| ) |
Get the average values of the three obstacle sensors in an array. Since readings of each obstacle sensor can vary substantially (successive readings may differ by several hundred or more), each sensor can be queried sampleSize times and an average obtained.
| obstSensors | array to store intensity values |
| sampleSize | how many readings are taken for each sensor |
| int rGetObstacleTxt | ( | const char * | sensorName, |
| int | sampleSize | ||
| ) |
Get the average values of a specified obstacle (IR) sensor. Since values of each obstacle sensor can vary substantially (successive readings may differ by several hundred or more), the sensor can be queried sampleSize times and an average obtained.
| sensorName | name of the obstacle sensor |
| sampleSize | how many readings are taken for the sensor |
| int rGetStall | ( | int | sampleSize | ) |
Determine if robot has stalled
MyroC Reference Manual (http://wiki.roboteducation.org/Myro_Reference_Manual) states "Every time you issue a move command, the stall sensor resets, and it needs to wait a short time to see whether the motors are stalled. This means that the sensor won't give accurate results if you test it too soon after the robot starts to move."
In practice, it may take 0.5-1.0 seconds for rGetStall to sense the robot is stalled
| sampleSize | how many readings are taken for each sensor |
| Picture rLoadPicture | ( | char * | filename | ) |
Load a picture from a .jpeg file.
| filename | the name of the file |
| void rMotors | ( | double | leftSpeed, |
| double | rightSpeed | ||
| ) |
move robot with given speeds for the left and right motors continues until given another motion command or disconnected (non-blocking)
| leftSpeed | the rate at which the left wheel should turn linear range: -1.0 specifies move backward at full speed 0.0 specifies no forward/backward movement 1.0 specifies move forwardward at full speed |
| rightSpeed | the rate at which the right wheel should turn linear range: -1.0 specifies move backward at full speed 0.0 specifies no forward/backward movement 1.0 specifies move forward at full speed |
| void rSavePicture | ( | Picture * | pic, |
| char * | filename | ||
| ) |
Save a Picture to a .jpeg.
| pic | pointer to an RGB picture struct from Scribbler 2 camera |
| filename | the name of the file |
| void rSetBluetoothEcho | ( | char | onOff | ) |
Turn on and off echoing of Bluetooth transmissions All robot commands involve the transmission of a command over Bluetooth Scribbler commands are always 9 bytes
Fluke commands have varying lengths
The fluke echos most, but not all, of the commands
For many commands, the fluke also echos 11 bytes of sensor data.
| onOff | char 'y' enables echoing char 'n' disables echoing other character values ignored |
| void rSetConnection | ( | int | new_socket_num | ) |
set current connection to the socket number
| new_socket_num | the number of an open socket for communication |
| void rSetForwardness | ( | char * | direction | ) |
specifies which end of the Scribbler is considered the front
| direction | identifies front direction |
| void rSetIRPower | ( | int | power | ) |
Set the amount of power for the dongle's IR sensors.
| power | the desired power level for the IR sensors |
| void rSetLEDBack | ( | double | led | ) |
Set the the intensity of the back fluke LED.
| led | intensity of the LED values between 0 and 1 provide a range of brightness from off to full intensity values bigger than 1 are treated as 1 (full brightness) values less than 0 are treated as 0 (LED off) |
| void rSetLEDFront | ( | int | led | ) |
Set the front [fluke] LED on or off.
| led | value 1 turns on LED value 0 turns off LED |
| void rSetName | ( | const char * | name | ) |
Change name stored in the robot to the 16-byte name given.
| name | specifies new name of robot if < 16 bytes given, name is filled with null characters if >= 16 bytes given, name is truncated to 15 bytes plus null |
| void rSetVolume | ( | char | highMute | ) |
Set sound to high volume (H) or mute (M) highMute set volume of Scribbler.
| Picture rTakePicture | ( | ) |
Use the camera to take a photo.
This section contains functions for taking and manipulating images All images are constrained with height <= 266 and width <= 427
images from robot cameras have varying sizes, depending on the Fluke images for the original Fluke are 192 (height) by 256 (width) low-resolution images for the Fluke 2 are 266 by 427 high-resolution images for the fluke 2 are 800 by 1280
Bluetooth communication constrains the time required for the Fluke to take a picture Typical times: original fluke: 2- 4 seconds Fluke 2 (low res): 4- 6 seconds Fluke 2 (high res): 25-30 seconds
BASED ON TIMINGS AND MEMORY CONSIDERATIONS, Myro C ALLOWS ONLY LOW RESOLUTION IMAGES
the Picture struct allows direct access to Pixel data Pictures can be saved and loaded as .jpeg files
| void rTurnLeft | ( | double | speed, |
| double | time | ||
| ) |
turn Scribbler left for a specified time and speed
| speed | the rate at which the robot should move left linear range: -1.0 specifies right turn at full speed 0.0 specifies no turn 1.0 specifies left turn at full speed |
| time | specifies the duration of the turn if negative: the robot starts to turn (non-blocking) other processing proceeds, and the robot continues to turn until given another motion command or disconnected (non-blocking) if zero: robot starts turning (non-blocking); other processing proceeds if positive: robot turns for the given duration, in seconds |
| void rTurnRight | ( | double | speed, |
| double | time | ||
| ) |
turn Scribbler right for a specified time and speed
| speed | the rate at which the robot should move right linear range: -1.0 specifies left turn at full speed 0.0 specifies no turn 1.0 specifies right turn at full speed |
| time | specifies the duration of the turn if negative: the robot starts to turn (non-blocking) other processing proceeds, and the robot continues to turn until given another motion command or disconnected (non-blocking) if zero: robot starts turning (non-blocking); other processing proceeds if positive: robot turns for the given duration, in seconds if nonnegative: robot turns for the given duration, in seconds |
| void rTurnSpeed | ( | char * | direction, |
| double | speed, | ||
| double | time | ||
| ) |
turn Scribbler in direction for a specified time and speed
| direction | direction of turn, based on looking from the center of the robot and facing forward |
| speed | the rate at which the robot should move forward linear range: -1.0 specifies turn at full speed 0.0 specifies no turn 1.0 specifies turn at full speed |
| time | specifies the duration of the turn if negative: the robot starts to turn (non-blocking) other processing proceeds, and the robot continues to turn until given another motion command or disconnected (non-blocking) if zero: robot starts turning (non-blocking); other processing proceeds if positive: robot turns for the given duration, in seconds |
| void rWaitTimedImageDisplay | ( | ) |
Wait until all timed, non-blocking image window timers are complete.
1.8.8