Get current motor position with Adafruit PWM Servo Driver Library

I'm currently using the Adafruit PWM Servo Driver Library to move my stepper motor. Works great.

Using a joystick, I can move the motor to the left and the right slowly by subtracting or adding a value to the setPWM function.

However, in order for this to work, I need to start from a known value, a 0-based point, which I set during the execution of my program.

The problem is this makes the motor move TOO fast to the 0 point. The motor drives some gears, and they cannot cope with this ultra-fast movement.

Is there either a way to make the motor move slower, or to get the current position of the motor (so that I can step back to the 0 position myself)?

which I set during the execution of my program.

I can’t see a program.

wimpie3:
I'm currently using the Adafruit PWM Servo Driver Library to move my stepper motor. Works great.

Using a joystick, I can move the motor to the left and the right slowly by subtracting or adding a value to the setPWM function.

However, in order for this to work, I need to start from a known value, a 0-based point, which I set during the execution of my program.

The problem is this makes the motor move TOO fast to the 0 point. The motor drives some gears, and they cannot cope with this ultra-fast movement.

Is there either a way to make the motor move slower, or to get the current position of the motor (so that I can step back to the 0 position myself)?

I've read your post several times and I still don't understand what sort of motors you're using. You're using a "Servo Driver Library" to control your stepper motor?

I think it would be very helpful if you posted links to the hardware and software you're using.

As suggested by AWOL, it would also be helpful if you added the code you are presently using.

The board I’m using is this one: https://www.adafruit.com/products/815

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(0x42);

int leftMinJoystickMotor = 220;
int rightMaxJoystickMotor = 470;
int joystickPosition = (leftMinJoystickMotor + rightMaxJoystickMotor) /2;
int prevJoystickPosition = joystickPosition;
int extensionBoardPinJoystickMotor = 12;
int pinJoystickLeft = 6;
int pinJoystickRight = 7;

void setup() {

pwm3.begin();
pwm3.setPWMFreq(60);
pwm3.setPWM(extensionBoardPinJoystickMotor,0,joystickPosition); // reset joystick to middle

pinMode(pinJoystickLeft, INPUT);
pinMode(pinJoystickRight, INPUT);
}

void loop() {
delay(4);
if (digitalRead(pinJoystickLeft) == HIGH) {
joystickPosition=joystickPosition-1;
}
if (digitalRead(pinJoystickRight) == HIGH) {
joystickPosition=joystickPosition+1;
}
if (joystickPosition < leftMinJoystickMotor) {joystickPosition=leftMinJoystickMotor;}
if (joystickPosition > rightMaxJoystickMotor) {joystickPosition=rightMaxJoystickMotor;}
if (prevJoystickPosition != joystickPosition) {
pwm3.setPWM(extensionBoardPinJoystickMotor,0,joystickPosition);
prevJoystickPosition = joystickPosition;
}
}

Hi,
Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks… Tom… :slight_smile:

It's not entirely clear what motors you are using but I'm extrapolating from the information provided that you're using radio-control type servos.

You cannot find out from the servo what position it's in. It will go towards your commanded position as fast as it can. Normally you don't need to know or care what position it's in when the power's off and when it's on, then it should be in the commanded position.

It may be possible, depending on your mechanics, to add another position sensor for feedback and write your own startup routine to take care of that but that's a lot of work.

The best solution is to make sure the servos are in a known position at power-off.

MorganS:
It’s not entirely clear what motors you are using but I’m extrapolating from the information provided that you’re using radio-control type servos.

It’s starting to look that way.

DuaneDegn:
I think it would be very helpful if you posted links to the hardware and software you’re using.

The above request included a request for a link to the motors you’re using. You’ve repeatedly called your motors “steppers” but you appear to be using code and hardware to control hobby servos.

Is there a reason you don’t want to control your servos directly?

I know I keep linking to these videos but I’m pleased with how well the servos behave if their speed is ramped up and back down. Servos don’t have to thrash about.

The same acceleration/deceleration algorithm could be adapted for use with the AdaFruit controller.

MorganS:
The best solution is to make sure the servos are in a known position at power-off.

And make sure the first command given to the servo is to move to this known position.

You can also reduce the violence of starting up servos is each servo is brought online one at a time. If a servo hasn’t received a pulse, it generally doesn’t move.

Sorry for not being clear: I am indeed using a RC servo motor.

The solution in the last post could be a good alternative: storing the current motor position "somewhere" and slowly turn back from this value to 0 when the Arduino boots.

or to get the current position of the motor (so that I can step back to the 0 position myself)?

You can go inside the servo and tap off of the pot wiper to measure the current voltage, then map to a corresponding servo command value.