Arduino {code}racer API
... better know the details.

Functions

void CodeRacer::stop_driving ()
 Stops the racer and sets status LEDs. More...
 
void CodeRacer::drive_forward ()
 Sets the speed and the directions of both drives so that it will move forward. More...
 
void CodeRacer::drive_forward (uint8_t left_speed, uint8_t right_speed)
 Sets the speed as specified for both drives and the directions of both drives so that it will move forward. More...
 
void CodeRacer::drive_backward ()
 Sets the speed and the directions of both drives so that it will move backward. More...
 
void CodeRacer::drive_backward (uint8_t left_speed, uint8_t right_speed)
 Sets the speed as specified for both drives and the directions of both drives so that it will move backward. More...
 
void CodeRacer::turn_left ()
 Will turn the racer to the left for the internally stroe time in ms and with the internally stored speed. More...
 
void CodeRacer::turn_left (unsigned long turn_for_ms)
 Will turn the racer to the left for the specified time in ms and with the internally stored speed. More...
 
void CodeRacer::turn_left (unsigned long turn_for_ms, uint8_t left_speed, uint8_t right_speed)
 Will turn the racer to the left for the specified time in ms and with the specified speed. More...
 
void CodeRacer::turn_right ()
 Will turn the racer to the right for the internally stroe time in ms and with the internally stored speed. More...
 
void CodeRacer::turn_right (unsigned long turn_for_ms)
 Will turn the racer to the right for the specified time in ms and with the internally stored speed. More...
 
void CodeRacer::turn_right (unsigned long turn_for_ms, uint8_t left_speed, uint8_t right_speed)
 Will turn the racer to the right for the specified time in ms and with the specified speed. More...
 
void CodeRacer::start_stop_at_min_distance ()
 Enables to stopp the racer if during a distance measurement the measured distance is smaller then the internally stored minimal distance. More...
 
void CodeRacer::start_stop_at_min_distance (unsigned long min_distance_cm)
 Enables to stopp the racer if during a distance measurement the measured distance is smaller then the specified minimal distance. More...
 
void CodeRacer::stop_stop_at_min_distance ()
 Disables to stopp the racer if during a distance measurement the measured distance is smaller then the specified minimal distance. More...
 
bool CodeRacer::start_stop ()
 This will return if the codracer is in active mode or not. More...
 

Detailed Description

Function Documentation

◆ stop_driving()

void CodeRacer::stop_driving ( )

Stops the racer and sets status LEDs.

Returns
nothing

Definition at line 161 of file CodeRacer.cpp.

161  {
162  _servo_sweep = false;
163  _drive = false;
164  set_drives_stop_left_right();
165  set_leds_left_stop_frwd_right(LEDOFF, LEDON, LEDOFF, LEDOFF);
166 }

◆ drive_forward() [1/2]

void CodeRacer::drive_forward ( )

Sets the speed and the directions of both drives so that it will move forward.

The speed is taken from the header file or set by one of the methods defined in the lower level drive methods section

Returns
nothing

Definition at line 173 of file CodeRacer.cpp.

174 {
175  drive_forward(_drive_left_speed, _drive_right_speed);
176 }
Here is the call graph for this function:

◆ drive_forward() [2/2]

void CodeRacer::drive_forward ( uint8_t  left_speed,
uint8_t  right_speed 
)

Sets the speed as specified for both drives and the directions of both drives so that it will move forward.

The specified speed values for both drives will be stored internaly so next time if you use e.g. drive_forward() exactly the here specified values will be taken.

Parameters
left_speedspeed for the left side drive. 0<=speed<=255
right_speedspeed for the right side drive. 0<=speed<=255
Returns
nothing

Definition at line 185 of file CodeRacer.cpp.

186 {
187  set_drives_states_left_right(DRIVEFRWD, DRIVEFRWD);
188  set_drives_speed_left_right(left_speed, right_speed);
189  set_leds_left_stop_frwd_right(LEDOFF, LEDOFF, LEDON, LEDOFF);
190  _drive = true;
191  _drive_set_at_ms = millis();
192 }

◆ drive_backward() [1/2]

void CodeRacer::drive_backward ( )

Sets the speed and the directions of both drives so that it will move backward.

The speed is taken from the header file or set by one of the methods defined in the lower level drive methods section

