MyroC Project
Package to control Scribbler 2 robots via Bluetooth
MyroC.h
Go to the documentation of this file.
1 
77 /*
78  ********************** implementation overview *************************
79  * MyroC implementation files organized by user function as follows:
80 
81  1. GENERAL 2. SENSORS
82  rConnect a.Scribbler Sensors
83  rDisconnect rGetLightsAll
84  rSetConnection rGetLightTxt
85  rFinishProcessing rGetIRAll
86  rSetVolume rGetIRTxt
87  rBeep rGetLine
88  rBeep2
89  rSetName b.Fluke Sensors
90  rGetName rGetObstacleAll
91  rSetForwardness rGetObstacleTxt
92  rGetForwardness rGetBrightAll
93  rSetLEDFront rGetBrightTxt
94  rSetLEDBack rSetIRPower
95  rGetBattery
96  rGetStall
97 
98 3. MOVEMENT 4. PICTURES
99  rTurnLeft rGetCameraSize
100  rTurnRight rTakePicture
101  rTurnSpeed rDisplayPicture
102  rForward rDisplayImageProcessingErrors
103  rFastForward rWaitTimedImageDisplay
104  rBackward rSavePicture
105  rMotors rLoadPicture
106  rStop
107  rHardStop
108 */
109 
110 #ifndef _MyroC
111 #define _MyroC
112 
115 typedef struct
116 {
117  unsigned char R;
118  unsigned char G;
119  unsigned char B;
120 } Pixel;
121 
147 typedef struct
148 {
149  int height;
150  int width;
151  Pixel pix_array[266][427];
152 } Picture;
153 
154 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
155  #include <winsock2.h>
156  #include <ws2bth.h>
157  #define ROBOT_CONNECTION_TYPE SOCKET
158 #else
159  #define ROBOT_CONNECTION_TYPE int
160 #endif
161 /* ***************************************************************/
162 /* 1. GENERAL - GENERAL - GENERAL - GENERAL - GENERAL - GENERAL */
163 /* ***************************************************************/
164 
206  ROBOT_CONNECTION_TYPE rConnect (const char * address);
207 
221 void rDisconnect();
222 
231  void rSetConnection (ROBOT_CONNECTION_TYPE new_socket_num);
232 
247 void rFinishProcessing ();
248 
255 void rSetVolume (char highMute);
256 
266 void rBeep(double duration, int frequency);
267 
278 void rBeep2(double duration, int freq1, int freq2);
279 
286 void rSetName (const char * name);
287 
293 char * rGetName();
294 
301 void rSetForwardness(char * direction);
302 
306 void rSetForwardnessTxt (char * direction);
307 
312 char * rGetForwardness ();
313 
320 void rSetLEDFront(int led);
321 
330 void rSetLEDBack(double led);
331 
338 double rGetBattery();
339 
359 int rGetStall (int sampleSize);
360 
372 void rSetBluetoothEcho (char onOff);
373 
374 
375 /* ************************************************************************/
376 /* 2. SENSORS - SENSORS - SENSORS - SENSORS - SENSORS - SENSORS - SENSORS */
377 /* ************************************************************************/
378 
379 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
380 /* Group a: Scribbler Sensors */
381 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
382 
399 void rGetLightsAll (int lightSensors[3], int sampleSize);
400 
417 int rGetLightTxt (const char * sensorName, int sampleSize);
418 
435 void rGetIRAll (int irSensors[2], int sampleSize);
436 
437 
453 int rGetIRTxt (const char * sensorName, int sampleSize);
454 
471 void rGetLine (int lineSensors[2], int sampleSize);
472 
473 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
474 /* Group b: Fluke Sensors */
475 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
476 
485 void rSetIRPower (int power);
486 
505 void rGetObstacleAll (int obstSensors[3], int sampleSize);
506 
528 int rGetObstacleTxt (const char * sensorName, int sampleSize);
529 
545 void rGetBrightAll (int brightSensors[3], int sampleSize);
546 
566 int rGetBrightTxt (char * sensorName, int sampleSize);
567 
574 void rGetInfo (char * infoBuffer);
575 
576 
577 /* *********************************************************************/
578 /* 3. MOVEMENT - MOVEMENT - MOVEMENT - MOVEMENT - MOVEMENT - MOVEMENT */
579 /* *********************************************************************/
580 
581 /* Procedures in this section, except rMotors, include a "time" parameter.
582  *
583  * Throughout, "time" is interpreted as follows:
584  * if time > 0, the call to the procedure is "blocking:
585  * That is, a call to the procedure starts a motion, and
586  * all other processing stops for the specified time (in seconds).
587  * After the specified time interval, the motion stops,
588  * and processing in the main program continues. \n
589  * If time == 0, the procedure is "non-blocking":
590  * That is, the procedure starts a motion,
591  * and that motion continues until another motion command is issued.
592  * Once the motion starts, other processing in the main
593  * program continues. \n
594  * If time < 0, the procedure is "non-blocking":
595  * That is, a call to the procedure starts a motion,
596  * and a timer is started for the abs("time"). \n
597  * Once the time interval is completed, \n
598  * if no other motion command has been issued,
599  * a command to stop robot motion is given \n
600  * if another motion command has been issued (before the
601  * specified time), the new command is executed immediately,
602  * and the timer is ignored. \n
603  * For example, suppose rForward is called with a time of -5 seconds:
604  * subsequent processing in the main program continues \n
605  * if numerous beeps are issued or the camera is used or
606  * a series of non-motion commands are issued, then
607  * the rForward action stops in 5 seconds. \n
608  * if an rRightTurn command is issued after 2 seconds,
609  * then the rForward command is overridden by rRightTurn
610  * and the timer for rForward (after another 3 seconds)
611  * is ignored.
612  *
613  * Program termination with timed, non-blocking commands:
614  * When a non-blocking time is specified (i.e., time < 0), processing within
615  * the controlling program continues. However, the robot's Bluetooth connection
616  * (established with rConnect) is not severed until the non-blocking timer has
617  * expired and the motion stopped. In particular, rDisconnect blocks until
618  * the specified non-blocking time is completed and the program tells the
619  * robot to stop.
620  */
621 
637 void rTurnLeft (double speed, double time);
638 
655 void rTurnRight (double speed, double time);
656 
675 void rTurnSpeed (char * direction, double speed, double time);
676 
692 void rForward (double speed, double time);
693 
706 void rFastForward (double time);
707 
723 void rBackward (double speed, double time);
724 
737 void rMotors (double leftSpeed, double rightSpeed);
738 
742 void rStop();
743 
747 void rHardStop();
748 
749 /* *********************************************************************/
750 /* 4. PICTURES PICTURES PICTURES PICTURES PICTURES PICTURES PICTURES */
751 /* *********************************************************************/
798 
807 void rSavePicture(Picture * pic, char * filename);
808 
817 Picture rLoadPicture(char * filename);
818 
819 
841 void rDisplayPicture(Picture * pic, double duration, const char * windowTitle);
842 
850 
861 void rWaitTimedImageDisplay ();
862 
863 #endif
unsigned char G
The value of the green component.
Definition: MyroC.h:118
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 ca...
Definition: MyroC-sensor.c:133
int height
The actual height of the image, but no more than 266.
Definition: MyroC.h:149
void rSavePicture(Picture *pic, char *filename)
Save a Picture to a .jpeg.
Definition: MyroC-image-file-linux-mac.c:240
int rGetStall(int sampleSize)
Definition: MyroC-general.c:524
void rTurnLeft(double speed, double time)
turn Scribbler left for a specified time and speed
Definition: MyroC-movement.c:415
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 robo...
Definition: MyroC-sensor.c:356
void rSetBluetoothEcho(char onOff)
Turn on and off the printing transmission and echong of Bluetooth transmissions All robot commands in...
Definition: MyroC-utilities-linux-mac.c:359
void rSetName(const char *name)
Change name stored in the robot to the 16-byte name given.
Definition: MyroC-general.c:281
Struct for a picture object.
Definition: MyroC.h:147
void rSetForwardnessTxt(char *direction)
alternative to rSetForwardness for compatibility with earlier MyroC
Definition: MyroC-general.c:395
ROBOT_CONNECTION_TYPE rConnect(const char *address)
connects program to Scribbler
Definition: MyroC-connect-linux.c:148
void rDisplayImageProcessingErrors()
Turn on and off the printing of error messasge for image processing.
Definition: MyroC-display-linux-mac.c:1303
void rMotors(double leftSpeed, double rightSpeed)
move robot with given speeds for the left and right motors continues until given another motion comma...
Definition: MyroC-movement.c:561
Picture rTakePicture()
Use the camera to take a photo.
Definition: MyroC-camera-windows.c:165
void rWaitTimedImageDisplay()
Wait until all timed, non-blocking image window timers are complete.
Definition: MyroC-display-linux-mac.c:1317
void rGetInfo(char *infoBuffer)
returns information about the robot&#39;s dongle, firmware, and communication mode as a 60 character arra...
Definition: MyroC-sensor.c:578
void rSetVolume(char highMute)
Set sound to high volume (H) or mute (M) highMute set volume of Scribbler.
Definition: MyroC-general.c:194
void rBeep(double duration, int frequency)
Beeps with the given duration and frequency.
Definition: MyroC-general.c:229
Struct for a pixel.
Definition: MyroC.h:115
int rGetBrightTxt(char *sensorName, int sampleSize)
Reads one of the Fluke&#39;s virtual light sensors. Each sensor reports a total intensity in the left...
Definition: MyroC-sensor.c:536
char * rGetName()
Get the name of the robot.
Definition: MyroC-general.c:315
void rDisconnect()
stop Scribbler motion and close Bluetooth
Definition: MyroC-connect-linux.c:411
int rGetLightTxt(const char *sensorName, int sampleSize)
Get the average values of a specified light sensor. Values of each light sensor can somewhat (typical...
Definition: MyroC-sensor.c:183
void rHardStop()
cuts power to the motor of the robot
Definition: MyroC-movement.c:627
double rGetBattery()
Get the current voltage from the Scribbler batteries; Maximum charge from 6 batteries could be up to ...
Definition: MyroC-general.c:487
void rDisplayPicture(Picture *pic, double duration, const char *windowTitle)
Display a picture in a new window.
Definition: MyroC-display-linux-mac.c:1190
void rSetConnection(ROBOT_CONNECTION_TYPE new_socket_num)
set current connection to the socket number
Definition: MyroC-general.c:148
void rGetBrightAll(int brightSensors[3], int sampleSize)
Read the Fluke&#39;s virtual light sensors. Since readings of each brightness sensor can vary substantial...
Definition: MyroC-sensor.c:510
int rGetObstacleTxt(const char *sensorName, int sampleSize)
Get the average values of a specified obstacle (IR) sensor. Since values of each obstacle sensor can ...
Definition: MyroC-sensor.c:456
void rForward(double speed, double time)
moves Scribbler forward for a specified time and speed
Definition: MyroC-movement.c:485
void rStop()
directs robot to stop movement
Definition: MyroC-movement.c:619
void rSetForwardness(char *direction)
specifies which end of the Scribbler is considered the front
Definition: MyroC-general.c:360
void rSetLEDFront(int led)
Set the front [fluke] LED on or off.
Definition: MyroC-general.c:436
void rFinishProcessing()
all timed motions/image displays completed, all robots stopped, and all robot Bluetooth connections c...
Definition: MyroC-general.c:172
void rBeep2(double duration, int freq1, int freq2)
Generates two notes for the prescribed duration.
Definition: MyroC-general.c:258
void rGetObstacleAll(int obstSensors[3], int sampleSize)
Get the average values of the three obstacle sensors in an array. Since readings of each obstacle sen...
Definition: MyroC-sensor.c:428
unsigned char R
The value of the red component.
Definition: MyroC.h:117
void rTurnSpeed(char *direction, double speed, double time)
turn Scribbler in direction for a specified time and speed
Definition: MyroC-movement.c:452
void rBackward(double speed, double time)
moves Scribbler backward for a specified time and speed
Definition: MyroC-movement.c:541
char * rGetForwardness()
Gets the forwardness of the Scribbler.
Definition: MyroC-general.c:404
unsigned char B
The value of the blue component.
Definition: MyroC.h:119
void rSetLEDBack(double led)
Set the the intensity of the back fluke LED.
Definition: MyroC-general.c:458
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 e...
Definition: MyroC-sensor.c:244
int width
The actual width of the image, but no more than 427.
Definition: MyroC.h:150
Picture rLoadPicture(char *filename)
Load a picture from a .jpeg file.
Definition: MyroC-image-file-linux-mac.c:320
int rGetIRTxt(const char *sensorName, int sampleSize)
Use specified IR sensor to determine if obstacle is present. Since values of each light sensor can va...
Definition: MyroC-sensor.c:293
void rFastForward(double time)
moves Scribbler forward at the largest possible speed for a specified time
Definition: MyroC-movement.c:500
void rSetIRPower(int power)
Set the amount of power for the dongle&#39;s IR sensors.
Definition: MyroC-sensor.c:397
void rTurnRight(double speed, double time)
turn Scribbler right for a specified time and speed
Definition: MyroC-movement.c:432