PC side Elisa-3 library
Defines | Functions | Variables
elisa3-lib.c File Reference
#include "elisa3-lib.h"

Defines

#define FRONT_IR_ON(x)   ((x) |= (1 << 1))
#define BACK_IR_ON(x)   ((x) |= (1 << 0))
#define ALL_IR_ON(x)   ((x) |= (1<<0) | (1 << 1))
#define TV_REMOTE_ON(x)   ((x) |= (1<<2))
#define SLEEP_ON(x)   ((x) = 0x08)
#define CALIBRATION_ON(x)   ((x) |= (1<<4))
#define OBSTACLE_AVOID_ON(x)   ((x) |= (1<<6))
#define CLIFF_AVOID_ON(x)   ((x) |= (1<<7))
#define FRONT_IR_OFF(x)   ((x) &= ~(1 << 1))
#define BACK_IR_OFF(x)   ((x) &= ~(1 << 0))
#define ALL_IR_OFF(x)   ((x) &= ~(1 << 0) & ~(1 << 1))
#define TV_REMOTE_OFF(x)   ((x) &= ~(1 << 2))
#define SLEEP_OFF(x)   ((x) &= ~(1 << 3))
#define CALIBRATION_OFF(x)   ((x) &= ~(1 << 4))
#define OBSTACLE_AVOID_OFF(x)   ((x) &= ~(1 << 6))
#define CLIFF_AVOID_OFF(x)   ((x) &= ~(1 << 7))
#define RAD_2_DEG   57.2957796
#define NUM_ROBOTS   4
#define PAYLOAD_SIZE   13
#define ADDR_SIZE   2
#define ROBOT_PACKET_SIZE   (PAYLOAD_SIZE+ADDR_SIZE)
#define PACKETS_SIZE   64
#define OVERHEAD_SIZE   (2*NUM_ROBOTS+1)
#define UNUSED_BYTES   3

Functions

char speed (char value)
int computeVerticalAngle (signed int x, signed int y)
int getIdFromAddress (int address)
void startCommunication (int *robotAddr, int numRobots)
 To be called once at the beginning, it init the USB communication with the RF module that is responsible to send data to the robots and initialize the list of robots to be controlled; max number of simultaneous robots is 100.
void stopCommunication ()
 To be called once at the end, it closes the USB communication.
void setMutexTx ()
void freeMutexTx ()
void setMutexRx ()
void freeMutexRx ()
void setMutexThread ()
void freeMutexThread ()
unsigned char checkConcurrency (int id)
void setLeftSpeed (int robotAddr, char value)
 Set the left speed of the robot.
void setRightSpeed (int robotAddr, char value)
 Set the right speed of the robot.
void setLeftSpeedForAll (char *value)
 Set the left speed of all the robots specified in the list.
void setRightSpeedForAll (char *value)
 Set the right speed of all the robots specified in the list.
void setRed (int robotAddr, unsigned char value)
 Set the red intensity of the RGB led on the robot.
void setGreen (int robotAddr, unsigned char value)
 Set the green intensity of the RGB led on the robot.
void setBlue (int robotAddr, unsigned char value)
 Set the blue intensity of the RGB led on the robot.
void setRedForAll (unsigned char *value)
 Set the red intensity of the RGB led of all the robots specified in the list.
void setGreenForAll (unsigned char *value)
 Set the green intensity of the RGB led of all the robots specified in the list.
void setBlueForAll (unsigned char *value)
 Set the blue intensity of the RGB led of all all the robots specified in the list.
void turnOnFrontIRs (int robotAddr)
 Turn on both the front IRs transmitter on the robot.
void turnOffFrontIRs (int robotAddr)
 Turn off both the front IRs transmitter on the robot.
void turnOnBackIR (int robotAddr)
 Turn on the back IR transmitter on the robot.
void turnOffBackIR (int robotAddr)
 Turn off the back IR transmitter on the robot.
void turnOnAllIRs (int robotAddr)
 Turn on all the 3 IRs transmitter on the robot.
