KU Corobots
KU Corobots Documentation
Public Member Functions | Public Attributes
CorobotC Class Reference

Class definition for creating a Corobot controller object. More...

#include <Corobot.h>

List of all members.

Public Member Functions

 CorobotC ()
 Construct a Corobot object.
void init ()
 Initialize Corobot.
void setLeftMotor (Direction dir, uint8_t speed) const
 Set power and direction for the left motor.
void setRightMotor (Direction dir, uint8_t speed) const
 Set power and direction for the right motor.
void setMotors (Direction dir_l, uint8_t speed_l, Direction dir_r, uint8_t speed_r)
 Set powers and directions for both motors.
void calibrateMotors (uint8_t leftMotorPercent, uint8_t rightMotorPercent)
 Calibrate motors.
bool getLeftEye () const
 Check whether the left eye (the left line tracker) is seeing non-black color.
bool getRightEye () const
 Check whether the right eye (the right line tracker) is seeing non-black color.
bool getCenterEye () const
 Check whether the center eye (the center line tracker) is seeing non-black color.
Color getColor ()
 Return the current color.
const char * getColorName (Color c) const
 Translate the given color code into a textual name.
void getRawColor (uint16_t *rr, uint16_t *rg, uint16_t *rb, uint16_t *rc)
 Get raw color readings from the color sensor.
Color getColor (uint16_t rr, uint16_t rg, uint16_t rb, uint16_t rc) const
 Estimate the color from the given raw values.
void calibrateColor (uint16_t black_r, uint16_t black_g, uint16_t black_b, uint16_t black_c, uint16_t white_r, uint16_t white_g, uint16_t white_b, uint16_t white_c, uint16_t red_r, uint16_t red_g, uint16_t red_b, uint16_t red_c, uint16_t green_r, uint16_t green_g, uint16_t green_b, uint16_t green_c, uint16_t blue_r, uint16_t blue_g, uint16_t blue_b, uint16_t blue_c, uint16_t yellow_r, uint16_t yellow_g, uint16_t yellow_b, uint16_t yellow_c, uint16_t magenta_r, uint16_t magenta_g, uint16_t magenta_b, uint16_t magenta_c)
 Calibrate the color sensor.
int8_t getPitch () const
 Return the current rotation angle of the Corobot along the pitch axis.
int8_t getRoll () const
 Return the current rotation angle of the Corobot along the roll axis.
void getRawAccel (uint16_t *ax, uint16_t *ay, uint16_t *az)
 Obtain the raw accelerometer's readings.
int8_t getPitch (uint16_t ax, uint16_t ay, uint16_t az) const
 Calculate the rotation angle of the Corobot along the pitch axis using the specified raw acceleration values.
int8_t getRoll (uint16_t ax, uint16_t ay, uint16_t az) const
 Calculate the rotation angle of the Corobot along the roll axis using the specified raw acceleration values.
void calibrateAccel ()
 Calibrate the accelerometer as "leveled" using the current readings.
void calibrateAccel (uint16_t ax, uint16_t ay, uint16_t az)
 Calibrate the accelerometer as "leveled" using the specified acceleration values.
void setLed (Color c, bool state)
 Set the state of the specified LED on the basic I/O board.
void setLedValue (uint8_t value)
 Set the LEDs on the basic I/O board to represent the binary of the specified value.
void setRightLed (bool state)
 Set the state of the right LED (the green TX LED) on the controller board.
void setLeftLed (bool state)
 Set the state of the left LED (the yellow RX LED) on the controller board.
bool switchPressed () const
 Check whether the switch on the basic I/O board is currently pressed.
void waitSwitchPress () const
 Wait until the switch on the basic I/O board is pressed.
void waitSwitchRelease () const
 Wait until the switch on the basic I/O board is released.
void waitRemote () const
 Wait until the remote Corobot is connected via Bluetooth.

Public Attributes

HardwareSerial & remote = Serial1
 Serial object reference for communicating with the remote Corobot via Bluetooth.

Detailed Description

Class definition for creating a Corobot controller object.


Member Function Documentation

void CorobotC::setLeftMotor ( Direction  dir,
uint8_t  power 
) const

Set power and direction for the left motor.

Parameters:
dirFORWARD|BACKWARD Direction of the left motor
power0-100 Power of the left motor

If calibrateMotors() has been used,the actual power of the motor will be adjusted by the previously specified power percentage.

