KU Corobots KU Corobots Documentation

- Main Page
- Classes
- Files

- File List
- File Members

Corobot.h
Go to the documentation of this file.

    00001
    00007 #ifndef COROBOT_H
    00008 #define COROBOT_H
    00009
    00010 #include <Arduino.h>
    00011 #include <Adafruit_TCS34725.h>
    00012
    00013 /*****************************************/
    00016 enum Direction { BACKWARD, FORWARD };
    00017
    00018 /*****************************************/
    00021 enum Color {
    00022   BLACK   = 0,
    00023   WHITE   = 1,
    00024   RED     = 2,
    00025   GREEN   = 3,
    00026   BLUE    = 4,
    00027   YELLOW  = 5,
    00028   MAGENTA = 6,
    00029   UNKNOWN = 7,
    00030 };
    00031
    00032 /*****************************************/
    00035 class CorobotC {
    00036 public:
    00043   HardwareSerial &remote = Serial1;
    00044
    00045   CorobotC();
    00046
    00047   void init();
    00048
    00049   void setLeftMotor(Direction dir,uint8_t speed) const;
    00050   void setRightMotor(Direction dir,uint8_t speed) const;
    00051   void setMotors(Direction dir_l,uint8_t speed_l,Direction dir_r,uint8_t speed_r);
    00052   void calibrateMotors(uint8_t leftMotorPercent,uint8_t rightMotorPercent);
    00053
    00054   bool getLeftEye() const;
    00055   bool getRightEye() const;
    00056   bool getCenterEye() const;
    00057
    00058   Color getColor();
    00059   const char* getColorName(Color c) const;
    00060   void getRawColor(uint16_t *rr,uint16_t *rg,uint16_t *rb,uint16_t *rc);
    00061   Color getColor(uint16_t rr,uint16_t rg,uint16_t rb,uint16_t rc) const;
    00062   void calibrateColor(
    00063           uint16_t   black_r, uint16_t   black_g, uint16_t   black_b, uint16_t   black_c,
    00064           uint16_t   white_r, uint16_t   white_g, uint16_t   white_b, uint16_t   white_c,
    00065           uint16_t     red_r, uint16_t     red_g, uint16_t     red_b, uint16_t     red_c,
    00066           uint16_t   green_r, uint16_t   green_g, uint16_t   green_b, uint16_t   green_c,
    00067           uint16_t    blue_r, uint16_t    blue_g, uint16_t    blue_b, uint16_t    blue_c,
    00068           uint16_t  yellow_r, uint16_t  yellow_g, uint16_t  yellow_b, uint16_t  yellow_c,
    00069           uint16_t magenta_r, uint16_t magenta_g, uint16_t magenta_b, uint16_t magenta_c);
    00070
    00071   int8_t getPitch() const;
    00072   int8_t getRoll() const;
    00073   void getRawAccel(uint16_t *ax,uint16_t *ay,uint16_t *az);
    00074   int8_t getPitch(uint16_t ax,uint16_t ay,uint16_t az) const;
    00075   int8_t getRoll(uint16_t ax,uint16_t ay,uint16_t az) const;
    00076   void calibrateAccel();
    00077   void calibrateAccel(uint16_t ax,uint16_t ay,uint16_t az);
    00078
    00079   void setLed(Color c,bool state);
    00080   void setLedValue(uint8_t value);
    00081   void setRightLed(bool state);
    00082   void setLeftLed(bool state);
    00083   bool switchPressed() const;
    00084   void waitSwitchPress() const;
    00085   void waitSwitchRelease() const;
    00086
    00087   void waitRemote() const;
    00088
    00089 private:
    00090   Adafruit_TCS34725 _tcs;
    00091   uint8_t _leftMotorPercent;
    00092   uint8_t _rightMotorPercent;
    00093   uint8_t _color_map[UNKNOWN][4];  // [color][r,g,b,c]
    00094   uint16_t _color_range[4][2];     // [r,g,b,c][min,max]
    00095   uint16_t _accel_center_x;
    00096   uint16_t _accel_center_y;
    00097   uint16_t _accel_center_z;
    00098 };
    00099
    00101 extern CorobotC Corobot;
    00102
    00103 #endif