SSLSimRobot::SSLSimRobot(const ros::NodeHandle& n) : nh(n) { first_command_arrived = false; motors.push_back(getServo("wheel1")); motors.push_back(getServo("wheel2")); motors.push_back(getServo("wheel3")); motors.push_back(getServo("wheel4")); for(unsigned int i=0;i<motors.size();i++) motors[i]->enablePosition(TIME_STEP); sub_motor_commands = nh.subscribe("motor_command", 1000, &SSLSimRobot::actuationCommandCallback, this); }
void LogEntry::print() { Serial.print("P: "); Serial.print(getPressure()); Serial.print(" T: "); Serial.print(getTemperature()); Serial.print(" B: "); Serial.print(getBattery()); Serial.print(" S: "); Serial.println(getServo(), DEC); }
int main (void) { uint8_t i = 0; uint8_t j = 0; char read = 0; char command[COMMAND_LENGTH]; uint8_t commandPosition = 0; uint8_t checksum = 0; for (i = 0; i < SERVO_COUNT; i++) { servopos[i] = 100; } sei(); servo_init(); ioinit(); while (1) { read = uart_getchar(); command[commandPosition] = read; checksum += read; if (read == 0) { if (checksum == 0) { // Handle command switch (command[0]) { case 0x01: setServo(command[1], command[2]); break; case 0x02: getServo(command[1]); break; } } else { // Command error uart_putchar(0xFF); } checksum = 0; commandPosition = 0; } else { commandPosition++; } } return 0; }
void deviceServoHandleRawData(unsigned char commandHeader, InputStream* inputStream, OutputStream* outputStream, OutputStream* notificationOutputStream) { // WRITE COMMANDS if (commandHeader == SERVO_COMMAND_WRITE) { ServoList* servoList = getServoDeviceServoList(); unsigned int servoIndex = readHex2(inputStream); checkIsSeparator(inputStream); unsigned int servoSpeed = readHex2(inputStream); checkIsSeparator(inputStream); unsigned int servoValue = readHex4(inputStream); if (servoIndex == SERVO_ALL_INDEX) { pwmServoAll(servoList, servoSpeed, servoValue); } else { Servo* servo = getServo(servoList, servoIndex); pwmServo(servo, servoSpeed, servoValue, false); } ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_WRITE); } else if (commandHeader == SERVO_COMMAND_WRITE_MAX_SPEED_UNDER_LOAD) { ServoList* servoList = getServoDeviceServoList(); unsigned int servoIndex = readHex2(inputStream); checkIsSeparator(inputStream); int servoMaxSpeedUnderLoad = readHex2(inputStream); Servo* servo = getServo(servoList, servoIndex); servo->maxSpeedUnderLoad = servoMaxSpeedUnderLoad; ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_WRITE_MAX_SPEED_UNDER_LOAD); } else if (commandHeader == SERVO_COMMAND_WRITE_COMPACT) { unsigned int servoValue = readHex4(inputStream); ServoList* servoList = getServoDeviceServoList(); pwmServoAll(servoList, PWM_SERVO_SPEED_MAX, servoValue); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_WRITE_COMPACT); } // ENABLE / DISABLE if (commandHeader == SERVO_COMMAND_WRITE_ENABLE_DISABLE) { ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_WRITE_ENABLE_DISABLE); ServoList* servoList = getServoDeviceServoList(); unsigned int servoIndex = readHex2(inputStream); checkIsSeparator(inputStream); bool enabled = readBool(inputStream); if (servoIndex == SERVO_ALL_INDEX) { servoEnableAll(servoList, enabled); } else { Servo* servo = getServo(servoList, servoIndex); pwmServoSetEnabled(servo, enabled); } } else if (commandHeader == SERVO_COMMAND_ENABLE_DISABLE_ALL) { ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_ENABLE_DISABLE_ALL); ServoList* servoList = getServoDeviceServoList(); bool enabled = readBool(inputStream); servoEnableAll(servoList, enabled); } // READ COMMANDS else if (commandHeader == SERVO_COMMAND_GET_COUNT) { ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_GET_COUNT); ServoList* servoList = getServoDeviceServoList(); unsigned int servoCount = getServoCount(servoList); appendHex2(outputStream, servoCount); } else if (commandHeader == SERVO_COMMAND_READ) { ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_READ); unsigned int servoIndex = readHex2(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); unsigned int speed = pwmServoReadTargetSpeed(servo); unsigned int currentPosition = pwmServoReadCurrentPosition(servo); unsigned int targetPosition = pwmServoReadTargetPosition(servo); appendHex2(outputStream, servoIndex); appendSeparator(outputStream); appendHex2(outputStream, speed); appendSeparator(outputStream); appendHex4(outputStream, currentPosition); appendSeparator(outputStream); appendHex4(outputStream, targetPosition); } else if (commandHeader == SERVO_COMMAND_READ_SPEED) { unsigned int servoIndex = readHex2(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); unsigned int speed = pwmServoReadTargetSpeed(servo); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_READ_SPEED); appendHex2(outputStream, speed); } else if (commandHeader == SERVO_COMMAND_READ_MAX_SPEED_UNDER_LOAD) { unsigned int servoIndex = readHex2(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); unsigned int maxSpeedUnderLoad = pwmServoReadMaxSpeedUnderLoad(servo); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_READ_MAX_SPEED_UNDER_LOAD); appendHex2(outputStream, maxSpeedUnderLoad); } else if (commandHeader == SERVO_COMMAND_READ_CURRENT_POSITION) { unsigned int servoIndex = readHex2(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); int currentPosition = pwmServoReadCurrentPosition(servo); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_READ_CURRENT_POSITION); appendHex4(outputStream, currentPosition); } else if (commandHeader == SERVO_COMMAND_READ_TARGET_POSITION) { unsigned int servoIndex = readHex2(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); int targetPosition = pwmServoReadTargetPosition(servo); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_READ_TARGET_POSITION); appendHex4(outputStream, targetPosition); } // DEBUG COMMANDS else if (commandHeader == SERVO_COMMAND_TEST) { ServoList* servoList = getServoDeviceServoList(); testAllPwmServos(servoList); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_TEST); } else if (commandHeader == SERVO_COMMAND_GET_TIME_TO_REACH_UNDER_LOAD) { unsigned int servoIndex = readHex2(inputStream); checkIsSeparator(inputStream); unsigned int servoTargetPosition = readHex4(inputStream); ServoList* servoList = getServoDeviceServoList(); Servo* servo = getServo(servoList, servoIndex); unsigned int timeToReachUnderLoad = pwmServoComputeTimeMilliSecondsToReachTargetPosition(servo, servoTargetPosition); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_GET_TIME_TO_REACH_UNDER_LOAD); appendHex4(outputStream, timeToReachUnderLoad); } else if (commandHeader == SERVO_COMMAND_DEBUG) { ServoList* servoList = getServoDeviceServoList(); printServoList(getInfoOutputStreamLogger(), servoList); ackCommand(outputStream, SERVO_DEVICE_HEADER, SERVO_COMMAND_DEBUG); } }