void CorobotC::setRightMotor ( Direction  dir,
uint8_t  power 
) const

Set power and direction for the right motor.

Parameters:
dirFORWARD|BACKWARD Direction of the right motor
power0-100 Power of the right motor

If calibrateMotors() has been used,the actual power of the motor will be adjusted by the previously specified power percentage.

void CorobotC::setMotors ( Direction  dir_l,
uint8_t  power_l,
Direction  dir_r,
uint8_t  power_r 
)

Set powers and directions for both motors.

If calibrateMotors() has been previously called, the actual power of each motor will be normalized by the corresponding power percentage.

Parameters:
dir_lFORWARD|BACKWARD Direction of the left motor
dir_rFORWARD|BACKWARD Direction of the right motor
power_l0-100 Power of the left motor
power_r0-100 Power of the right motor
void CorobotC::calibrateMotors ( uint8_t  leftMotorPercent,
uint8_t  rightMotorPercent 
)

Calibrate motors.

The power percentages will be used to adjust the actual motors' powers when calling setLeftMotor(), setRightMotor(), and setMotors()

Parameters:
leftMotorPercentPower percentage adjustment to be applied to the left motor
rightMotorPercentPower percentage adjustment to be applied to the right motor
bool CorobotC::getLeftEye ( ) const

Check whether the left eye (the left line tracker) is seeing non-black color.

eye-left.png
Return values:
truethe left eye is on top of a non-black color floor
falsethe left eye is on top of a black floor
bool CorobotC::getRightEye ( ) const

Check whether the right eye (the right line tracker) is seeing non-black color.

eye-right.png
Return values:
truethe right eye is on top of a non-black color floor
falsethe right eye is on top of a black floor
bool CorobotC::getCenterEye ( ) const

Check whether the center eye (the center line tracker) is seeing non-black color.

eye-center.png
Return values:
truethe center eye is on top of a non-black color floor
falsethe center eye is on top of a black floor

Return the current color.

Color recognition is done by comparing the current raw color readings with the calibrated values indicated by the most recent call to calibrateColor(). The closest color is returned.

color-sensor.png
Returns:
Color code representing the recognized color on the floor.
const char * CorobotC::getColorName ( Color  c) const

Translate the given color code into a textual name.

Parameters:
cColor code
Returns:
String containing the corresponding textual color name
void CorobotC::getRawColor ( uint16_t *  r,
uint16_t *  g,
uint16_t *  b,
uint16_t *  c 
)

Get raw color readings from the color sensor.

Parameters:
rPointer to 16-bit unsigned integer to store raw red intensity reading
gPointer to 16-bit unsigned integer to store raw green intensity reading
bPointer to 16-bit unsigned integer to store raw blue intensity reading
cPointer to 16-bit unsigned integer to store raw clear intensity reading
Color CorobotC::getColor ( uint16_t  rr,
uint16_t  rg,
uint16_t  rb,
uint16_t  rc 
) const

Estimate the color from the given raw values.

Parameters:
rrRaw red intensity value
rgRaw green intensity value
rbRaw blue intensity value
rcRaw clear intensity value
Returns:
Corresponding color code recognized from the specified raw values
void CorobotC::calibrateColor ( uint16_t  black_r,
uint16_t  black_g,
uint16_t  black_b,
uint16_t  black_c,
uint16_t  white_r,
uint16_t  white_g,
uint16_t  white_b,
uint16_t  white_c,
uint16_t  red_r,
uint16_t  red_g,
uint16_t  red_b,
uint16_t  red_c,
uint16_t  green_r,
uint16_t  green_g,
uint16_t  green_b,
uint16_t  green_c,
uint16_t  blue_r,
uint16_t  blue_g,
uint16_t  blue_b,
uint16_t  blue_c,
uint16_t  yellow_r,
uint16_t  yellow_g,
uint16_t  yellow_b,
uint16_t  yellow_c,
uint16_t  magenta_r,
uint16_t  magenta_g,
uint16_t  magenta_b,
uint16_t  magenta_c 
)

Calibrate the color sensor.

These values will be used by the getColor() method for computing closest matching color.

