Page 1 of 1

setTargetPosition Variable Speeds

Posted: Wed Mar 01, 2023 1:20 pm
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!

Re: setTargetPosition Variable Speeds

Posted: Wed Mar 01, 2023 2:42 pm
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.

Re: setTargetPosition Variable Speeds

Posted: Mon Jul 03, 2023 1:59 am
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

Re: setTargetPosition Variable Speeds

Posted: Tue Jul 04, 2023 8:01 am
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)