Juggler Position Control Parsing
Dependencies: MODSERIAL mbed Servo
Fork of juggler_mbed_position_control by
Diff: main.cpp
- Revision:
- 5:2c84869b2edb
- Parent:
- 4:a3720ed072d2
- Child:
- 6:75d01138b015
--- a/main.cpp Mon Jan 16 02:46:37 2017 +0000 +++ b/main.cpp Mon Jan 16 03:47:11 2017 +0000 @@ -13,15 +13,16 @@ MODSERIAL pcSerial(USBTX, USBRX); // Initialize a pins t//o perform analog and digital output fucntions -AnalogOut aout(p18); PwmOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); +DigitalOut led4(LED4); PwmOut motorPwm(p26); AnalogOut motorAna(p18); DigitalOut motorEnable(p12); Ticker aTimer; +AnalogIn motorSpeed(p15); AnalogIn potentiometer(p20); DigitalIn potentiometerEnable(p21); @@ -41,19 +42,20 @@ int main(void) { // DEFINE the operation modes - bool messageMode = false; + bool messageMode = true; bool analogMode = true; led1 = 0.0f; led2 = 0; led3 = 0; + led4 = 0; motorEnable = 0; // turn off motor motorAna.write_u16(POWER_OFF); // set motor pwm to zero - motorPwm.period_us(200); + motorPwm.period_us(400); motorPwm = 0.5f; uint16_t motorCommandReceived = POWER_OFF; uint16_t motorCommand = POWER_OFF; - uint16_t motorPositionMeas = POWER_OFF; + uint16_t motorSpeedMeas = POWER_OFF; float motorCommandFloat = 0.5f; pcSerial.baud(115200); pcSerial.printf("Start!\n"); @@ -77,8 +79,8 @@ motorAna.write_u16(motorCommandReceived); } else { //PWM motorCommandFloat = ((float) motorCommandReceived)/ 65535.0f; - motorPwm.write( motorCommandFloat * 0.79f + 0.105f); - led1 = motorCommandFloat; // drive led1 brightness accordingly + motorPwm.write( motorCommandFloat * 0.8f + 0.1f); + //led1 = motorCommandFloat; // drive led1 brightness accordingly } } else { //potentiometer controlled motorCommand = potentiometer.read_u16(); @@ -86,8 +88,8 @@ motorAna.write_u16(motorCommand); } else { //PWM motorCommandFloat = ((float) motorCommand) / 65535.0f; - motorPwm.write( motorCommandFloat * 0.79f + 0.105f); - led1 = motorCommandFloat; // drive led1 brightness accordingly + motorPwm.write( motorCommandFloat * 0.8f + 0.1f); + //led1 = motorCommandFloat; // drive led1 brightness accordingly } } @@ -95,9 +97,14 @@ } if(readyToSendNext == true) { - motorPositionMeas = motorCommandReceived; - serialComm.sendUnsignedShort(motorPositionMeas); + // reading in current speed + motorSpeedMeas = motorSpeed.read_u16(); + //sending speed to host + serialComm.sendUnsignedShort(motorSpeedMeas); + led4 = !led4; + readyToSendNext = false; + } }