constantly set outputs for ramp, otherwise the ESC doesn't keep it's setting (why?)

This commit is contained in:
Andreas Antener
2016-06-20 20:24:46 +02:00
parent ede032c557
commit d8cdb2032c
+15 -13
View File
@@ -201,32 +201,30 @@ int set_out(int fd, unsigned long max_channels, float output)
int prepare(int fd, unsigned long *max_channels) int prepare(int fd, unsigned long *max_channels)
{ {
int ret;
/* get number of channels available on the device */ /* get number of channels available on the device */
ret = ioctl(fd, PWM_SERVO_GET_COUNT, (unsigned long)max_channels); if (px4_ioctl(fd, PWM_SERVO_GET_COUNT, (unsigned long)max_channels) != OK) {
if (ret != OK) {
PX4_ERR("[motor_ramp] PWM_SERVO_GET_COUNT"); PX4_ERR("[motor_ramp] PWM_SERVO_GET_COUNT");
return 1; return 1;
} }
/* tell IO/FMU that its ok to disable its safety with the switch */ /* tell IO/FMU that its ok to disable its safety with the switch */
ret = ioctl(fd, PWM_SERVO_SET_ARM_OK, 0); if (px4_ioctl(fd, PWM_SERVO_SET_ARM_OK, 0) != OK) {
if (ret != OK) {
PX4_ERR("[motor_ramp] PWM_SERVO_SET_ARM_OK"); PX4_ERR("[motor_ramp] PWM_SERVO_SET_ARM_OK");
return 1; return 1;
} }
/* tell IO/FMU that the system is armed (it will output values if safety is off) */ /* tell IO/FMU that the system is armed (it will output values if safety is off) */
ret = ioctl(fd, PWM_SERVO_ARM, 0); if (px4_ioctl(fd, PWM_SERVO_ARM, 0) != OK) {
if (ret != OK) {
PX4_ERR("[motor_ramp] PWM_SERVO_ARM"); PX4_ERR("[motor_ramp] PWM_SERVO_ARM");
return 1; return 1;
} }
/* tell IO to switch off safety without using the safety switch */
if (px4_ioctl(fd, PWM_SERVO_SET_FORCE_SAFETY_OFF, 0) != OK) {
PX4_ERR("[motor_ramp] PWM_SERVO_SET_FORCE_SAFETY_OFF");
return 1;
}
return 0; return 0;
} }
@@ -282,11 +280,12 @@ int motor_ramp_thread_main(int argc, char *argv[])
case RAMP_MIN: { case RAMP_MIN: {
if (timer > 3.0f) { if (timer > 3.0f) {
PX4_WARN("[motor_ramp] min set, starting ramp"); PX4_WARN("[motor_ramp] starting ramp");
start = hrt_absolute_time(); start = hrt_absolute_time();
ramp_state = RAMP_RAMP; ramp_state = RAMP_RAMP;
} }
set_out(fd, max_channels, output);
break; break;
} }
@@ -310,6 +309,7 @@ int motor_ramp_thread_main(int argc, char *argv[])
break; break;
} }
set_out(fd, max_channels, output);
break; break;
} }
} }
@@ -319,7 +319,9 @@ int motor_ramp_thread_main(int argc, char *argv[])
} }
if (fd >= 0) { if (fd >= 0) {
set_out(fd, max_channels, 0.0f); /* disarm */
ioctl(fd, PWM_SERVO_DISARM, 0);
px4_close(fd); px4_close(fd);
} }