The approach you have followed to send the PWM values sounds correct to me. Make sure that you are not held up by unnecessary tasks by commenting them out in the stabilizer.c. And also make sure that the stabilizer.c runs at 1000Hz (RATE_MAIN_LOOP RATE_1000_HZ). However, did you take the maximum logging frequency into the consideration? As far as I could remember logging cannot be done beyond a certain max frequency. Secondly, if you calculate the PWM values offboard, is it really required to send set points/state variables to the drone?
Basically, what I did there was; adding a new 4 variables for the setpoint type and setting the motor values to those 4 variables by decoding the incoming CRTP message in the crtpCommanderGenericDecodeSetpoint().
Code: Select all
void crtpCommanderGenericDecodeSetpoint(setpoint_t *setpoint, CRTPPacket *pk) {
static int nTypes = -1;
ASSERT(pk->size > 0);
if (nTypes < 0) {
nTypes = sizeof(packetDecoders) / sizeof(packetDecoders[0]);
}
const void *data1 = ((char *) pk->data);
const struct geometricPacket_s *values = data1;
size = pk->size;
m1 = values->m1;
m2 = values->m2;
m3 = values->m3;
m4 = values->m4;
setpoint->m1 = m1;
setpoint->m2 = m2;
setpoint->m3 = m3;
setpoint->m4 = m4;
}
Code: Select all
while (1) {
vTaskDelayUntil(&lastWakeTime, F2T(RATE_MAIN_LOOP));
getExtPosition(&state);
stateEstimator(&state, &sensorData, &control, tick);
commanderGetSetpoint(&setpoint, &state);
motorsSetRatio(MOTOR_M1,setpoint.m1);
motorsSetRatio(MOTOR_M2,setpoint.m2);
motorsSetRatio(MOTOR_M3,setpoint.m3);
motorsSetRatio(MOTOR_M4,setpoint.m4);
checkEmergencyStopTimeout();
if (emergencyStop) {
powerStop();
} else {
powerDistribution(&control, &setpoint);
}
tick++;
}