eBoard ①⑧⑨
Written for SIA 2017/2018
eagle_SoccerBoard.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_SOCCERBOARD
2  #define EAGLE_EBOARD_HELPLIB_SOCCERBOARD
3 
12 //=====================================================================================================================================================
13 // SoccerBoard
14 //=====================================================================================================================================================
15 
16  //-------------------------------------------------------------------------------------------------------------------------------------------------
17  // class
18  //-------------------------------------------------------------------------------------------------------------------------------------------------
19 
45  struct SoccerBoard {
50  inline SoccerBoard(void);
51  //inline ~SoccerBoard(void) {}
52  #if EBOARD_USE_UTILITY > 0x0 or defined(__AVR_ATmega2560__) //won't shrink space... just speed things up
53 
61  inline void led(int idx,bool state);
69  inline void ledOn(int idx);
77  inline void ledOff(int idx);
83  inline void ledsOff(void);
89  inline void ledMeter(int);
90 
91  #endif
92  #if EBOARD_USE_UTILITY > 0x0
93  inline void /*bool*/ button(int);
96  inline void waitForButton(int);
97  #endif
98 
119  void motor(uint8_t id,int16_t val);
121  void motorsOff(void);
122  //ARDUINO UNO PINOUT
123  //D0,D1 => Bluetooth connection
124  //D4,D5 => MotorControl (D5: 980Hz)
125  //D10,D13 => SPI
126 
136  inline void power(optVAL_t id, bool state);
146  inline void powerOn(optVAL_t id);
156  inline void powerOff(optVAL_t id);
162  inline void sleep(uint16_t t);
168  inline void msleep(uint16_t t);
176  inline bool digital (optVAL_t id);
184  inline optVAL_t analog (optVAL_t id);
186  inline void reset(void); /* use crash-reset? =>*/ /* wdt_enable(WDTO_15MS); while(1) {} */
187  };
188 
190 
191  //-------------------------------------------------------------------------------------------------------------------------------------------------
192  // definitions
193  //-------------------------------------------------------------------------------------------------------------------------------------------------
194 
195  SoccerBoard::SoccerBoard(void) {}
196 
197  #if defined(__AVR_ATmega2560__)
198  inline void SoccerBoard::led(int idx, bool state) {writePin(13,state);}
199  void SoccerBoard::ledOn(int) {writePin(13,HIGH);}
200  void SoccerBoard::ledOff(int) {writePin(13,LOW);}
201  void SoccerBoard::ledsOff(void) {writePin(13,LOW);}
202  void SoccerBoard::ledMeter(int) {writePin(13,HIGH);}
203  #elif EBOARD_USE_UTILITY > 0x0
204  void SoccerBoard::led(int, bool) {}
205  void SoccerBoard::ledOn(int) {}
206  void SoccerBoard::ledOff(int) {}
207  void SoccerBoard::ledsOff(void) {}
208  void SoccerBoard::ledMeter(int) {}
209  #endif
210 
211  #if EBOARD_USE_UTILITY > 0x0
212  void SoccerBoard::button(int) {}
213  void SoccerBoard::waitForButton(int) {}
214  #endif
215 
216 
217  void SoccerBoard::reset(void) {
218  #if EBOARD_USE_RESET > 0x0
219  wdt_enable(WDTO_15MS);
220  for(;;) {}
221  #endif
222  }
223 
224  void SoccerBoard::motor(uint8_t id,int16_t val) {
225  #ifndef EBOARD_HELPCAR
226  if(id==0&&(val>-256 && val < 256)) {writePin(PIN_MOTOR_DIR,val<0); writePWM(abs(val));}
227  else if(id>0&&id<3) {_servoHandler.write(id,val);}
228  #else
229  if (id == 0) {
230  if(val < 0 || val > 180) return;
231  mainMotor.write(val);
232  }
233  else if (id == 1){
234  if(val < 0 || val > 180) return;
235  steerMotor.write(val);
236  }
237  #endif
238  }
239 
240  void SoccerBoard::motorsOff(void) {
241  #ifndef EBOARD_HELPCAR
242  writePWM(0);
243  #else
244  mainMotor.write(90);
245  #endif
246 
247  }
248 
249 
250  void SoccerBoard::power(optVAL_t id, bool state) {writePin(id,state);}
251  void SoccerBoard::powerOn(optVAL_t id) {this->power(id,1);}
252  void SoccerBoard::powerOff(optVAL_t id) {this->power(id,0);}
253  void SoccerBoard::sleep(uint16_t t) {delay(1000*t);}
254  void SoccerBoard::msleep(uint16_t t) {delay(t);}
255  bool SoccerBoard::digital (optVAL_t id) {return readPin(id);}
256  optVAL_t SoccerBoard::analog (optVAL_t id) {return readPin(id,0);}
258 #endif
void writePWM(optVAL_t val)
write a clamped pwm value to an output pin
Servo steerMotor
Definition: eBoard.h:651
SoccerBoard(void)
The constructor.
This is the SoccerBoard ghost struct :D.
void write(int value)
sets angle or pulse width of the Servo
void powerOn(optVAL_t id)
Set the state of a certain D-pin to HIGH.
void reset(void)
Resets the Soccerboard if EBOARD_USE_RESET is set to true.
void sleep(uint16_t t)
Say goodnight!
void writePin(optVAL_t idx, bool val)
write a boolean state to an output pin
void msleep(uint16_t t)
Say goodnight!
void motorsOff(void)
As requested this is the shortcut to disable the main motor.
void motor(uint8_t id, int16_t val)
As requested this is the ultimate shortcut ;)
bool digital(optVAL_t id)
Reads a digital value from a pin.
void power(optVAL_t id, bool state)
Set the state of a certain D-pin.
optVAL_t readPin(optVAL_t idx, bool dig=true)
read a digital state from an INPUTpin
#define PIN_MOTOR_DIR
Definition: eBoard.h:569
void write(int ID, int Pos)
Moves a Servo to a certain position.
optVAL_t analog(optVAL_t id)
Reads an analog value from a pin.
ServoCds55 _servoHandler
this is the "to_use" instance of ServoCds55
int optVAL_t
Definition: eBoard.h:137
Servo mainMotor
Definition: eBoard.h:651
void powerOff(optVAL_t id)
Set the state of a certain D-pin to LOW.