Returns
nothing

Definition at line 199 of file CodeRacer.cpp.

200 {
201  drive_backward(_drive_left_speed, _drive_right_speed);
202 }

◆ drive_backward() [2/2]

void CodeRacer::drive_backward ( uint8_t  left_speed,
uint8_t  right_speed 
)

Sets the speed as specified for both drives and the directions of both drives so that it will move backward.

The specified speed values for both drives will be stored internaly so next time if you use e.g. drive_backward() exactly the here specified values will be taken.

Parameters
left_speedspeed for the left side drive. 0<=speed<=255
right_speedspeed for the right side drive. 0<=speed<=255
Returns
nothing

Definition at line 211 of file CodeRacer.cpp.

212 {
213  set_drives_states_left_right(DRIVEBACK, DRIVEBACK);
214  set_drives_speed_left_right(left_speed, right_speed);
215  set_leds_left_stop_frwd_right(LEDOFF, LEDON, LEDON, LEDOFF);
216  _drive = true;
217  _drive_set_at_ms = millis();
218 }

◆ turn_left() [1/3]

void CodeRacer::turn_left ( )

Will turn the racer to the left for the internally stroe time in ms and with the internally stored speed.

The speed for both the left side and right side drive can be set by the methods described in the lower level drive section. The turn to left time can be set by thoose methods as well. The method is delayed until the racer has turned.

Returns
nothing

Definition at line 226 of file CodeRacer.cpp.

227 {
228  turn_left(_turn_left_for_ms, _drive_left_speed, _drive_right_speed);
229 }

◆ turn_left() [2/3]

void CodeRacer::turn_left ( unsigned long  turn_for_ms)

Will turn the racer to the left for the specified time in ms and with the internally stored speed.

The specified duration of time is stored internally and will be used next time by e.g. turn_left()

Parameters
turn_for_msduration of time in ms to turn the racer
Returns
nothing

Definition at line 237 of file CodeRacer.cpp.

238 {
239  turn_left(turn_for_ms, _drive_left_speed, _drive_right_speed);
240 }

◆ turn_left() [3/3]

void CodeRacer::turn_left ( unsigned long  turn_for_ms,
uint8_t  left_speed,
uint8_t  right_speed 
)

Will turn the racer to the left for the specified time in ms and with the specified speed.

The specified duration of time and the specified speeds are stored internally and will be used next time by e.g. turn_left()

Parameters
turn_for_msduration of time in ms to turn the racer
left_speedspeed for the left side drive
right_speedspeed for the right side drive
Returns
nothing

Definition at line 250 of file CodeRacer.cpp.

251 {
252  _drive = false;
253  set_leds_left_stop_frwd_right(LEDON, LEDOFF, LEDOFF, LEDOFF); // LEDs setzen
254  set_drives_states_left_right(DRIVEBACK, DRIVEFRWD);
255  set_drives_speed_left_right(left_speed, right_speed);
256  // wait set delay for the timed turn
257  _turn_left_for_ms = turn_for_ms;
258  delay(_turn_left_for_ms);
259  // stop drives again
260  set_drives_stop_left_right();
261 }

◆ turn_right() [1/3]

void CodeRacer::turn_right ( )

Will turn the racer to the right for the internally stroe time in ms and with the internally stored speed.

The speed for both the left side and right side drive can be set by the methods described in the lower level drive section. The turn to right time can be set by thoose methods as well. The method is delayed until the racer has turned.

Returns
nothing

Definition at line 269 of file CodeRacer.cpp.

270 {
271  turn_right(_turn_right_for_ms, _drive_left_speed, _drive_right_speed);
272 }

◆ turn_right() [2/3]

void CodeRacer::turn_right ( unsigned long  turn_for_ms)

Will turn the racer to the right for the specified time in ms and with the internally stored speed.

The specified duration of time is stored internally and will be used next time by e.g. turn_right()

Parameters
turn_for_msduration of time in ms to turn the racer
Returns
nothing

Definition at line 280 of file CodeRacer.cpp.

281 {
282  turn_right(turn_for_ms, _drive_left_speed, _drive_right_speed);
283 }

◆ turn_right() [3/3]

void CodeRacer::turn_right ( unsigned long  turn_for_ms,
uint8_t  left_speed,
uint8_t  right_speed 
)

