You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you clone/download this repository you get version 2.0.0-DEV, which is BLEEDING EDGE - not flight tested at all, might not even compile, and will completely change in the next hour...
19
+
20
+
Use [release version 1.3.3](https://github.com/qqqlab/madflight/releases) if you want something that actually has logged flight hours.
@@ -44,10 +50,10 @@ The source code and [website](https://madflight.com/) have extensive documentati
44
50
3. Open *Examples for custom libraries->madflight->Quadcopter.ino* in the Arduino IDE.
45
51
4. Edit the HARDWARE section in madflight_config.h to enable the connected peripherals.
46
52
5. If you're not using the default pinout then setup your board pinout in the CUSTOM PINS section.
47
-
6. Compile Quadcopter.ino and upload it to your board. Connect the Serial Monitor at 115200 baud and check the messages. Type `help` to see the available CLI commands.
53
+
6. Compile Quadcopter.ino and upload it to your board. Connect the Serial Monitor at 115200 baud and check the startup messages. Type `help` to see the available CLI commands.
48
54
7. Type `calradio` and follow the prompts to setup your RC radio receiver.
49
55
8. IMPORTANT: Use CLI `calimu` and `calmag` to calibate the sensors.
50
-
9. Use CLI commands `pimu`, `pahrs`, `pradio`, `pmot`, etc. and check that IMU sensor, AHRS and RC Receiver are working correctly.
56
+
9. Use CLI commands `pimu`, `pahr`, `prcl`, `pmot`, etc. and check that IMU sensor, AHRS and RC Receiver are working correctly.
51
57
10. Connect motors (no props) and battery and check that motors are spinning correctly.
52
58
11. Mount props, go to an wide open space, and FLY!
53
59
@@ -88,7 +94,7 @@ By default **madflight** has these safety features enabled:
88
94
-`rcin` RC INput, retrieves RC receiver data
89
95
-`veh` Vehicle information
90
96
- Most modules are interfaced through a global object, for example the `imu` object has property `imu.gx` which is the current gyro x-axis rate in degrees per second for the selected IMU chip.
91
-
- The module implementations are in subdirectories of the `src/madflight` directory. Here you find the module header file, e.g. `src/madflight/imu/imu.h`, and the interface declaration `src/madflight/imu/imu_interface.h`
97
+
- The module implementations are in subdirectories of the `src/madflight` directory. Here you find the module header file, e.g. `src/madflight/imu/imu.h`, and the interface declaration `src/madflight/imu/imu.h`
92
98
- The module files are usually header only, that is, the header also includes the implemention.
or for I2C IMU: connect pin_imu_int, pin_i2c1_scl, pin_i2c1_sda
19
+
RC receiver: connect pin_ser0_rx to receiver TX pin
20
+
ESCs: pin_out0 ... pin_out3 to the ESC inputs of motor1 ... motor4
18
21
19
22
Arming: Set throttle low, then flip arm switch from DISARMED to ARMED.
20
23
Disarming: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
@@ -80,23 +83,26 @@ void setup() {
80
83
//setup madflight components: Serial.begin(115200), imu, rcin, led, etc. See src/madflight/interface.h for full interface description of each component.
81
84
madflight_setup();
82
85
83
-
//setup 4 motors for the quadcopter
84
-
for(int i=0;i<4;i++) {
85
-
//uncomment one line - sets pin, frequency (Hz), minimum (us), maximum (us)
86
-
out.setupMotor(i, HW_PIN_OUT[i], 400, 950, 2000); //Standard PWM: 400Hz, 950-2000 us
87
-
//out.setupMotor(i, (HW_PIN_OUT[i], 2000, 125, 250); //Oneshot125: 2000Hz, 125-250 us
88
-
}
86
+
// Uncomment ONE line - select output type
87
+
int out_hz = 400; int min_us = 950; int max_us = 2000; //Standard PWM: 400Hz, 950-2000 us
88
+
//int out_hz = 2000; int min_us = 125; int max_us = 250; //Oneshot125: 2000Hz, 125-250 us
//Sensor fusion: update ahrs.roll, ahrs.pitch, and ahrs.yaw angle estimates (degrees) from IMU data
112
-
ahrs.update();
117
+
//Sensor fusion: update ahr.roll, ahr.pitch, and ahr.yaw angle estimates (degrees) from IMU data
118
+
ahr.update();
113
119
114
120
//Get radio commands - Note: don't do this in loop() because loop() is a lower priority task than imu_loop(), so in worst case loop() will not get any processor time.
115
-
rcin.update();
121
+
rcl.update();
116
122
117
123
//PID Controller RATE or ANGLE
118
124
#ifdef FLIGHTMODE_ANGLE
119
-
control_Angle(rcin.throttle == 0); //Stabilize on pitch/roll angle setpoint, stabilize yaw on rate setpoint //control_Angle2(rcin_thro_is_low); //Stabilize on pitch/roll setpoint using cascaded method. Rate controller must be tuned well first!
125
+
control_Angle(rcl.throttle == 0); //Stabilize on pitch/roll angle setpoint, stabilize yaw on rate setpoint //control_Angle2(rcin_thro_is_low); //Stabilize on pitch/roll setpoint using cascaded method. Rate controller must be tuned well first!
120
126
#else
121
-
control_Rate(rcin.throttle == 0); //Stabilize on rate setpoint
127
+
control_Rate(rcl.throttle == 0); //Stabilize on rate setpoint
PIDroll.PID = 0.01 * (Kp_ro_pi_angle*error_roll + Ki_ro_pi_angle*integral_roll - Kd_ro_pi_angle*derivative_roll); //Scaled by .01 to bring within -1 to 1 range
PIDpitch.PID = 0.01 * (Kp_ro_pi_angle*error_pitch + Ki_ro_pi_angle*integral_pitch - Kd_ro_pi_angle*derivative_pitch); //Scaled by .01 to bring within -1 to 1 range
PIDroll.PID = 0.01 * (Kp_ro_pi_rate*error_roll + Ki_ro_pi_rate*integral_roll + Kd_ro_pi_rate*derivative_roll); //Scaled by .01 to bring within -1 to 1 range
PIDpitch.PID = 0.01 * (Kp_ro_pi_rate*error_pitch + Ki_ro_pi_rate*integral_pitch + Kd_ro_pi_rate*derivative_pitch); //Scaled by .01 to bring within -1 to 1 range
*rcin.roll, rcin.pitch, rcin.yaw - direct unstabilized command passthrough
318
+
*rcl.roll, rcl.pitch, rcl.yaw - direct unstabilized command passthrough
318
319
*/
319
320
/*
320
321
Motor order diagram (Betaflight order)
@@ -336,7 +337,7 @@ Yaw right (CCW+ CW-) -++-
336
337
337
338
// IMPORTANT: This is a safety feature to remind the pilot to disarm.
338
339
// Set throttle to at least armed_min_throttle, to keep at least one prop spinning when armed. The [out] module will disable motors when out.armed == false
339
-
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcin.throttle; //shift throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
340
+
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcl.throttle; //shift throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
340
341
341
342
//Quad mixing
342
343
out.set(0, thr - PIDpitch.PID - PIDroll.PID - PIDyaw.PID); //M1 Back Right CW
0 commit comments