void turnOffAllIRs (int robotAddr)
 Turn off all the 3 IRs transmitter on the robot.
void enableTVRemote (int robotAddr)
 Enable the reception of commands from a TV remote.
void disableTVRemote (int robotAddr)
 Disable the reception of commands from a TV remote.
void enableSleep (int robotAddr)
 Put the robot in sleep mode (energy saving mode).
void disableSleep (int robotAddr)
 Put the robot in normal mode (out of sleep).
void enableObstacleAvoidance (int robotAddr)
 Enable the onboard obstacle avoidance.
void disableObstacleAvoidance (int robotAddr)
 Disable the onboard obstacle avoidance.
void enableCliffAvoidance (int robotAddr)
 Enable the onboard cliff avoidance.
void disableCliffAvoidance (int robotAddr)
 Disable the onboard cliff avoidance.
void resetRobotData (int robotIndex)
void setRobotAddress (int robotIndex, int robotAddr)
 Set the address of a robot related to a particular index, the index must be in the range of the robot list size.
void setRobotAddresses (int *robotAddr, int numRobots)
 Set the addresses of the robots that need to be controlled; max number of simultaneous robots is 100.
unsigned int getProximity (int robotAddr, int proxId)
 Request one of the proximity sensors value of the robot.
unsigned int getProximityAmbient (int robotAddr, int proxId)
 Request one of the ambient value (from proximity sensors) of the robot.
unsigned int getGround (int robotAddr, int groundId)
 Request one of the ground sensors value of the robot.
unsigned int getGroundAmbient (int robotAddr, int groundId)
 Request one of the ambient value (from ground sensors) of the robot.
void getAllProximity (int robotAddr, unsigned int *proxArr)
 Request all the proximity sensors values at once.
void getAllProximityAmbient (int robotAddr, unsigned int *proxArr)
 Request all the ambient values (from proximity sensors) at once.
void getAllGround (int robotAddr, unsigned int *groundArr)
 Request all the ground sensors values at once.
void getAllGroundAmbient (int robotAddr, unsigned int *groundArr)
 Request all the ambient values (from ground sensors) at once.
void getAllProximityFromAll (unsigned int proxArr[][8])
 Request all the proximity sensors values of all the robots specified in the list.
void getAllProximityAmbientFromAll (unsigned int proxArr[][8])
 Request all the ambient values (from proximity sensors) of all the robots specified in the list.
void getAllGroundFromAll (unsigned int groundArr[][4])
 Request all the ground sensors values of all the robots specified in the list.
void getAllGroundAmbientFromAll (unsigned int groundArr[][4])
 Request all the ambient values (from ground sensors) of all the robots specified in the list.
unsigned int getBatteryAdc (int robotAddr)
 Request the raw battery value, it contains the sampled value of the battery.
unsigned int getBatteryPercent (int robotAddr)
 Request the charge percentage of the battery.
signed int getAccX (int robotAddr)
 Request the raw value of the accelerometer x axis.
signed int getAccY (int robotAddr)
 Request the raw value of the accelerometer y axis.
signed int getAccZ (int robotAddr)
 Request the raw value of the accelerometer z axis.
unsigned char getSelector (int robotAddr)
 Request the selector position.
unsigned char getTVRemoteCommand (int robotAddr)
 Request last command received from the TV remote.
signed int getOdomTheta (int robotAddr)
 Request the current orientation of the robot computed from the measured speed of the motors.
signed int getOdomXpos (int robotAddr)
 Request the current position (x component) of the robot computed from the measured speed of the motors.
signed int getOdomYpos (int robotAddr)
 Request the current position (y component) of the robot computed from the measured speed of the motors.
void setSmallLed (int robotAddr, int ledId, int state)
 Set a new stato (on or off) for the small green leds around the robot.
void turnOffSmallLeds (int robotAddr)
 Turn off all the small green leds around the robot.
void turnOnSmallLeds (int robotAddr)
 Turn on all the small green leds around the robot.
int getVerticalAngle (int robotAddr)
 Request the current orientation of the robot given by the accelerometer. This function is usable only if the robot is moving vertically.
