Arduino Servo Motor Controlling

Hi Everyone,

I am working on a project which includes 3 Servo Motors. The motor model is "POWER HD LF-20MG". It is R/C type of motor.

I am controlling the motors with Arduino by using external power supply. Let me give you a few specifications of the motor :

  • Motors' Torque : @4.8V -16kg-cm : @6.6V -20kg-cm.
  • Stall Current : nearly 2.7 A at the highest load applied on it.

The project is about a Delta Robot, also known as Parallel Delta Robot. There is kinematic equations in order to find the angles, in this case 3 angles exist, correspondig to the given loactions/coordinates, x,y,z.
I wrote an Arduino library to calculate these equations to find the angles. I am done here without any trouble.
However, since the arms of the robot are always in motion, the loads on the motors are also always changing. (This is a section what I am in a bit trouble to control.)

I am using a C# - Arduino communication to give the locations by user. This was a user-friendly approach for me. (In fact, it is not necessary, but it looks like pretty well :slight_smile: )

So, I have a few question about controlling, communicating and interfacing :

1-) I am just using "servo.writeMicroseconds()" function to give the values to the motors. I am considering to use PID control in order to overcome the vibration issue, since the arms are always in motion up and down, as I explained above.
Is this a correct approach ?
Or should I use "interrupts" ?
What will be the effect of using "interrupts" ?

2-) I can manage to send the data for just one motor from C# to Arduino. However, how can I send multiple data ? (I was using "Serial.readUntil()" function. So, I could send just one data from C# to Arduino)

3*) Is there a way to sending and reading data at the same time ? Or at least with a little time delay interval ?

These are my questions. I hope, I could be clear as well as possible.

Thanks in advanced.
Regards.

Hi,
I am not sure what you are asking but do you have a situation where your servo's vibrate or jitter?
How big is your power supply, as you state 2.7A stall ,so you will need a supply that is at least 10A.
Even when a servo is stationary, if there is load on the servo, it will continue to draw current.

Have you got the power supply wire heavy enough to carry those currents?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a picture of your project, showing your wiring and component layout please?

You do have the gnd of the Arduino connected to the gnd of the servo power supply?

Try this link for Serial Comms

Thanks.. Tom.. :slight_smile:

Is your mechanical structure stiff enough or is it causing the vibration?

If you send large steps using servo.writeMicroseconds() the servo will try to jump to the new position, so you can get smoother movements using a ramp or smoothing function, but it will slow your movements. It's always a trade off. PID control requires feedback. I don't know how that would work in your system. I also don't understand what using interrupts would do.

Not sure what your problem is sending serial data. Why can't you send a longer serial message with all three servo commands in one string? Alternatively you can send each motor command and the Arduino saves the data but doesn't write to the servos until it receives a message telling it to "update now" so all three servos are updated simultaneously.

TomGeorge:
Hi,
I am not sure what you are asking but do you have a situation where your servo’s vibrate or jitter?
How big is your power supply, as you state 2.7A stall ,so you will need a supply that is at least 10A.
Even when a servo is stationary, if there is load on the servo, it will continue to draw current.

Have you got the power supply wire heavy enough to carry those currents?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a picture of your project, showing your wiring and component layout please?

You do have the gnd of the Arduino connected to the gnd of the servo power supply?

Try this link for Serial Comms

http://forum.arduino.cc/index.php?topic=396450

Thanks… Tom… :slight_smile:

Hi,
Firstly, thanks for your response. I attached the circuit diagram to below. As you can see in the figure, the gnd of the motors and the Arduino are common.

I used two power supply. The reason of that is one of the power supply carries upto 5A.

Now, I haven’t implemented a controller, which is neither with software nor electrical, yet. This may be the reason of vibration. However, there shouldn’t be vibration. The motors can carry upto 20 kg/cm. In my robot, the maximum load 400~500gr. on 35cm. So, I think, I can’t use the motors efficiently.

Thanks again…

sdturner:
Is your mechanical structure stiff enough or is it causing the vibration?

