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

Functions

void CodeRacer::servo_settings (uint8_t pos_center, uint8_t pos_left, uint8_t pos_right, uint8_t sweep_left_pos, uint8_t sweep_right_pos)
 Overwrites the default settings taken from header file by the parameters given to this method. More...
 
void CodeRacer::servo_sweep ()
 Turns sweeping of the servo from left to right and back on. More...
 
void CodeRacer::servo_set_to_right ()
 Drives the servo to the postion that is defined by #servo_right_pos. More...
 
void CodeRacer::servo_set_to_left ()
 Drives the servo to the postion that is defined by #servo_left_pos. More...
 
void CodeRacer::servo_set_to_center ()
 Drives the servo to the postion that is defined by #servo_center_pos. More...
 
uint8_t CodeRacer::servo_set_position_wait (uint8_t position)
 Drive the servo to the postion given to this method. More...
 
unsigned long CodeRacer::servo_set_position (uint8_t position)
 Drive the servo to the postion given to this method. More...
 

Detailed Description

Function Documentation

◆ servo_settings()

void CodeRacer::servo_settings ( uint8_t  pos_center,
uint8_t  pos_left,
uint8_t  pos_right,
uint8_t  sweep_left_pos,
uint8_t  sweep_right_pos 
)

Overwrites the default settings taken from header file by the parameters given to this method.

Parameters
pos_centerThe postion at which the servo moves to straight forward. Default is 90. Allowed 10 <= pos_center <= 170.
pos_leftThe postion at which the servo moves to the left. Default is 170. Allowed 10 <= pos_center <= 170.
pos_rightThe postion at which the servo moves to the right. Default is 10. Allowed 10 <= pos_center <= 170.
sweep_left_posIf the servo is sweeping from left to the right - this defines the most left postion. Default is 140. Allowed 10 <= pos_center <= 170.
sweep_right_posIf the servo is sweeping from left to the right - this defines the most right postion. Default is 40. Allowed 10 <= pos_center <= 170.
Returns
nothing

Definition at line 510 of file CodeRacer.cpp.

511 {
512  servo_center_pos = pos_center;
513  servo_left_pos = pos_left;
514  servo_right_pos = pos_right;
515  servo_sweep_left_pos = sweep_left_pos;
516  servo_sweep_right_pos = sweep_right_pos;
517 }

◆ servo_sweep()

void CodeRacer::servo_sweep ( )

Turns sweeping of the servo from left to right and back on.

The sweeping range is defind by #servo_sweep_left_pos and #servo_sweep_right_pos attributes. Both can be set by either servo_settings() or as public members. Every time servo_sweep() is called the servo is driven by 5 steps until either #servo_sweep_left_pos or #servo_sweep_right_pos is reached. Then it will turn the direction and step to the other side every time this method is called.

Returns
nothing

Definition at line 526 of file CodeRacer.cpp.

527 {
528  uint8_t position;
529  _servo_sweep = true;
530  if (millis() - _servo_position_set_at_ms > SERVO_SWEEP_MS) {
531  position = _servo_position + _servo_sweep_step;
532  //sprintf(_debugmsg,"[%s] current position=%ld newpostion=%ld", __func__, _servo_position, position);
533  if ((position >= servo_sweep_left_pos) || (position >= SERVO_MAX_POSITION)) {
534  position = servo_sweep_left_pos;
535  _servo_sweep_step = SERVO_SWEEP_TO_RIGHT_STEP;
536  }
537  if ((position <= servo_sweep_right_pos) || (position <= SERVO_MIN_POSITION)) {
538  position = servo_sweep_right_pos;
539  _servo_sweep_step = SERVO_SWEEP_TO_LEFT_STEP;
540  }
541  _servo_set_position(position);
542  }
543 }

◆ servo_set_to_right()

void CodeRacer::servo_set_to_right ( )

Drives the servo to the postion that is defined by #servo_right_pos.

Returns
nothing

Definition at line 548 of file CodeRacer.cpp.

549 {
550  servo_set_position_wait(servo_right_pos);
551 }

◆ servo_set_to_left()

void CodeRacer::servo_set_to_left ( )

Drives the servo to the postion that is defined by #servo_left_pos.

Returns
nothing

Definition at line 556 of file CodeRacer.cpp.

557 {
558  servo_set_position_wait(servo_left_pos);
559 }

◆ servo_set_to_center()

void CodeRacer::servo_set_to_center ( )

Drives the servo to the postion that is defined by #servo_center_pos.

Returns
nothing

Definition at line 564 of file CodeRacer.cpp.

565 {
566  servo_set_position_wait(servo_center_pos);
567 }

◆ servo_set_position_wait()

uint8_t CodeRacer::servo_set_position_wait ( uint8_t  position)

Drive the servo to the postion given to this method.

The method will wait until the servo has reached its new position.

Parameters
positionPosition the servo will be drived to. Allowed are values 10<=postion<=170. 10 is at the right hand side, 170 at the left hand side.
Returns
The new servo position

Definition at line 575 of file CodeRacer.cpp.

576 {
577  _servo_sweep = false;
578  unsigned long wait_time_ms = _servo_set_position(position);
579  delay(wait_time_ms);
580  return(_servo_position);
581 }

◆ servo_set_position()

unsigned long CodeRacer::servo_set_position ( uint8_t  position)

Drive the servo to the postion given to this method.

The method will not wait until the servo has reached its new position.

Parameters
positionPosition the servo will be drived to. Allowed are values 10<=postion<=170. 10 is at the right hand side, 170 at the left hand side.
Returns
The time in ms the servo will need to reach the new position

Definition at line 589 of file CodeRacer.cpp.

590 {
591  _servo_sweep = false;
592  unsigned long wait_time_ms = _servo_set_position(position);
593  return(wait_time_ms);
594 }