void calibrateSensors (int robotAddr)
 Calibrate the sensors of the robot (proximity, accelerometer).
void calibrateSensorsForAll ()
 Calibrate the sensors (proximity, accelerometer) of all the robots specified in the list.
void startOdometryCalibration (int robotAddr)
 Start the odometry calibration.
unsigned char robotIsCharging (int robotAddr)
 Tell whether the robot is charging or not.
unsigned char robotIsCharged (int robotAddr)
 Tell whether the robot is completely charged or not.
unsigned char buttonIsPressed (int robotAddr)
 Tell whether the button on the back side of the robot is pressed or not.
void resetFlagTX (int robotAddr)
 Reset all the flags sent to the robot.
unsigned char getFlagTX (int robotAddr, int flagInd)
 Request the current flags value (raw) sent to the robot.
unsigned char getFlagRX (int robotAddr)
 Request the current flags value (raw) received from the robot.
signed long int getLeftMotSteps (int robotAddr)
 Request the current raw value of the left motor steps (sum of the measured speed).
signed long int getRightMotSteps (int robotAddr)
 Request the current raw value of the right motor steps (sum of the measured speed).
void resetMessageIsSentFlag (int robotAddr)
 Reset the flag indicating that the last modified packet is sent to the robot; it should be called before using "messageIsSent".
unsigned char messageIsSent (int robotAddr)
 Request if the last modified packet is sent to the robot; this function is thought to be used in polling mode (continue to check whether the message is sent untill it is actually sent). Before the polling the function "resetMessageIsSentFlag" need to be called. It can be used for both check whether the robots received the new messages and to know when new data from the robots are available.
double getRFQuality (int robotAddr)
 Request the current percentage of failed trasnfers in the last 5 seconds.
void stopTransferData ()
 This function stop the transmission of the packets to the robots.
void resumeTransferData ()
 This function resume the transmission of the packets to the robots.
void setCompletePacket (int robotAddr, char red, char green, char blue, char flags[2], char left, char right, char leds)
 Set all the values of a robot at one time.
void setCompletePacketForAll (int *robotAddr, char *red, char *green, char *blue, char flags[][2], char *left, char *right, char *leds)
 Set all the values of all the robots specified in the list.
unsigned char sendMessageToRobot (int robotAddr, char red, char green, char blue, char flags[2], char left, char right, char leds, unsigned long us)
 Send a message to a particular robot resetting the list of robots to a single one (all previous address set with "startCommunication" will be lost).
unsigned char waitForUpdate (int robotAddr, unsigned long us)
 Wait for updated data coming from the robot; if the robot isn't reachable (out of range, discharged, ...) then the function will exit after the amount of time specified as parameter even if no data are received. this function can be used also to check whether a message is successfully sent to a robot or not.
void transferData ()
 This function need to be called periodically (as fast as possible) in order to exchange data with the robots.

Variables

int robotAddress [100]
char leftSpeed [100]
char rightSpeed [100]
char redLed [100]
char greenLed [100]
char blueLed [100]
unsigned int proxValue [100][8]
unsigned int proxAmbientValue [100][8]
unsigned int groundValue [100][4]
unsigned int groundAmbientValue [100][4]
unsigned int batteryAdc [100]
unsigned int batteryPercent [100]
signed int accX [100]
signed int accY [100]
signed int accZ [100]
unsigned char selector [100]
unsigned char tvRemote [100]
unsigned char flagsRX [100]
unsigned char flagsTX [100][2]
unsigned char smallLeds [100]
signed long int leftMotSteps [100]
signed long int rightMotSteps [100]
signed int robTheta [100]
signed int robXPos [100]
signed int robYPos [100]
unsigned char sleepEnabledFlag [100]
char RX_buffer [64] = {0}
char TX_buffer [64] = {0}
double numOfErrors [100]
double numOfPackets = 0
double errorPercentage [100]
unsigned char lastMessageSentFlag [100]
unsigned char calibrationSent [100]
unsigned char calibrateOdomSent [100]
unsigned char stopTransmissionFlag = 0
unsigned int currNumRobots = 0
unsigned int currPacketId = 0
unsigned char usbCommOpenedFlag = 0