If you send large steps using servo.writeMicroseconds() the servo will try to jump to the new position, so you can get smoother movements using a ramp or smoothing function, but it will slow your movements. It's always a trade off. PID control requires feedback. I don't know how that would work in your system. I also don't understand what using interrupts would do.

Not sure what your problem is sending serial data. Why can't you send a longer serial message with all three servo commands in one string? Alternatively you can send each motor command and the Arduino saves the data but doesn't write to the servos until it receives a message telling it to "update now" so all three servos are updated simultaneously.

Thanks for your response. I just explained what my mechanical structure stiff is, on previous post. Honestly, I think, I cant use the servo motors efficiently. This may be caused by using them without a PID controller.

For "interrupts", there are people who control the motors with interrupts, but I haven't got a clue how to use the interrupts. In fact, I don't know what solution I will get by using interrupt. I couldn't understand the background of that.

For communication, thanks for the advice. I think, it will work.

Thanks again..

Hi,
Can your post your code that you are using please.

Tom... :slight_smile:

TomGeorge:
Hi,
Can your post your code that you are using please.

Tom… :slight_smile:

Hi,
Here it is :slight_smile:

#include <DeltaRobot.h>  /// This is the library that I wrote.
#include <Servo.h>
int i = 0;

int angle1;
int angle2;
int angle3;
String x,y,z;

int val_x,val_y,val_z;

DeltaRobot robot(400,500,112.5,75); /// These are the constant coefficients such as upper arm length etc.

Servo motor1;  
Servo motor2;
Servo motor3;


void setup() {
  motor1.attach(9);
  motor2.attach(10);
  motor3.attach(11);
  Serial.begin(9600);
}

void loop() {
    if(Serial.available()>0)
    {
        x=Serial.readStringUntil(',');  /// These x,y and z values are coming from C# as a string.
        val_x = x.toInt();              /// Converting them to integer.
        y=Serial.readStringUntil(';');
        val_y = y.toInt();
        z=Serial.readStringUntil(':');
        val_z = z.toInt();
        
        robot.InitialCoordinates(val_x,val_y,val_z);  /// This is a function from the library. This put the desirable coordinates into the library.
        angle1 = robot.CalculateAngle_1();            /// After defining the coordinates, "CalculateAngle_1()" function calculates the angle1 for motor1.
        angle2 = robot.CalculateAngle_2();            /// It is the same progress for angle2 for motor2.
        angle3 = robot.CalculateAngle_3();            /// Again, it will calculate for angle3 for motor3.
        motor1.writeMicroseconds(544 + 10.31*angle1); /// Since the this function works between 544~2400 by default ...
        motor2.writeMicroseconds(544 + 10.31*angle2); /// ... I calculate the angle interval as 10.31. For example, 10 degree corresponds to 544 + 10.31*10.
        motor3.writeMicroseconds(544 + 10.31*angle3); 
    }
}

I did not have implement the PID Controller ,yet.
Thanks in advance :slight_smile:

Hi,
Sorry but we don't have a copy of your library.

Can you write a simple bit of code, that doesn't use your library or serial, that just sets the three servos at a fixed angle each?
This is to check if the problem is in your hardware.

In your code above please put some serial.print in to show what you are outputting to the the servos.

Thanks.. Tom.. :slight_smile:

TomGeorge:
Can you write a simple bit of code, that doesn't use your library or serial, that just sets the three servos at a fixed angle each?
This is to check if the problem is in your hardware.

Hi,
In basic servo code which is included within Arduino, Servo Sweep or Servo Knob, I can handle that. There is no problem. The angles are fixed. However, I think, making a controller which controls the position is not an efficient idea for Servo motors, since they handle these within itself. I am already supplying the motors with constant value, which is 6.6V, so, the velocity control is not required. This is also my opinion.

TomGeorge:
In your code above please put some serial.print in to show what you are outputting to the the servos.

In the code above, "serial.print" function does not work, since at the beginning, Arduino starts to communicate with C#. As I said the previous posts, the motor specifications are quite appropriate for the mechanical parameters.

Thanks. :slight_smile:

Hi,
Thanks for the reply, but have you written code for ALL 3servos at once, not just a single servo to check hardware?

We need to see your library you wrote please.

Thanks.. Tom... :slight_smile: