-
Notifications
You must be signed in to change notification settings - Fork 0
/
Remote_Control_Go_Cart.ino
42 lines (30 loc) · 1.44 KB
/
Remote_Control_Go_Cart.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <AccelStepper.h>
const int gasPulse = 1, gasDir = 2;
const int brakePulse = 3, brakeDir = 4;
const int steerPulse = 5, steerDir = 6;
AccelStepper gasStepper(AccelStepper::DRIVER, gasPulse, gasDir);
AccelStepper brakeStepper(AccelStepper::DRIVER, brakePulse, brakeDir);
AccelStepper steerStepper(AccelStepper::DRIVER, steerPulse, steerDir);
const float pedalMaxSpeed = 300, pedalAcceleration = 100;
const float steerMaxSpeed = 500, steerAcceleration = 200;
const long pedalMinPos = 0, pedalMaxPos = 100;
const long steerMinPos = -100, steerMaxPos = 100;
long minInput = 0.0, maxInput = 1.0;
long rawGasInput = 0, rawBrakeInput = 0, rawSteerInput = 0;
void setup() {
gasStepper.setMaxSpeed(pedalMaxSpeed);
brakeStepper.setMaxSpeed(pedalMaxSpeed);
gasStepper.setAcceleration(pedalAcceleration);
brakeStepper.setAcceleration(pedalAcceleration);
steerStepper.setMaxSpeed(steerMaxSpeed);
steerStepper.setAcceleration(pedalAcceleration);
}
void loop() {
// insert processing to get inputs
gasStepper.moveTo(scaleStepperInputs(rawGasInput, pedalMinPos, pedalMaxPos));
brakeStepper.moveTo(scaleStepperInputs(rawBrakeInput, pedalMinPos, pedalMaxPos));
steerStepper.moveTo(scaleStepperInputs(rawSteerInput, steerMinPos, steerMaxPos));
}
long scaleStepperInputs(long stepperInput, long stepperMinPos, long stepperMaxPos) {
return constrain(map(stepperInput, minInput, maxInput, stepperMinPos, stepperMaxPos), stepperMinPos, stepperMaxPos);
}