Define Documentation

#define ADDR_SIZE   2
#define ALL_IR_OFF (   x)    ((x) &= ~(1 << 0) & ~(1 << 1))
#define ALL_IR_ON (   x)    ((x) |= (1<<0) | (1 << 1))
#define BACK_IR_OFF (   x)    ((x) &= ~(1 << 0))
#define BACK_IR_ON (   x)    ((x) |= (1 << 0))
#define CALIBRATION_OFF (   x)    ((x) &= ~(1 << 4))
#define CALIBRATION_ON (   x)    ((x) |= (1<<4))
#define CLIFF_AVOID_OFF (   x)    ((x) &= ~(1 << 7))
#define CLIFF_AVOID_ON (   x)    ((x) |= (1<<7))
#define FRONT_IR_OFF (   x)    ((x) &= ~(1 << 1))
#define FRONT_IR_ON (   x)    ((x) |= (1 << 1))
#define NUM_ROBOTS   4
#define OBSTACLE_AVOID_OFF (   x)    ((x) &= ~(1 << 6))
#define OBSTACLE_AVOID_ON (   x)    ((x) |= (1<<6))
#define OVERHEAD_SIZE   (2*NUM_ROBOTS+1)
#define PACKETS_SIZE   64
#define PAYLOAD_SIZE   13
#define RAD_2_DEG   57.2957796
#define SLEEP_OFF (   x)    ((x) &= ~(1 << 3))
#define SLEEP_ON (   x)    ((x) = 0x08)
#define TV_REMOTE_OFF (   x)    ((x) &= ~(1 << 2))
#define TV_REMOTE_ON (   x)    ((x) |= (1<<2))
#define UNUSED_BYTES   3

Function Documentation

unsigned char buttonIsPressed ( int  robotAddr)

Tell whether the button on the back side of the robot is pressed or not.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
0 not pressed, 1 button is pressed.
void calibrateSensors ( int  robotAddr)

Calibrate the sensors of the robot (proximity, accelerometer).

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none

Calibrate the sensors (proximity, accelerometer) of all the robots specified in the list.

Returns:
none
unsigned char checkConcurrency ( int  id)
int computeVerticalAngle ( signed int  x,
signed int  y 
)
void disableCliffAvoidance ( int  robotAddr)

Disable the onboard cliff avoidance.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void disableObstacleAvoidance ( int  robotAddr)

Disable the onboard obstacle avoidance.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void disableSleep ( int  robotAddr)

Put the robot in normal mode (out of sleep).

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void disableTVRemote ( int  robotAddr)

Disable the reception of commands from a TV remote.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void enableCliffAvoidance ( int  robotAddr)

Enable the onboard cliff avoidance.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void enableObstacleAvoidance ( int  robotAddr)

Enable the onboard obstacle avoidance.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void enableSleep ( int  robotAddr)

Put the robot in sleep mode (energy saving mode).

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void enableTVRemote ( int  robotAddr)

Enable the reception of commands from a TV remote.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void freeMutexRx ( )
void freeMutexThread ( )
void freeMutexTx ( )
signed int getAccX ( int  robotAddr)

Request the raw value of the accelerometer x axis.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current x value, the range is between -64 to 64.
signed int getAccY ( int  robotAddr)

Request the raw value of the accelerometer y axis.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current y value, the range is between -64 to 64.
signed int getAccZ ( int  robotAddr)

Request the raw value of the accelerometer z axis.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current z value, the range is between -64 to 64.
void getAllGround ( int  robotAddr,
unsigned int *  groundArr 
)

Request all the ground sensors values at once.

Parameters:
robotAddrthe address of the robot from which receive data.
groundArrdestination array for the ground values (size must be 4).
Returns:
none
void getAllGroundAmbient ( int  robotAddr,
unsigned int *  groundArr 
)

Request all the ambient values (from ground sensors) at once.