Will turn the racer to the right for the specified time in ms and with the specified speed.

The specified duration of time and the specified speeds are stored internally and will be used next time by e.g. turn_right()

Parameters
turn_for_msduration of time in ms to turn the racer
left_speedspeed for the left side drive
right_speedspeed for the right side drive
Returns
nothing

Definition at line 293 of file CodeRacer.cpp.

294 {
295  _drive = false;
296  set_leds_left_stop_frwd_right(LEDOFF, LEDOFF, LEDOFF, LEDON); // LEDs setzen
297  set_drives_states_left_right(DRIVEFRWD, DRIVEBACK);
298  set_drives_speed_left_right(left_speed, right_speed);
299  // wait set delay for the timed turn
300  _turn_right_for_ms = turn_for_ms;
301  delay(_turn_right_for_ms);
302  // stop drives again
303  set_drives_stop_left_right();
304 }

◆ start_stop_at_min_distance() [1/2]

void CodeRacer::start_stop_at_min_distance ( )

Enables to stopp the racer if during a distance measurement the measured distance is smaller then the internally stored minimal distance.

This allow all of the none-single shot ultra sonic measurement methods to stopp the racer in the case the measured distance is smaller than minimal distance. This is just the enablement - you have to call one of the none-single-shot ultra sonic measurement methods continously while driving and maybe sweeping the servo. If the racer was stopped can be checked with stopped_at_min_distance() - it will return true in that case. The minimal distance can be set by the ultrasonic sensor setter methods. There is an example coming with the coderacer libary that you can load and get an idea how that works.

Returns
nothing

Definition at line 314 of file CodeRacer.cpp.

314  {
315  start_stop_at_min_distance(_usonic_stop_distance_cm);
316 }

◆ start_stop_at_min_distance() [2/2]

void CodeRacer::start_stop_at_min_distance ( unsigned long  min_distance_cm)

Enables to stopp the racer if during a distance measurement the measured distance is smaller then the specified minimal distance.

This is almos the same as described for start_stop_at_min_distance(). You can specify the distance in cm here - this value will be stored internally and used by start_stop_at_min_distance() next time.

Parameters
min_distance_cmthe minimal disctance in cm
Returns
nothing

Definition at line 324 of file CodeRacer.cpp.

324  {
325  if (false == _coderacer_stop_at_distance_enabled) {
326  _coderacer_stopped_at_min_distance = false;
327  usonic_set_stop_distance_cm(min_distance_cm);
328  _coderacer_stop_at_distance_enabled = true;
329  }
330 }

◆ stop_stop_at_min_distance()

void CodeRacer::stop_stop_at_min_distance ( )

Disables to stopp the racer if during a distance measurement the measured distance is smaller then the specified minimal distance.

Returns
nothing

Definition at line 335 of file CodeRacer.cpp.

335  {
336  _coderacer_stop_at_distance_enabled = false;
337 }

◆ start_stop()

bool CodeRacer::start_stop ( )

This will return if the codracer is in active mode or not.

There is a button used to toogle between active and inactive each time it is pressed This may help you to start driving and scanning the distance by pressing the button - and as well to stop the racer by pressing the button. This method will set the LEDs depending on the mode and sets the servo back to center and stopps the racer when leaving the active mode. You can leave or enter the active mode as well by setting using set_active() and set_inactive(). The button itself triggers and internall interrupt event and sets the active state - but you have to continously call that method to switch between inactive and active mode depending on the active state. If in inactive mode and fun is enabeld by just setting the coderacer_fun_enabled = true ... some fun will happen :-)

Returns
True if the coderacer is in active mode. False if in inactive mode.

Definition at line 348 of file CodeRacer.cpp.

348  {
349  if (_coderracer_activ != coderracer_activ) {
350  _coderracer_activ = coderracer_activ;
351  if (true == _coderracer_activ) {
352  set_leds_all_off();
353  delay(500);
354  }
355  else {
356  stop_driving();
357  set_leds_all_on();
358  delay(200);
359  servo_set_to_center();
360  _servo_look_around_at_ms = millis() + random(20000, 120000);
361  }
362  }
363 
364  if ((false == _coderracer_activ) && (true == coderacer_fun_enabled)) {
365  kitt();
366  look_around();
367  }
368 
369  return(_coderracer_activ);
370 }