Raw Potentiometer Continuous Readings using Python

Hi,

I’ve a linear servo motor with a linear potentiometer attached to the channel 10 on 24 channel maestro servo controller. The potentiometer is connected to the channel 0. I intend to move the servo motor from min to max position and plot the raw potentiometer data being transmitted on channel 0 against time.
Language in use : Python.

Code:

import maestro
import time
servo = maestro.Controller()
servo.setSpeed(10, 0) # I want to measure the data at speed =0
servo.setAccel(10, 0) # I want to measure the data at acceleration =0
servo.setTarget(10, 3968) # min postion in microseconds
pos_data = []
servo.setTarget(10, 8000)# max position in microseconds
while servo.isMoving(10): #want to write a method to check whether the servo is still moving
    pos_data.append(servo.get_read_position(0))

print pos_data

#method : servo.get_read_position()

def get_read_position(self, channel):
    command = self.PololuCmd + chr(0x90) + chr(channel)
    self.usb.write(command)
    lsb = ord(self.usb.read())
    msb = ord(self.usb.read())
    read_position = (256 * msb) + lsb
    return read_position

#method: servo.isMoving()
#not sure how to implement this method.

Currently I’m not able to read a complete continuous analog data through channel 0. using the method getPosition doesn’t give me the correct value for channel 0. Could anyone help me with implementing the task ?

Hello.

For the benefit of others reading this thread, I want to let them know that you are using the Python module, maestro.py, and that getPosition is a method of maestro.py that you tried using. (For those who do not know already, the Python module is linked under the “Related Resources” section of the Maestro User’s Guide.)

I looked at your code briefly and it looks like your Get Position command is wrong. self.PololuCmd is set to \xaa\x0c in the class constructor (__init__), which are the starting bytes of the Pololu command. The next byte of the command object after self.PololuCmd should be \x10 not \x90. I strongly recommend looking at the maestro.py source code, in particular getPosition and isMoving, to get a better understanding of how each function works. However, I suspect that the problem is due to your Maestro settings not being configured properly, not your code, which might explain why the Maestro isn’t responding to the commands defined in the maestro.py.

Can you post your Maestro settings file here? (You can save your Maestro settings file by selecting the “Save settings file…” option within the “File” drop-down menu of the Maestro Control Center.) Also, when you move your linear potentiometer connected to Channel 0, does the green/blue dot on the slider bar for Channel 0 move? If not, can you post pictures clearly showing how you have it connected to the Maestro?

- Amanda

Hi Amanda,

Apologies for the late reply. As you had suggested, I found the problem with the GetPosition Methods which I had tried to implement on my own. I replaced the method with the maestro.py methods and it started working fine.

Many thanks for your help.

Regards,
Prabhakar.