Go Down

Topic: How to control Servo motor precisely above 180° ? [Solved] (Read 289 times) previous topic - next topic

zerhorace

Hi there !

I am currently using a  Servo PDI-6225MG-300 which can rotate up to 295° I send(through Wi fi) a value between 0 to 295 which is the value of the angle (value called val).

Code: [Select]
#include <Servo.h>

#include <SPI.h>

#include <RF24.h>
#include <RF24_config.h>
int msg[1];
int val = 0;
RF24 radio(5, 10);
const uint64_t pipe = 0xE9E9F0F0E1LL;
Servo myservo;

void setup() {

  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  Serial.begin(9600);
  myservo.attach(9);

}

void loop() {
  
  if (radio.available()) {          
    bool done = false;              
    while (!done) {
      done = radio.read(msg, 2);
      val = msg[0];
      val = map(val, 0, 295, 0, 180);
      Serial.println(msg[0]);
      myservo.write(val);
      
      }
      myservo.write(val);
      
    }
  }




But I have a big problem, I can't really control it precisely. He is achieving the 295° rotation when the value reach 180 so I tried to "map" the value but it doesnt work.

Is it possible to control it percisely ?
Is it because of the Servo Library which can only control between 0 to 180° ?
What am I doing wrong ?

Ps: spec of the servo

Brand Name: JX Servo
Item Name: PDI-6225MG-300 Degree
Max Angle: 295°
Dead Band: 4μs
Maximum Pulse Width: 500-2500us (for control board)
Motor: Iron core
Voltage range: 4.8V-6.6V
Speed (4.8V): 0.25 sec / 60 degree
Speed (6V): 0.21 sec / 60 degree
Torque (4.8V): 19.9 kg.cm
Torque (6V): 25.3 kg.cm
Size: 40.5 x 20.2 x 38mm
Weight: 62g
Cable: JR 265 mm
Bearing: 2BB
Output Teeth: 25T (Futaba Universal)


Thx in advance !

Seb

vinceherman

#1
Jul 30, 2018, 05:01 pm Last Edit: Jul 30, 2018, 05:03 pm by vinceherman
I tried to "map" the value but it doesnt work.
What doesn't work?  What did you expect it to do and how does the actual result differ from that expectation?

Edit - Hit CTRL-T to autoformat your code.  It makes it easier to read and understand.
Also, consider using writeMicroseconds() instead of write() any time you are concerned about accuracy.
write simply maps the 0-180 parameter to the microseconds value and passes that in to writeMicroseconds.

zerhorace

#2
Jul 30, 2018, 05:06 pm Last Edit: Jul 30, 2018, 05:08 pm by zerhorace
Hi, what do not work is that it is still not precise.

Edit, sorry for my bad code presentation :( ok i'll try it but i'm not sure to understand. Should I transform the value in micro second ?

vinceherman

Hi, what do not work is that it is still not precise.
I am going to ask you to describe this better.
What about its behavior makes you think that it is not precise?

And, yes, I would switch to writeMicroseconds.  It should be easy.  You just need to know the microsecond range that the attach used.  Since you used the single parameter attach method, it used the default min and max of 544 and 2400.

I *think* that only 2 lines need to change.
Your map should be like this:
Code: [Select]
val = map(val, 0, 295, 544, 2400);
and your servo.write should change to:
Code: [Select]
myservo.writeMicroseconds(val);

zerhorace

It Worked ! Thank you !

You totally understood the problem, now it's very precise ! I'm really sorry for the bother.

Have a nice day !

Thank you !

Go Up