Parameters:
robotAddrthe address of the robot from which receive data.
groundArrdestination array for the ambient values (size must be 4).
Returns:
none
void getAllGroundAmbientFromAll ( unsigned int  groundArr[][4])

Request all the ambient values (from ground sensors) of all the robots specified in the list.

Parameters:
groundArrdestination matrix for the ambient values (size must be list_size x 4).
Returns:
none
void getAllGroundFromAll ( unsigned int  groundArr[][4])

Request all the ground sensors values of all the robots specified in the list.

Parameters:
groundArrdestination matrix for the ground values (size must be list_size x 4).
Returns:
none
void getAllProximity ( int  robotAddr,
unsigned int *  proxArr 
)

Request all the proximity sensors values at once.

Parameters:
robotAddrthe address of the robot from which receive data.
proxArrdestination array for the proximity values (size must be 8).
Returns:
none
void getAllProximityAmbient ( int  robotAddr,
unsigned int *  proxArr 
)

Request all the ambient values (from proximity sensors) at once.

Parameters:
robotAddrthe address of the robot from which receive data.
proxArrdestination array for the ambient values (size must be 8).
Returns:
none
void getAllProximityAmbientFromAll ( unsigned int  proxArr[][8])

Request all the ambient values (from proximity sensors) of all the robots specified in the list.

Parameters:
proxArrdestination matrix for the ambient values (size must be list_size x 8).
Returns:
none
void getAllProximityFromAll ( unsigned int  proxArr[][8])

Request all the proximity sensors values of all the robots specified in the list.

Parameters:
proxArrdestination matrix for the proximity values (size must be list_size x 8).
Returns:
none
unsigned int getBatteryAdc ( int  robotAddr)

Request the raw battery value, it contains the sampled value of the battery.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current battery value, the values range is between 780 (battery discharged) and 930 (battery charged).
unsigned int getBatteryPercent ( int  robotAddr)

Request the charge percentage of the battery.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current charge percentage, the values range is between 0 and 100.
unsigned char getFlagRX ( int  robotAddr)

Request the current flags value (raw) received from the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current flag value.
unsigned char getFlagTX ( int  robotAddr,
int  flagInd 
)

Request the current flags value (raw) sent to the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
flagInd0 or 1
Returns:
current flag value.
unsigned int getGround ( int  robotAddr,
int  groundId 
)

Request one of the ground sensors value of the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
groundIdfrom 0 to 3 (0 is on the left side, then increases clockwise).
Returns:
current ground value from 512 to 1023, the smaller the value the darker the surface
unsigned int getGroundAmbient ( int  robotAddr,
int  groundId 
)

Request one of the ambient value (from ground sensors) of the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
groundIdfrom 0 to 3 (0 is on the left side, then increases clockwise).
Returns:
current ambient value from 0 to 1023, the smaller the value the brighter the ambient light
int getIdFromAddress ( int  address)
signed long int getLeftMotSteps ( int  robotAddr)

Request the current raw value of the left motor steps (sum of the measured speed).

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current motor steps.
signed int getOdomTheta ( int  robotAddr)

Request the current orientation of the robot computed from the measured speed of the motors.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current orientation of the robot expressed in 1/10 of degree (3600 degrees for a full turn).
signed int getOdomXpos ( int  robotAddr)

Request the current position (x component) of the robot computed from the measured speed of the motors.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current x position of the robot expressed in millimiters.
signed int getOdomYpos ( int  robotAddr)

Request the current position (y component) of the robot computed from the measured speed of the motors.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current y position of the robot expressed in millimiters.
unsigned int getProximity ( int  robotAddr,
int  proxId 
)

Request one of the proximity sensors value of the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
proxIdfrom 0 to 7 (0 is in front, then increases clockwise).
Returns:
current proximity value from 0 to 1023, the greater the value the nearer the objects to the sensor
unsigned int getProximityAmbient ( int  robotAddr,
int  proxId 
)

Request one of the ambient value (from proximity sensors) of the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
proxIdfrom 0 to 7 (0 is in front, then increases clockwise).
Returns:
current ambient value from 0 to 1023, the smaller the value the brighter the ambient light
double getRFQuality ( int  robotAddr)

