void
SmartDrive::Run_Seconds(int motor_id, int direction, uint8_t speed, uint8_t duration, bool wait_for_completion, int next_action ) {
uint8_t ctrl = 0;
ctrl |= SmartDrive_CONTROL_SPEED;
ctrl |= SmartDrive_CONTROL_TIME;
if ( next_action ==SmartDrive_Action_Brake )
ctrl |= SmartDrive_CONTROL_BRK;
if ( next_action ==SmartDrive_Action_BrakeHold ) {
ctrl |= SmartDrive_CONTROL_BRK;
ctrl |= SmartDrive_CONTROL_ON;
}
if ( motor_id != SmartDrive_Motor_ID_BOTH )
ctrl |= SmartDrive_CONTROL_GO;
if ( direction != SmartDrive_Dir_Forward )
speed = speed * -1;
if ( motor_id != SmartDrive_Motor_ID_2) {
uint8_t array[5] = {SmartDrive_SPEED_M1, speed, duration, 0, ctrl};
writeArray(array, sizeof(array));
}
if ( motor_id != SmartDrive_Motor_ID_1) {
uint8_t array[5] = {SmartDrive_SPEED_M2, speed, duration, 0, ctrl};
writeArray(array, sizeof(array));
}
if ( motor_id == SmartDrive_Motor_ID_BOTH )
writeByte(SmartDrive_COMMAND, CMD_S);
if ( wait_for_completion ) {
sleep(1); //this delay is required for the status byte to be available for reading.
WaitUntilTimeDone(motor_id);
}
}