setTargetPosition Variable Speeds

Supporting 2.7 and 3.2+
Saylerjen73
Fresh meat
Posts: 2
Joined: Wed Nov 30, 2022 5:52 pm

setTargetPosition Variable Speeds

Post by Saylerjen73 »

Hi!

I'm using the setTargetPosition() to control two different motors. I was wondering how to change velocity and acceleration for these movements, and if the motors can have different speeds.

Thanks!
You do not have the required permissions to view the files attached to this post.
User avatar
mparadis
Site Admin
Posts: 679
Joined: Fri Oct 28, 2011 12:17 pm

Re: setTargetPosition Variable Speeds

Post by mparadis »

Yes, you can have different speeds and velocities set for each stepper channel. You can see our API for a full list of available properties to set. For example,

Code: Select all

stepper1.setAcceleration(10000)
stepper2.setAcceleration(5000)

stepper1.setVelocityLimit(10000)
stepper1.setVelocityLimit(15000)
Note that "Velocity limit" is not the same as actual velocity. If you set the velocity limit to 10000, it means the controller will send out motor step pulses such that it should go no faster than 10,000 sixteenth-steps per second. This means it may go slower than that if something is physically working against the motor. For actual velocity control, you'd need to monitor the physical position of the motor with an encoder and make a control loop.
Raphisfa
Phidgetsian
Posts: 5
Joined: Mon May 22, 2023 2:55 am

Re: setTargetPosition Variable Speeds

Post by Raphisfa »

Hi, when I am in ControlMode 1 how do i affect the direction of moving. I read at the API Page that I have to work with minVelocity/maxvelocity but I don't know how to implement that correctly?

Thanks, Raphi :D
fraser
Engineering
Posts: 139
Joined: Thu Nov 19, 2009 4:41 pm

Re: setTargetPosition Variable Speeds

Post by fraser »

In ControlMode 1, you only need to set "VelocityLimit" to control your speed and direction. MinVelocityLimit and MaxVelocityLimit are constants, and in control mode 1 they will be fixed to specific values.

To control direction, you will set VelocityLimit to a positive number for one direction, and a negative number for the opposite direction of rotation.

For example...
stepper1.setVelocityLimit(10000)
stepper2.setVelocityLimit(-10000)