Request the current percentage of failed trasnfers in the last 5 seconds.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current quality, 0 to 100.
signed long int getRightMotSteps ( int  robotAddr)

Request the current raw value of the right motor steps (sum of the measured speed).

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current motor steps.
unsigned char getSelector ( int  robotAddr)

Request the selector position.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current selector position, range is between 0 and 15.
unsigned char getTVRemoteCommand ( int  robotAddr)

Request last command received from the TV remote.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current TV remote value.
int getVerticalAngle ( int  robotAddr)

Request the current orientation of the robot given by the accelerometer. This function is usable only if the robot is moving vertically.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
current robot orientation, range is between 0 and 360 degrees (0 pointing to the right).
unsigned char messageIsSent ( int  robotAddr)

Request if the last modified packet is sent to the robot; this function is thought to be used in polling mode (continue to check whether the message is sent untill it is actually sent). Before the polling the function "resetMessageIsSentFlag" need to be called. It can be used for both check whether the robots received the new messages and to know when new data from the robots are available.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
0 if message not received by the robot, 1 if message sent correctly.
void resetFlagTX ( int  robotAddr)

Reset all the flags sent to the robot.

Parameters:
robotAddrthe address of the robot for which to change data.
Returns:
none.
void resetMessageIsSentFlag ( int  robotAddr)

Reset the flag indicating that the last modified packet is sent to the robot; it should be called before using "messageIsSent".

Parameters:
robotAddrthe address of the robot for which to change data.
Returns:
none.
void resetRobotData ( int  robotIndex)

This function resume the transmission of the packets to the robots.

Returns:
none.
unsigned char robotIsCharged ( int  robotAddr)

Tell whether the robot is completely charged or not.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
0 not charged, 1 robot is charged.
unsigned char robotIsCharging ( int  robotAddr)

Tell whether the robot is charging or not.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
0 not charging, 1 robot is charging.
unsigned char sendMessageToRobot ( int  robotAddr,
char  red,
char  green,
char  blue,
char  flags[2],
char  left,
char  right,
char  leds,
unsigned long  us 
)

Send a message to a particular robot resetting the list of robots to a single one (all previous address set with "startCommunication" will be lost).

Parameters:
robotAddrthe address of the robot for which to change data.
red,green,redRGB channels intensity, range is between 0 (led off) to 100 (max power).
flagsraw flag bytes: byte0:
  • first two bits are dedicated to the IRs: 0x00 => all IRs off 0x01 => back IR on 0x02 => front IRs on 0x03 => all IRs on
  • third bit is used for enabling/disablng IR remote control (0=>diabled, 1=>enabled)
  • fourth bit is used for sleep (1 => go to sleep for 1 minute)
  • fifth bit is used to calibrate all sensors (proximity, ground, accelerometer)
  • sixth bits is reserved (used by radio station)
  • seventh bit is used for enabling/disabling onboard obstacle avoidance
  • eight bit is used for enabling/disabling onboard cliff avoidance byte1:
  • first is used for starting odometry calibration
left,rightleft and right speed, range is -128..127.
ledsraw byte value for small green leds (bit0=0/1 turn off/on led0, bit1=0/1 turn off/on led1, ...).
usfunction timeout given in microseconds
Returns:
0 if message sent succesfully, 1 otherwise.
void setBlue ( int  robotAddr,
unsigned char  value 
)

Set the blue intensity of the RGB led on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
valueThe intensity, range is between 0 (led off) to 100 (max power).
Returns:
none
void setBlueForAll ( unsigned char *  value)

Set the blue intensity of the RGB led of all all the robots specified in the list.

Parameters:
valueThe intensity array, range is between 0 (led off) to 100 (max power).
Returns:
none
void setCompletePacket ( int  robotAddr,
char  red,
char  green,
char  blue,
char  flags[2],
char  left,
char  right,
char  leds 
)

Set all the values of a robot at one time.

