reading position of servo from servo controller
SIMECorp
Posts: 4
anyone been able to read the position of the servo using the uart object talking to the servo controller?
I have tried a few methods, below is my snipet try with one uart and switching directions. Also tried 2 uarts
I always get bogus data
··········· // read servo position
··········· // send command to serial controller to get position
··········· servoController.sendString("!SCRSP");
··········· servoController.sendByte(servoCh);
··········· servoController.sendByte(0x0D);
··········· while (!servoController.sendBufferEmpty())
··········· {
············· // wait till all output is done
··········· }
··········· // CPU.delay(1500);
··········· servoController.setDirection(Uart.dirReceive);
··········· //·get current position
··········· getChannel = servoController.receiveByte();
··········· c1 = servoController.receiveByte();
··········· c2 = servoController.receiveByte();
··········· actualPosition = c1 + (c2<<8);
··········· System.out.println("Servo.finished(): position="+actualPosition);
··········· // return to output
··········· servoController.setDirection(Uart.dirTransmit);
the servo controller is initalizzed with
········· servoController = new Uart(Uart.dirTransmit,
······························· SER_TXRX_PIN,
······························· Uart.dontInvert,
······························· Uart.speed2400,
······························· Uart.stop1);
thanks...
alan
I have tried a few methods, below is my snipet try with one uart and switching directions. Also tried 2 uarts
I always get bogus data
··········· // read servo position
··········· // send command to serial controller to get position
··········· servoController.sendString("!SCRSP");
··········· servoController.sendByte(servoCh);
··········· servoController.sendByte(0x0D);
··········· while (!servoController.sendBufferEmpty())
··········· {
············· // wait till all output is done
··········· }
··········· // CPU.delay(1500);
··········· servoController.setDirection(Uart.dirReceive);
··········· //·get current position
··········· getChannel = servoController.receiveByte();
··········· c1 = servoController.receiveByte();
··········· c2 = servoController.receiveByte();
··········· actualPosition = c1 + (c2<<8);
··········· System.out.println("Servo.finished(): position="+actualPosition);
··········· // return to output
··········· servoController.setDirection(Uart.dirTransmit);
the servo controller is initalizzed with
········· servoController = new Uart(Uart.dirTransmit,
······························· SER_TXRX_PIN,
······························· Uart.dontInvert,
······························· Uart.speed2400,
······························· Uart.stop1);
thanks...
alan