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 
117  void motor(uint8_t id,int16_t val);
119  void motorsOff(void);
120  //ARDUINO UNO PINOUT
121  //D0,D1 => Bluetooth connection
122  //D4,D5 => MotorControl (D5: 980Hz)
123  //D10,D13 => SPI
124 
134  inline void power(optVAL_t id, bool state);
144  inline void powerOn(optVAL_t id);
154  inline void powerOff(optVAL_t id);
160  inline void sleep(uint16_t t);
166  inline void msleep(uint16_t t);
174  inline bool digital (optVAL_t id);
182  inline optVAL_t analog (optVAL_t id);
184  inline void reset(void); /* use crash-reset? =>*/ /* wdt_enable(WDTO_15MS); while(1) {} */
185  };
186 
188 
189  //-------------------------------------------------------------------------------------------------------------------------------------------------
190  // definitions
191  //-------------------------------------------------------------------------------------------------------------------------------------------------
192 
193  SoccerBoard::SoccerBoard(void) {}
194 
195  #if defined(__AVR_ATmega2560__)
196  inline void SoccerBoard::led(int idx, bool state) {writePin(13,state);}
197  void SoccerBoard::ledOn(int) {writePin(13,HIGH);}
198  void SoccerBoard::ledOff(int) {writePin(13,LOW);}
199  void SoccerBoard::ledsOff(void) {writePin(13,LOW);}
200  void SoccerBoard::ledMeter(int) {writePin(13,HIGH);}
201  #elif EBOARD_USE_UTILITY > 0x0
202  void SoccerBoard::led(int, bool) {}
203  void SoccerBoard::ledOn(int) {}
204  void SoccerBoard::ledOff(int) {}
205  void SoccerBoard::ledsOff(void) {}
206  void SoccerBoard::ledMeter(int) {}
207  #endif
208 
209  #if EBOARD_USE_UTILITY > 0x0
210  void SoccerBoard::button(int) {}
211  void SoccerBoard::waitForButton(int) {}
212  #endif
213 
214 
215  void SoccerBoard::reset(void) {
216  #if EBOARD_USE_RESET > 0x0
217  wdt_enable(WDTO_15MS);
218  for(;;) {}
219  #endif
220  }
221 
223  void SoccerBoard::motor(uint8_t id,int16_t val) {
224  #ifndef EBOARD_HELPCAR
225  if(id==0&&(val>-256 && val < 256)) {setPin(PIN_MOTOR_DIR,val<0); writePWM(abs(val));}
226  else if(id>0&&id<3) {_servoHandler.write(id,val);}
227  #else
228  if (id == 0) {
229  if(val < 0 || val > 180) return;
230  mainMotor.write(val);
231  }
232  else if (id == 1){
233  if(val < 0 || val > 180) return;
234  steerMotor.write(val);
235  }
236  #endif
237  }
238  void SoccerBoard::motorsOff(void) {
239  #ifndef EBOARD_HELPCAR
240  writePWM(0);
241  #else
242  mainMotor.write(90);
243  #endif
244 
245  }
247 
248 
249  void SoccerBoard::power(optVAL_t id, bool state) {writePin(id,state);}
250  void SoccerBoard::powerOn(optVAL_t id) {this->power(id,1);}
251  void SoccerBoard::powerOff(optVAL_t id) {this->power(id,0);}
252  void SoccerBoard::sleep(uint16_t t) {delay(1000*t);}
253  void SoccerBoard::msleep(uint16_t t) {delay(t);}
254  bool SoccerBoard::digital (optVAL_t id) {return readPin(id);}
257 #endif
void writePWM(optVAL_t val)
write a clamped pwm value to an output pin
Servo steerMotor
Definition: eBoard.h:619
SoccerBoard(void)
The constructor.
This is the SoccerBoard ghost struct :D.
void setPin(optVAL_t idx, optVAL_t mode=OUTPUT)
[COPY&PASTE] set a pin to a certain mode => checkPin() will return true then
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:539
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:133
Servo mainMotor
Definition: eBoard.h:619
void powerOff(optVAL_t id)
Set the state of a certain D-pin to LOW.