Parameters:
robotAddrthe address of the robot for which to change data.
red,green,redRGB channels intensity, range is between 0 (led off) to 100 (max power).
flagsraw flag bytes: byte0:
  • first two bits are dedicated to the IRs: 0x00 => all IRs off 0x01 => back IR on 0x02 => front IRs on 0x03 => all IRs on
  • third bit is used for enabling/disablng IR remote control (0=>diabled, 1=>enabled)
  • fourth bit is used for sleep (1 => go to sleep for 1 minute)
  • fifth bit is used to calibrate all sensors (proximity, ground, accelerometer)
  • sixth bits is reserved (used by radio station)
  • seventh bit is used for enabling/disabling onboard obstacle avoidance
  • eight bit is used for enabling/disabling onboard cliff avoidance byte1:
  • first is used for starting odometry calibration
left,rightleft and right speed, range is -128..127.
ledsraw byte value for small green leds (bit0=0/1 turn off/on led0, bit1=0/1 turn off/on led1, ...).
Returns:
none.
void setCompletePacketForAll ( int *  robotAddr,
char *  red,
char *  green,
char *  blue,
char  flags[][2],
char *  left,
char *  right,
char *  leds 
)

Set all the values of all the robots specified in the list.

Parameters:
robotAddrarray the addresses of the robots for which to change data.
red,green,redarrays RGB channels intensity, range is between 0 (led off) to 100 (max power).
flagsarray raw flag bytes: byte0:
  • first two bits are dedicated to the IRs: 0x00 => all IRs off 0x01 => back IR on 0x02 => front IRs on 0x03 => all IRs on
  • third bit is used for enabling/disablng IR remote control (0=>diabled, 1=>enabled)
  • fourth bit is used for sleep (1 => go to sleep for 1 minute)
  • fifth bit is used to calibrate all sensors (proximity, ground, accelerometer)
  • sixth bits is reserved (used by radio station)
  • seventh bit is used for enabling/disabling onboard obstacle avoidance
  • eight bit is used for enabling/disabling onboard cliff avoidance byte1:
  • first is used for starting odometry calibration
left,rightarrays left and right speed, range is -128..127.
ledsarray raw byte value for small green leds (bit0=0/1 turn off/on led0, bit1=0/1 turn off/on led1, ...).
Returns:
none.
void setGreen ( int  robotAddr,
unsigned char  value 
)

Set the green intensity of the RGB led on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
valueThe intensity, range is between 0 (led off) to 100 (max power).
Returns:
none
void setGreenForAll ( unsigned char *  value)

Set the green intensity of the RGB led of all the robots specified in the list.

Parameters:
valueThe intensity array, range is between 0 (led off) to 100 (max power).
Returns:
none
void setLeftSpeed ( int  robotAddr,
char  value 
)

Set the left speed of the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
valueThe speed, range is between -128 to 127.
Returns:
none
void setLeftSpeedForAll ( char *  value)

Set the left speed of all the robots specified in the list.

Parameters:
valueThe speed array, range is between -128 to 127.
Returns:
none
void setMutexRx ( )
void setMutexThread ( )
void setMutexTx ( )
void setRed ( int  robotAddr,
unsigned char  value 
)

Set the red intensity of the RGB led on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
valueThe intensity, range is between 0 (led off) to 100 (max power).
Returns:
none
void setRedForAll ( unsigned char *  value)

Set the red intensity of the RGB led of all the robots specified in the list.

Parameters:
valueThe intensity array, range is between 0 (led off) to 100 (max power).
Returns:
none
void setRightSpeed ( int  robotAddr,
char  value 
)

Set the right speed of the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
valueThe speed, range is between -128 to 127.
Returns:
none
void setRightSpeedForAll ( char *  value)

Set the right speed of all the robots specified in the list.

Parameters:
valueThe speed array, range is between -128 to 127.
Returns:
none
void setRobotAddress ( int  robotIndex,
int  robotAddr 
)

Set the address of a robot related to a particular index, the index must be in the range of the robot list size.

