SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
AeroServo.cpp
Go to the documentation of this file.
1
11//@cond
12
13#include "AeroServo.h"
14#include "Log.h"
15#include "PWMServo.h" // Servo.h is reliant on quick interrupts, switch (and test) if PWMServo is not good enough
16
17namespace Aero {
18
19static const LOG_TAG ID = "AeroServo";
20
21// TODO: check that these values are okay
22static const int steerLMin = PINS_VOLT_TO_ANALOG(1.5);
23static const int steerLMax = PINS_VOLT_TO_ANALOG(0);
24static const int steerRMin = PINS_VOLT_TO_ANALOG(3.5);
25static const int steerRMax = PINS_VOLT_TO_ANALOG(5);
26
27static const int angleMin = 30; // 30 is min possible servo angle, 180 is max
28static const int angleMax = 72; // angle of attack is 42
29static const int lerpConst = 50;
30
31static PWMServo servo1;
32static PWMServo servo2;
33
34static int servoVal = angleMin * lerpConst;
35
36void setup() {
37 Log.i(ID, "Initializing Aero servo pins");
38 servo1.attach(PINS_BACK_SERVO1_PWM);
39 servo2.attach(PINS_BACK_SERVO2_PWM);
40 Log.i(ID, "Turning on servos");
41 Pins::setPinValue(PINS_BACK_SERVO_OFF, 0);
42 Log.i(ID, "Done");
43}
44
45int getServoValue() {
46 return servoVal / lerpConst;
47}
48
49void run(int breakPressure, int steeringAngle) { // Add 10 millisec delay
50 // Brake pressure
51 int breakPos = map(breakPressure, PINS_ANALOG_MIN, PINS_ANALOG_MAX, angleMin, angleMax);
52
53 // Steering angle sensor
54 int steerPos = 0;
55
56 if (steeringAngle <= steerLMin) {
57 steerPos = map(steeringAngle, steerLMax, steerLMin, angleMax, angleMin);
58 } else if (steeringAngle >= steerRMin) {
59 steerPos = map(steeringAngle, steerRMin, steerRMax, angleMin, angleMax);
60 }
61
62 servoVal += max(breakPos, steerPos) - (servoVal / lerpConst);
63
64 servo1.write(servoVal / lerpConst);
65 servo2.write(servoVal / lerpConst);
66}
67
68} // namespace Aero
69 //@endcond
Interpretation of Aero subteam code.
Special logging functionality.
const char * LOG_TAG
Type definition of logging tags This typedef is necessary to allow for easier manipulation of code by...
Definition Log.h:48
Logging::Log_t Log
The global logging object.
#define PINS_ANALOG_MIN
The minimum analog value. Its zero, I think it will always be zero. Not sure why i needed this.
Definition Pins.h:71
#define PINS_ANALOG_MAX
The maximum analog value, given the current PINS_ANALOG_RES.
Definition Pins.h:63
#define PINS_VOLT_TO_ANALOG(x)
Maps Voltages 0-5v to an appropriate analog value.
Definition Pins.h:76
Module used for aero calculations.
Definition AeroServo.h:29
void run(int breakPressure, int steeringAngle)
Run Aero servo logic, given raw values.
void setup(void)
Attach analog pins to their servo objects.
int getServoValue()
Get the current servo position value.
void setPinValue(uint8_t GPIO_Pin, int value)
Set the pin value of a predefined pin.
void i(LOG_TAG TAG, LOG_MSG message)
Log a string using an info tag.