Go Down

### Topic: controlling motors like CNC (Read 1 time)previous topic - next topic

#### JoseArg

##### Feb 04, 2018, 12:44 am
I have three servos, let's say M1, M2, and M3. I desire to write functions to move motors like this

Code: [Select]

void loop(){
clockwise (M1,65,2);//65 is in degree and 2 corresponds to r.p.m.
clockwise (M1,120,4);
counterclockwise(M1,22,2);
stop(M1);
//... etc
}

I mean, in the first place, M1 rotates 65º at 2r.p.m., when it reaches that position, M1 moves another 120º at r.p.m., after that M1 turns back 22º ...etc, you know how it works in CNC code, I want to do something similar. Can you advise me how can I get this?. Thanks.

#### Johan_Ha

#1
##### Feb 04, 2018, 08:08 am
What will M2 and M3 do in the meantime? Can they rotate or can only one motor rotate at a time?
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

#### slipstick

#2
##### Feb 04, 2018, 10:14 am
RPM and degrees moved don't really mix for me. Wouldn't it be easier to say how long you want it to take to move in seconds?

Not that you can do either of those with normal servos because they have angle control but no speed control.

Steve

#### Johan_Ha

#3
##### Feb 04, 2018, 02:40 pm
And what does stop(M1) do in your code? Something that the previous line doesn't do already?

What servos do you have? 120 + 65 = 185. Most servos can hardly move 180 degrees. But as long as you stay inside the sector that your servo can operate in, what you want is possible. Though it's a very unconventional way to program servos.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

#### JoseArg

#4
##### Feb 04, 2018, 05:39 pm
@Johan_Ha, yes, the other two motors will be controlled separately with Arduino in multithread program, using Metro or similar. So M1, M2 and M3 can rotate simultaneously.
Stop(M1) is easy in fact:

void Stop(Servo M){
M.detach();
}

#### JoseArg

#5
##### Feb 04, 2018, 05:47 pm
@slipstick conversion angular velocity to time in seconds is easy:

t = angle/agular vel.;  angle in radians and angular velocity in rpm x (2pi/60)

#### Johan_Ha

#6
##### Feb 04, 2018, 06:11 pm
Search for servo speed control to learn how to adjust the speed of the servo. My guess is (I don't bother to check, sorry for that) that the speed control servo libs still want absolute angles, and not relative angles. If you insist on using relative angles - like "turn 20 degrees ccw" instead of "turn to position 130 degrees" - you need to save each new position of the servo so you can convert your relative turns into absolute angle commands. I'd hide everything into a class.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

#### slipstick

#7
##### Feb 04, 2018, 10:27 pm
@slipstick conversion angular velocity to time in seconds is easy:

t = angle/agular vel.;  angle in radians and angular velocity in rpm x (2pi/60)
O.k. it's your requirement but since servos don't do relative angles and they don't do rpm I can't see the point.

But good luck anyway.

Steve

#### PaulS

#8
##### Feb 05, 2018, 04:50 pm
Quote
O.k. it's your requirement but since servos don't do relative angles and they don't do rpm I can't see the point.
If they are continuous rotation servos, they don't do absolute angles, either.

OP: You REALLY want to be using the proper motors. CNC machines use stepper motors.

#### slipstick

#9
##### Feb 05, 2018, 05:57 pm
If they are continuous rotation servos, they don't do absolute angles, either.
If they are continuous rotation they aren't servos, they're motors.

It's all in the terminology, isn't it?

Steve

#### Johan_Ha

#10
##### Feb 05, 2018, 08:27 pm
We haven't been confirmed that they are/aren't continuous servos. A normal servo that turns inside a 180 degree sector can be speed controlled. rpm is a bit stupid as a unit, but as JoseArg wrote, conversions are easy.

Side discussion:
The servo terminology discussion is eternal. I think a continuous servo is such a handy little thing that it deserves a good name. I'd like to call it continuous servo instead of anything else, like geared-dc-motor-with-integrated-speed-and-direction-control-unit-thing. The bad thing with calling it continuous servo is that newbies tend to think it can be set to any angle.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Go Up