Parameters:
robotIndexfrom 0 to number of robots - 1 (set with "setRobotAddresses" function)
robotAddrthe address of the robot
Returns:
none
void setRobotAddresses ( int *  robotAddr,
int  numRobots 
)

Set the addresses of the robots that need to be controlled; max number of simultaneous robots is 100.

Parameters:
robotAddrarray list of robot addresses to be handled.
numRobotsthe array size (number of robots to handle).
Returns:
none
void setSmallLed ( int  robotAddr,
int  ledId,
int  state 
)

Set a new stato (on or off) for the small green leds around the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
ledIdthe led to change, from 0 to 7 (0 is in front, then increases clockwise).
state0 to turn off, 1 to turn on.
Returns:
none.
char speed ( char  value)
void startCommunication ( int *  robotAddr,
int  numRobots 
)

To be called once at the beginning, it init the USB communication with the RF module that is responsible to send data to the robots and initialize the list of robots to be controlled; max number of simultaneous robots is 100.

Parameters:
robotAddrarray list of robot addresses to be handled.
numRobotsthe array size (number of robots to handle).
Returns:
none
void startOdometryCalibration ( int  robotAddr)

Start the odometry calibration.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none.

To be called once at the end, it closes the USB communication.

Returns:
none
void stopTransferData ( )

This function stop the transmission of the packets to the robots.

Returns:
none.
void transferData ( )

This function need to be called periodically (as fast as possible) in order to exchange data with the robots.

Returns:
none.
void turnOffAllIRs ( int  robotAddr)

Turn off all the 3 IRs transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOffBackIR ( int  robotAddr)

Turn off the back IR transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOffFrontIRs ( int  robotAddr)

Turn off both the front IRs transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOffSmallLeds ( int  robotAddr)

Turn off all the small green leds around the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
none.
void turnOnAllIRs ( int  robotAddr)

Turn on all the 3 IRs transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOnBackIR ( int  robotAddr)

Turn on the back IR transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOnFrontIRs ( int  robotAddr)

Turn on both the front IRs transmitter on the robot.

Parameters:
robotAddrthe address of the robot for which to change the packet.
Returns:
none
void turnOnSmallLeds ( int  robotAddr)

Turn on all the small green leds around the robot.

Parameters:
robotAddrthe address of the robot from which receive data.
Returns:
none.
unsigned char waitForUpdate ( int  robotAddr,
unsigned long  us 
)

Wait for updated data coming from the robot; if the robot isn't reachable (out of range, discharged, ...) then the function will exit after the amount of time specified as parameter even if no data are received. this function can be used also to check whether a message is successfully sent to a robot or not.

Parameters:
robotAddrthe address of the robot from which receive data.
usfunction timeout given in microseconds
Returns:
0 if updated data received, 1 otherwise.

Variable Documentation

signed int accX[100]
signed int accY[100]
signed int accZ[100]
unsigned int batteryAdc[100]
unsigned int batteryPercent[100]
char blueLed[100]
unsigned char calibrateOdomSent[100]
unsigned char calibrationSent[100]
unsigned int currNumRobots = 0
unsigned int currPacketId = 0
double errorPercentage[100]
unsigned char flagsRX[100]
unsigned char flagsTX[100][2]
char greenLed[100]
unsigned int groundAmbientValue[100][4]
unsigned int groundValue[100][4]
unsigned char lastMessageSentFlag[100]
signed long int leftMotSteps[100]
char leftSpeed[100]
double numOfErrors[100]
double numOfPackets = 0
unsigned int proxAmbientValue[100][8]
unsigned int proxValue[100][8]
char redLed[100]
signed long int rightMotSteps[100]
char rightSpeed[100]
int robotAddress[100]
signed int robTheta[100]
signed int robXPos[100]
signed int robYPos[100]
char RX_buffer[64] = {0}
unsigned char selector[100]
unsigned char sleepEnabledFlag[100]
unsigned char smallLeds[100]
unsigned char stopTransmissionFlag = 0
unsigned char tvRemote[100]
char TX_buffer[64] = {0}
unsigned char usbCommOpenedFlag = 0
 All Files Functions Variables Defines