|
KU Corobots
KU Corobots Documentation
|
Class definition for creating a Corobot controller object. More...
#include <Corobot.h>
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. | |
Class definition for creating a Corobot controller object.
| void CorobotC::setLeftMotor | ( | Direction | dir, |
| uint8_t | power | ||
| ) | const |
Set power and direction for the left motor.
| dir | FORWARD|BACKWARD Direction of the left motor |
| power | 0-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.
| dir | FORWARD|BACKWARD Direction of the right motor |
| power | 0-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.
| dir_l | FORWARD|BACKWARD Direction of the left motor |
| dir_r | FORWARD|BACKWARD Direction of the right motor |
| power_l | 0-100 Power of the left motor |
| power_r | 0-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()
| leftMotorPercent | Power percentage adjustment to be applied to the left motor |
| rightMotorPercent | Power 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.
| true | the left eye is on top of a non-black color floor |
| false | the 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.
| true | the right eye is on top of a non-black color floor |
| false | the 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.
| true | the center eye is on top of a non-black color floor |
| false | the 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.
| const char * CorobotC::getColorName | ( | Color | c | ) | const |
Translate the given color code into a textual name.
| c | Color code |
| void CorobotC::getRawColor | ( | uint16_t * | r, |
| uint16_t * | g, | ||
| uint16_t * | b, | ||
| uint16_t * | c | ||
| ) |
Get raw color readings from the color sensor.
| r | Pointer to 16-bit unsigned integer to store raw red intensity reading |
| g | Pointer to 16-bit unsigned integer to store raw green intensity reading |
| b | Pointer to 16-bit unsigned integer to store raw blue intensity reading |
| c | Pointer 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.
| rr | Raw red intensity value |
| rg | Raw green intensity value |
| rb | Raw blue intensity value |
| rc | Raw clear intensity value |
| 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.
| black_r,black_g,black_b,black_c | Raw color sensor readings when the sensor is on black color |
| white_r,white_g,white_b,white_c | Raw color sensor readings when the sensor is on white color |
| red_r,red_g,red_b,red_c | Raw color sensor readings when the sensor is on red color |
| green_r,green_g,green_b,green_c | Raw color sensor readings when the sensor is on green color |
| blue_r,blue_g,blue_b,blue_c | Raw color sensor readings when the sensor is on blue color |
| yellow_r,yellow_g,yellow_b,yellow_c | Raw color sensor readings when the sensor is on yellow color |
| magenta_r,magenta_g,magenta_b,magenta_c | Raw 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.
| 0 | The Corobot is leveled with respect to the pitch axis |
| >0 | The Corobot's nose is pointing downward |
| <0 | The Corobot's nose is pointing upward |
| int8_t CorobotC::getRoll | ( | ) | const |
Return the current rotation angle of the Corobot along the roll axis.
| 0 | The Corobot is leveled with respect to the roll axis |
| >0 | The Corobot is banking right |
| <0 | The Corobot is banking left |
| void CorobotC::getRawAccel | ( | uint16_t * | ax, |
| uint16_t * | ay, | ||
| uint16_t * | az | ||
| ) |
Obtain the raw accelerometer's readings.
| ax | Pointer to a location for storing x-axis acceleration |
| ay | Pointer to a location for storing y-axis acceleration |
| az | Pointer 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.
| ax,ay,az | Accelerometer reading on the X, Y and Z axes, respectively |
| 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.
| ax,ay,az | Accelerometer reading on the X, Y and Z axes, respectively |
| void CorobotC::calibrateAccel | ( | uint16_t | ax, |
| uint16_t | ay, | ||
| uint16_t | az | ||
| ) |
Calibrate the accelerometer as "leveled" using the specified acceleration values.
| ax | Acceleration value on the x-axis |
| ay | Acceleration value on the y-axis |
| az | Acceleration 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.
| c | Color code of the LED, which can be either RED, YELLOW, or GREEN. Requests to set other colors will be silently ignored. |
| state | true 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.
| value | Value 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.
| state | true 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.
| state | true 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.
| true | the switch is pressed. |
| false | the 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
| void CorobotC::waitSwitchRelease | ( | ) | const |
Wait until the switch on the basic I/O board is released.
If the switch is currently released, this function will return immediately
| 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.
| 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).
1.7.6.1