Skip to content
Lukáš Dršman edited this page May 10, 2022 · 6 revisions

Contains compound movement functions for a dual-motor robot with a gyro sensor. Depends on base, pid and color.

Constants

Function types (fn_type)

  • NS_INI - initial non-stop movement function
  • NS_FIN - finalizing non-stop movement function
  • NS_MID - non-stop functions between NS_INI and NS_FIN
  • NS_STD - standard function, not non-stop

Directions

  • FWD - forwards movement, gets replaced with 1 on compilation
  • BWD - forwards movement, gets replaced with -1 on compilation

Speed constants

  • FIX_SPEED - angle correction rotation speed after NS_FIN or NS_STD function
  • MIN_SPEED - minimum rotation speed
  • STEERING_MOD - modifies the aggressiveness of steering when following lines

Line following modifiers (lf_mod)

  • LBRW - black line on the left, white line on the right
  • LWRB - white line on the left, black line on the right

Functions

Dependent on base

void moveTimed(base b, int speed, double duration, pid *ctl, int direction, int fn_type);
  • moves robot for duration seconds with PID control
  • Parameters:
    • base b - base object
    • int speed - maximum speed
    • double duration - movement duration in seconds
    • pid *ctl - a pointer to a pid object (if PID object is named foo, use &foo as parameter)
    • int direction - FWD for forwards movement, BWD for backwards movement
    • int fn_type - see Function types
void moveColor(base b, int speed, color cs, double value, double delta, pid *ctl, int direction, int fn_type);
  • moves robot until a color of a value within delta is reached
  • Parameters:
    • base b - base object
    • int speed - maximum speed
    • color cs - color sensor object
    • double value - a grey scale value in % (~0% - black, ~100% - white)
    • double delta - an allowed difference between sensor reading and value in %
    • pid *ctl - a pointer to a pid object (if PID object is named foo, use &foo as parameter)
    • int direction - FWD for forwards movement, BWD for backwards movement
    • int fn_type - see Function types
void moveLine(base b, int speed, color cs_f, color cs_s, double value, double delta, int course, int lf_mod, int direction, int fn_type);
  • moves robot until a color of a value within delta is reached, following a line
  • Parameters:
    • base b - base object
    • int speed - maximum speed
    • color cs_f - color sensor object for line following
    • color cs_s - color sensor object for function interruption
    • double value - a grey scale value in % (~0% - black, ~100% - white)
    • double delta - an allowed difference between sensor reading and value in %
    • int course - the final orientation of the robot
    • int lf_mod - see Line following modifiers
    • int direction - FWD for forwards movement, BWD for backwards movement
    • int fn_type - see Function types
void rotate(base b, int target, int speed);
  • rotates the robot around its own axis
  • Parameters:
    • base b - base object
    • int target - target angle
    • int speed - maximum speed

Independent of base

int modSpeed(double target, double angle, double speed);
  • returns speed for rotation function based on the difference of the target angle and (current) angle
  • Parameters:
    • double target - target angle
    • double angle - current angle
    • double speed - maximum speed
Clone this wiki locally