-
Notifications
You must be signed in to change notification settings - Fork 7
Motor
Bidirectional motor control interface for direct, user-driven motor management.
Caution: Driving motors directly bypasses the flight controller's stabilization. Test with props off.
Rotation direction, used by Motor_SetDir().
typedef enum motor_direction {
CLOCK_WISE = 0, // Clockwise rotation
ANTICLOCK_WISE // Counter-clockwise rotation
} motor_direction_e;Selects the motor for the Motor_* functions.
typedef enum bidirectional_motor {
M1, // Motor 1
M2, // Motor 2
M5, // Motor 5
M6, // Motor 6
M7, // Motor 7
M8 // Motor 8
} bidirectional_motor_e;Two motor groups behave differently:
- M1, M2 - bidirectional motors. Require
Motor_Init(), supportMotor_SetDir(), and are driven directly byMotor_Set().- M5 - M8 - the regular flight motors.
Motor_Init()/Motor_SetDir()have no effect on them;Motor_Set()only takes effect while the drone is disarmed (it writes the disarmed motor value), which setsusingMotorAPI.
-
bool usingMotorAPI- Set when the motor API is in use (the firmware checks this to release motor control to user code).
Initializes a motor for direct control. Do this once at startup.
void plutoInit ( void ) {
Motor_Init ( M1 );
Motor_Init ( M2 );
}Sets a motor's rotation direction. Set it once before driving the motor.
void onLoopStart ( void ) {
Motor_SetDir ( M1, CLOCK_WISE );
Motor_SetDir ( M2, ANTICLOCK_WISE );
}Sets a motor's speed. pwmValue is constrained to 1000 - 2000 (1000 = stopped,
2000 = full speed). Direction is controlled separately by Motor_SetDir(), not by
the sign of this value. Drive motors from plutoLoop().
void plutoLoop ( void ) {
Motor_Set ( M1, 1500 ); // ~half speed
Motor_Set ( M2, 2000 ); // full speed
}Initialize at startup, set directions on entry, drive in the loop, stop on exit.
#include "PlutoPilot.h"
// Power-up: initialize the bidirectional motors.
void plutoInit ( void ) {
Motor_Init ( M1 );
Motor_Init ( M2 );
}
// Dev button pressed: set rotation directions once.
void onLoopStart ( void ) {
Motor_SetDir ( M1, CLOCK_WISE );
Motor_SetDir ( M2, ANTICLOCK_WISE );
}
// While active: drive the motors (1000 = stop, 2000 = full).
void plutoLoop ( void ) {
Motor_Set ( M1, 1500 );
Motor_Set ( M2, 1500 );
}
// Dev button released: stop the motors.
void onLoopFinish ( void ) {
Motor_Set ( M1, 1000 );
Motor_Set ( M2, 1000 );
}No Motor_Init() or Motor_SetDir() is needed for these. Motor_Set() only
takes effect while the drone is disarmed, so this is for props-off bench
testing of the four flight motors.
#include "PlutoPilot.h"
// While active (and disarmed): spin each flight motor at low speed.
void plutoLoop ( void ) {
Motor_Set ( M5, 1200 );
Motor_Set ( M6, 1200 );
Motor_Set ( M7, 1200 );
Motor_Set ( M8, 1200 );
}
// Dev button released: stop all flight motors.
void onLoopFinish ( void ) {
Motor_Set ( M5, 1000 );
Motor_Set ( M6, 1000 );
Motor_Set ( M7, 1000 );
Motor_Set ( M8, 1000 );
}MagisV2 © 2026 Drona Aviation | Licensed under GPL-3.0 | Report Issues