Parameters:
black_r,black_g,black_b,black_cRaw color sensor readings when the sensor is on black color
white_r,white_g,white_b,white_cRaw color sensor readings when the sensor is on white color
red_r,red_g,red_b,red_cRaw color sensor readings when the sensor is on red color
green_r,green_g,green_b,green_cRaw color sensor readings when the sensor is on green color
blue_r,blue_g,blue_b,blue_cRaw color sensor readings when the sensor is on blue color
yellow_r,yellow_g,yellow_b,yellow_cRaw color sensor readings when the sensor is on yellow color
magenta_r,magenta_g,magenta_b,magenta_cRaw color sensor readings when the sensor is on magenta color
int8_t CorobotC::getPitch ( ) const

Return the current rotation angle of the Corobot along the pitch axis.

pitch.png
Returns:
Pitch angle in degrees between -20 and 20
Return values:
0The Corobot is leveled with respect to the pitch axis
>0The Corobot's nose is pointing downward
<0The Corobot's nose is pointing upward
int8_t CorobotC::getRoll ( ) const

Return the current rotation angle of the Corobot along the roll axis.

roll.png
Returns:
Roll angle in degrees between -20 and 20
Return values:
0The Corobot is leveled with respect to the roll axis
>0The Corobot is banking right
<0The Corobot is banking left
void CorobotC::getRawAccel ( uint16_t *  ax,
uint16_t *  ay,
uint16_t *  az 
)

Obtain the raw accelerometer's readings.

Parameters:
axPointer to a location for storing x-axis acceleration
ayPointer to a location for storing y-axis acceleration
azPointer to a location for storing z-axis acceleration
int8_t CorobotC::getPitch ( uint16_t  ax,
uint16_t  ay,
uint16_t  az 
) const

Calculate the rotation angle of the Corobot along the pitch axis using the specified raw acceleration values.

Parameters:
ax,ay,azAccelerometer reading on the X, Y and Z axes, respectively
Returns:
Pitch angle in degrees, similar to getRoll()
int8_t CorobotC::getRoll ( uint16_t  ax,
uint16_t  ay,
uint16_t  az 
) const

Calculate the rotation angle of the Corobot along the roll axis using the specified raw acceleration values.

Parameters:
ax,ay,azAccelerometer reading on the X, Y and Z axes, respectively
Returns:
Roll angle in degrees, similar to getPitch()
void CorobotC::calibrateAccel ( uint16_t  ax,
uint16_t  ay,
uint16_t  az 
)

Calibrate the accelerometer as "leveled" using the specified acceleration values.

Parameters:
axAcceleration value on the x-axis
ayAcceleration value on the y-axis
azAcceleration value on the z-axis
void CorobotC::setLed ( Color  c,
bool  state 
)

Set the state of the specified LED on the basic I/O board.

leds.jpg
Parameters:
cColor code of the LED, which can be either RED, YELLOW, or GREEN. Requests to set other colors will be silently ignored.
statetrue to turn the specified LED on; false to turn off
void CorobotC::setLedValue ( uint8_t  value)

Set the LEDs on the basic I/O board to represent the binary of the specified value.

leds.jpg
Parameters:
valueValue to be interpreted as binary. Only the 3 least significant bits will be used.
void CorobotC::setRightLed ( bool  state)

Set the state of the right LED (the green TX LED) on the controller board.

led-right.jpg
Parameters:
statetrue to turn the LED on; false to turn off
void CorobotC::setLeftLed ( bool  state)

Set the state of the left LED (the yellow RX LED) on the controller board.

led-left.jpg
Parameters:
statetrue to turn the LED on; false to turn off
bool CorobotC::switchPressed ( ) const

Check whether the switch on the basic I/O board is currently pressed.

switch.jpg
Return values:
truethe switch is pressed.
falsethe switch is not pressed.
void CorobotC::waitSwitchPress ( ) const

Wait until the switch on the basic I/O board is pressed.

If the switch is currently pressed, this function will return immediately

switch.jpg

Wait until the switch on the basic I/O board is released.

If the switch is currently released, this function will return immediately

switch.jpg
void CorobotC::waitRemote ( ) const

Wait until the remote Corobot is connected via Bluetooth.

Make sure that both Corobots call this same function during setup(). While calling this function, the special character '#' will be sent continuously to the remote Corobot. At the same time, the local Corobot is also expecting a '#' from the remote.


Member Data Documentation

HardwareSerial& CorobotC::remote = Serial1

Serial object reference for communicating with the remote Corobot via Bluetooth.

It has exactly the same API as Arduino's Serial object (https://www.arduino.cc/en/Reference/Serial).


The documentation for this class was generated from the following files: