# Coding problem with motor speed and position data

I hv a robot car with 2 wheels. It can run along the x-axis. The MCU can get the instant x-axis data. Can any one give me some idea to program the following motion performance? The current control method is that when I click the button once and then move from point to point with constant speed.

Constant speed ? So you want it to accelerate from a stop to that speed instantaneously ? That's going to be tricky.

But give us details of the robot car/motors/motor drivers/button/wiring etc. and show us the code you have so far and we'll see what we can do.

Steve

2-W1ND: and then move from point to point with constant speed.

Your diagram very clearly shows varying speed - unless you have some very sophisticated system that can change the RPM without changing the speed.

...R

slipstick: Constant speed ? So you want it to accelerate from a stop to that speed instantaneously ? That's going to be tricky.

But give us details of the robot car/motors/motor drivers/button/wiring etc. and show us the code you have so far and we'll see what we can do.

Steve

No, I want the car to accelerate when it is starting from x0 slowly and decelerate when it is approaching x1. In the middle part, I want it keeps constants speed. Since I want to reduce inertia effect on the car when it start to run or stop.

The car can get Cartesian coordinate (x-asix) feedback (mm unit) from encoder to MCU. What I want to know is that how to use this feedback to generate the speed value. I will put this value on my function which control the speed of the motor.

Sorry, I can't provide more detail now for some reasons.

Robin2: Your diagram very clearly shows varying speed - unless you have some very sophisticated system that can change the RPM without changing the speed.

...R

Sorry for the bad explanation. I mean that I can control the car move from point to point with constant motor speed but I don't want it is constant.

The car can get Cartesian coordinate (x-asix) feedback (mm unit) from encoder to MCU. I think my question should be how to write the algorithm to generate the speed value, and then put this value on my function which control the speed of the motor.

2-W1ND: The car can get Cartesian coordinate (x-asix) feedback (mm unit) from encoder to MCU. I think my question should be how to write the algorithm to generate the speed value, and then put this value on my function which control the speed of the motor.

I think you are saying (and please correct me if I am wrong) ...

The Arduino will be counting the encoder pulses and at any moment the number of pulses represents the distance traveled.

And as the distance changes you want to change the speed (RPM of the motor).

That should (in general) be perfectly possible but you have not told us how you will be measuring the speed or how you want the speed to vary as the distance varies.

I think you may find it useful to study the code in the AccelStepper library because a key part of that library is to smoothly accelerate and decelerate a stepper motor though a specified number of steps.

And what do you mean, in Reply #3, by "I can't provide more detail now for some reasons" I hope you are not looking for free advice for a commercial project just so you can make profit at our expense.

...R

Robin2: I think you are saying (and please correct me if I am wrong) ...

The Arduino will be counting the encoder pulses and at any moment the number of pulses represents the distance traveled.

And as the distance changes you want to change the speed (RPM of the motor).

That should (in general) be perfectly possible but you have not told us how you will be measuring the speed or how you want the speed to vary as the distance varies.

I think you may find it useful to study the code in the AccelStepper library because a key part of that library is to smoothly accelerate and decelerate a stepper motor though a specified number of steps.

And what do you mean, in Reply #3, by "I can't provide more detail now for some reasons" I hope you are not looking for free advice for a commercial project just so you can make profit at our expense.

...R

Thank you! I will study AccelStepper library. And it's student project rather than a commercial project :)