void motorsSendValues(void) { int i; for (i = 0; i < MOTORS_NUM; i++) if (motorsData.active[i]) { // ensure motor output is constrained motorsData.value[i] = constrainInt(motorsData.value[i], 0, MOTORS_SCALE); // PWM if (i < PWM_NUM_PORTS && motorsData.pwm[i]) { if (supervisorData.state & STATE_ARMED) *motorsData.pwm[i]->ccr = constrainInt((float)motorsData.value[i] * (p[MOT_MAX] - p[MOT_MIN]) / MOTORS_SCALE + p[MOT_MIN], p[MOT_START], p[MOT_MAX]); else *motorsData.pwm[i]->ccr = 0; } // CAN else if (motorsData.can[i]) { motorsCheckCanStatus(i); if (supervisorData.state & STATE_ARMED) // convert to 16 bit *motorsData.canPtrs[i] = constrainInt(motorsData.value[i], MOTORS_SCALE * 0.1f, MOTORS_SCALE)<<4; else *motorsData.canPtrs[i] = 0; } } motorsCanSendGroups(); }
void motorsOff(void) { int i; for (int j = 0; j < motorsData.numActive; ++j) { i = motorsData.activeList[j]; motorsData.value[i] = 0; // PWM if (i < PWM_NUM_PORTS && motorsData.pwm[i]) { #ifdef HAS_ONBOARD_ESC if (MOTORS_ESC_TYPE == ESC_TYPE_ONBOARD_PWM) *motorsData.pwm[i]->ccr = (supervisorData.state & STATE_ARMED) ? ONBOARD_ESC_PWM_ARM : 0; else #endif *motorsData.pwm[i]->ccr = (supervisorData.state & STATE_ARMED) ? p[MOT_ARM] : 0; } // CAN else if (motorsData.can[i]) { motorsCheckCanStatus(i); *motorsData.canPtrs[i] = 0; } } motorsCanSendGroups(); motorsData.throttle = 0; motorsData.throttleLimiter = 0.0f; }
void motorsOff(void) { int i; for (i = 0; i < MOTORS_NUM; i++) if (motorsData.active[i]) { motorsData.value[i] = 0; // PWM if (i < PWM_NUM_PORTS && motorsData.pwm[i]) { //*motorsData.pwm[i]->ccr = (supervisorData.state & STATE_ARMED) ? p[MOT_ARM] : 0; *motorsData.pwm[i]->ccr = p[MOT_ARM]; } #ifdef CANx // CAN else if (motorsData.can[i]) { motorsCheckCanStatus(i); *motorsData.canPtrs[i] = 0; } #endif } #ifdef CANx motorsCanSendGroups(); #endif motorsData.throttle = 0; motorsData.throttleLimiter = 0.0f; }
void motorsSendValues(void) { int i; for (int j = 0; j < motorsData.numActive; ++j) { i = motorsData.activeList[j]; // ensure motor output is constrained motorsData.value[i] = constrainInt(motorsData.value[i], 0, MOTORS_SCALE); // PWM if (i < PWM_NUM_PORTS && motorsData.pwm[i]) { if (supervisorData.state & STATE_ARMED) { #ifdef HAS_ONBOARD_ESC if (MOTORS_ESC_TYPE == ESC_TYPE_ONBOARD_PWM) *motorsData.pwm[i]->ccr = constrainInt((float)motorsData.value[i] * (ONBOARD_ESC_PWM_MAX - ONBOARD_ESC_PWM_MIN) / MOTORS_SCALE + ONBOARD_ESC_PWM_MIN, ONBOARD_ESC_PWM_START, ONBOARD_ESC_PWM_MAX); else #endif *motorsData.pwm[i]->ccr = constrainInt((float)motorsData.value[i] * (p[MOT_MAX] - p[MOT_MIN]) / MOTORS_SCALE + p[MOT_MIN], p[MOT_START], p[MOT_MAX]); } else *motorsData.pwm[i]->ccr = 0; } // CAN else if (motorsData.can[i]) { motorsCheckCanStatus(i); if (supervisorData.state & STATE_ARMED) // convert to 16 bit *motorsData.canPtrs[i] = constrainInt(motorsData.value[i], MOTORS_SCALE * 0.1f, MOTORS_SCALE)<<4; else *motorsData.canPtrs[i] = 0; } } motorsCanSendGroups(); }