summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/main.cpp b/main.cpp
index 72c0389..d3c14b3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -57,11 +57,12 @@ int main() {
RCC.enable(RCC.IOPA);
RCC.enable(RCC.IOPB);
- GPIOA.CRL = 0x4434bbbb;
+ GPIOA.CRL = 0x4444bbbb;
GPIOA.CRH = 0x444444b4;
- GPIOA.ODR = 1 << 5;
- GPIOB.CRH = 0x4444ff44;
+ GPIOB.CRL = 0xff444434;
+ GPIOB.CRH = 0x44444444;
+ GPIOB.ODR = 1 << 1;
I2C i2c;
i2c.enable();
@@ -81,9 +82,9 @@ int main() {
TIM2.CR1 = 0x05;
- PID pid_pitch(3000, 0, 0);
- PID pid_roll(3000, 0, 0);
- PID pid_yaw(2000, 0, 0);
+ PID pid_pitch(6000, 0, 0);
+ PID pid_roll(6000, 0, 0);
+ PID pid_yaw(6000, 0, 0);
while(1) {
// Wait for a new update.
@@ -97,9 +98,9 @@ int main() {
// Generate motor mix.
int16_t throttle = ppmsum.channels[2] - 1000;
- int16_t pitch = pid_pitch.update((ppmsum.channels[1] - 1500) * 3 - gyro.x);
- int16_t roll = pid_roll.update((ppmsum.channels[0] - 1500) * 3 - gyro.y);
- int16_t yaw = pid_yaw.update((ppmsum.channels[3] - 1500) * 5 - gyro.z);
+ int16_t pitch = pid_pitch.update((ppmsum.channels[1] - 1500) * 1 - gyro.x);
+ int16_t roll = pid_roll.update((ppmsum.channels[0] - 1500) * 1 - gyro.y);
+ int16_t yaw = pid_yaw.update((ppmsum.channels[3] - 1500) * -1 - gyro.z);
int16_t max = throttle > 250 ? 250 : throttle;
saturate(pitch, max);
@@ -107,10 +108,10 @@ int main() {
saturate(yaw, max);
int cmds[] = {
- 1000 + throttle + pitch + roll + yaw,
- 1000 + throttle + pitch - roll - yaw,
- 1000 + throttle - pitch + roll - yaw,
- 1000 + throttle - pitch - roll + yaw,
+ 1000 + throttle + pitch - roll + yaw,
+ 1000 + throttle - pitch - roll - yaw,
+ 1000 + throttle - pitch + roll + yaw,
+ 1000 + throttle + pitch + roll - yaw,
};
TIM2.CCR1 = limit(cmds[0], 1000, 2000);