mirror of
https://github.com/peter-tanner/des-car-2022.git
synced 2024-11-30 03:50:15 +08:00
Peter
e65b30830e
http://github.com/Alphurious007/DES. Copy of the `peterus` branch which has my code. Original was adapted from MoBot but I have added many changes and replaced many parts so it is almost completely different.
64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
|
|
#include <Arduino.h>
|
|
#include <inttypes.h>
|
|
#include "util.h"
|
|
#include "parameters.h"
|
|
|
|
typedef enum driving_direction
|
|
{
|
|
FORWARD,
|
|
STOP,
|
|
} DRIVING_DIRECTION;
|
|
|
|
typedef enum steering_direction
|
|
{
|
|
RIGHT,
|
|
STRAIGHT,
|
|
LEFT,
|
|
} STEERING_DIRECTION;
|
|
|
|
// *(10 ms)
|
|
#define STEERING_DURATION 25
|
|
#define DRIVE_DURATION 200
|
|
#define STOP_DURATION 0
|
|
|
|
#define INITIALIZE_DRIVE() \
|
|
pinMode(WHEEL_L_F, OUTPUT); \
|
|
pinMode(WHEEL_L_B, OUTPUT); \
|
|
pinMode(WHEEL_R_F, OUTPUT); \
|
|
pinMode(WHEEL_R_B, OUTPUT); \
|
|
diff_drive(STOP, STRAIGHT);
|
|
|
|
inline void diff_drive(DRIVING_DIRECTION drive, STEERING_DIRECTION steer)
|
|
{
|
|
if (drive == STOP)
|
|
{
|
|
digitalWrite(WHEEL_L_F, LOW);
|
|
digitalWrite(WHEEL_L_B, LOW);
|
|
digitalWrite(WHEEL_R_F, LOW);
|
|
digitalWrite(WHEEL_R_B, LOW);
|
|
return;
|
|
}
|
|
|
|
switch (steer)
|
|
{
|
|
case LEFT:
|
|
digitalWrite(WHEEL_L_F, HIGH);
|
|
digitalWrite(WHEEL_L_B, LOW);
|
|
digitalWrite(WHEEL_R_F, LOW);
|
|
digitalWrite(WHEEL_R_B, HIGH);
|
|
return;
|
|
case RIGHT:
|
|
digitalWrite(WHEEL_L_F, LOW);
|
|
digitalWrite(WHEEL_L_B, HIGH);
|
|
digitalWrite(WHEEL_R_F, HIGH);
|
|
digitalWrite(WHEEL_R_B, LOW);
|
|
return;
|
|
case STRAIGHT:
|
|
digitalWrite(WHEEL_L_F, LOW);
|
|
digitalWrite(WHEEL_L_B, HIGH);
|
|
digitalWrite(WHEEL_R_F, LOW);
|
|
digitalWrite(WHEEL_R_B, HIGH);
|
|
return;
|
|
}
|
|
} |