Two Servos gimbaling in a circle (X and Y Servo)

Hi Everyone,

Any advise on how to get an X axis servo and Y axis servo to move in a circle.

The Application - Building a gimbaling system for an EDF. I want to test the gimbals range of motion. I am expecting for it to be able to move 20 degrees on either axis. I want the gimbal to move the motor in a circle as part of the start up sequence to ensure there is nothing restricting the motors movement and that will also indicate the servos are calibrated properly (It will also look cool which is a completely sufficient reason for this level of over complication). I've got as for as using for loops to move it diagonally back and forth. And a basic system.

#include <Arduino.h>
#include <ESP32Servo.H>


Servo XAxis;
Servo YAxis;

int posx = 90;
int posy = 90;

void Start_Sequence() {
  XAxis.write(90);
  YAxis.write(90);

  Serial.println("Centre");

  delay(500);

  Serial.println("Begin X Axis Test");

  XAxis.write(110);
  delay(500);
  XAxis.write(90);
  delay(500);
  XAxis.write(90);
  delay(500);

  Serial.println("X Axis Test Complete");

  delay(500);

  Serial.println("Begin Y Axis Test");

  YAxis.write(110);
  delay(500);
  YAxis.write(90);
  delay(500);
  YAxis.write(90);
  delay(500);

  Serial.println("Y Axis Test Complete");
}

void setup() {

  Serial.begin(115200);


  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  ESP32PWM::allocateTimer(2);
  ESP32PWM::allocateTimer(3);

  XAxis.setPeriodHertz(50);
  YAxis.setPeriodHertz(50);

  XAxis.attach(32, 500, 2400);
  YAxis.attach(33, 500, 2400);

  XAxis.write(90);
  YAxis.write(90);

  Start_Sequence();

}

void loop() {

for (posx = 70, posy = 110; posx <= 110, posy >= 70; posx += 1, posy -= 1){
  XAxis.write(posx);
  YAxis.write(posy);
  delay(20);
}
for (posx = 110, posy = 70; posx >= 70, posy <= 110; posx -= 1, posy += 1){
  XAxis.write(posx);
  YAxis.write(posy);
  delay(20);
}

}

Any tips are welcome.

Thanks in advance

What is an EDF ? (I only know it as the initials for Electricte de France)

...R

I suspect its something to do with a ducted fan.

for (posx = 70, posy = 110; posx <= 110, posy >= 70; posx += 1, posy -= 1){

Whoops!

Perhaps you meant:

for (posx = 70, posy = 110; posx <= 110 && posy >= 70; posx += 1, posy -= 1){

or the much clearer and easily comprehensible:

for (int i = 0 ; i <= 40 ; i++)
{
  int posx = 70+i ;
  int posy = 110-i ;
  ....
}

MarkT:
I suspect its something to do with a ducted fan.

Thats right, EDF = Electronic Ducted Fan (A motor in tube basically). The motor itself is not of particular importance, the main idea I wish to pursue is moving two servos positioned to control X and Y axis to move in a circular motion

MarkT:

for (int i = 0 ; i <= 40 ; i++)

{
 int posx = 70+i ;
 int posy = 110-i ;
 ....
}

Thanks for that, quite right that is far more comprehensible. I've incorperated this as shown below

for (int i = 0 ; i <= 40 ; i++)
{
  int posx = 70+i ;
  XAxis.write(posx);
  int posy = 110-i ;
  YAxis.write(posy);
  delay(15);
}

I've used that format and made it a cycle through a few variations of this. Has worked successfully and I have managed to get it sweep in multiple directions and travel in diagonals etc. but still no luck with gambling in a circle. Is the a complexed mathematic equation somewhere I can implement or a library or anything...?

Is the a complexed mathematic equation somewhere I can implement or a library or anything...?

You mean Sinus and Cosinus ?

Or Pythagoras

amanbasra:
Thats right, EDF = Electronic Ducted Fan (A motor in tube basically). The motor itself is not of particular importance, the main idea I wish to pursue is moving two servos positioned to control X and Y axis to move in a circular motion

It would be a big help if you explain the role of the servos in relation to the ducted fan. I know what a ducted fan is but I can't envisage what the servos are going to move in a circle.

A diagram of your proposed machine would be great.

...R

The ducted fan is in the centre of 2 rings. One ring holds a servo which is connected to the edf, that controls the X axis. The outer ring holds another servo which rotates the ring and servo in the Y axis. The two servos work in conjunction with IMU data to gimbal the motor in a specific directions to thrust vector. I tried uploading a picture a few times but the forum doesn't seem to let me so I hope that makes sense. In a nutshell the servos angle the EDFs exhast 20 degrees in any direction, or at least it should in theory. Hence why I wish to test this by gimbaling in a circle.

Sine and Cosine definitely seem a step in the right direction, although I'm not quite sure how to incorporate that into code just yet. I'll do some digging and let you know if it works out

A picture is still worthwhile. See this Simple Image Posting Guide

Note that the Forum software does not like JPG files with EXIF data from a camera. Copying the JPG to a GIF file will sort that out.

I still can't figure out where the motion in a circle comes into the project.

...R

Perhaps

for (int i = 0 ; i <= 360 ; i++)
{
  int posx = 90 + 20 * cos (i*M_PI/180) ;
  int posy = 90 + 20 * sin (i*M_PI/180) ;
  ....
}

Robin2:
A picture is still worthwhile. See this Simple Image Posting Guide

Problem must have been it was a .JPG. See attached. The circular gimbaling isn't necessity but will help make calibration easier. You should be able to see the two servos I highlighted and hopefully that will illustrate how it moves.

MarkT:
Perhaps

for (int i = 0 ; i <= 360 ; i++)

{
 int posx = 90 + 20 * cos (iM_PI/180) ;
 int posy = 90 + 20 * sin (i
M_PI/180) ;
 ....
}

Thanks Mark! Unfortunately a thrust test went horribly wrong and wrecked most of the structure since the photo. It seems the potentiometer on the transmitter has a mind of its own and likes to randomly shoot the output to max for extended periods of time! I'm waiting on the test rig to be re printed I'll let you know if that worked. Thanks for your help!

It seems the potentiometer on the transmitter has a mind of its own and likes to randomly shoot the output to max for extended periods of time!

I've never seen this.
Are you sure it isn't down to your receiver, or noise?

TheMemberFormerlyKnownAsAWOL:
I've never seen this.
Are you sure it isn't down to your receiver, or noise?

Very possibly. The pot was playing up prior to testing. It did spit out some random outputs without being moved. Both the transmitter and receiver I made myself using arduinos, NRF24s and some custom PCBs I designed. Being a novice at electronics I've definitely missed out a few things I don't fully understand yet such as properly incorporating voltage regulation into my PCBs. I believe there is an inbuilt voltage regulator on the arduino nano and I used a capacitor to stabilised the RF24 voltage but the pot is literally just soldered onto the board so perhaps something to do with wires on the pot touching and shorting itself out? The design is definitely nothing to be admired so I'm looking into controlling things via a web server run on an ESP32. Problem is ESP32's don't seem to play ball with the ESC I'm using. So many complications but a good chance to learn as I go along!

Just a comment..l
SIN & COS (circle drawing) is the right way to go for a 2D plot, but the duct assembly has a third dimension, which extends the plot away from the origin.

In effect, this may require an extra set of calculations to project the ‘radius’ of the duct path, or the air jet correctly.

There are reasons this may not be necessary in your project, but to be mathematically correct, it would be needed ?

amanbasra:
Problem must have been it was a .JPG. See attached. The circular gimbaling isn't necessity but will help make calibration easier. You should be able to see the two servos I highlighted and hopefully that will illustrate how it moves.

I can see the servos but I can't see how they are connected to the gimbals - the advantage of a diagram as a simple pencil drawing is that it can make that clearer than a photo of the actual hardware.

And I'm still unclear about this circling business. Do you want the servos to rotate the motor so (for example) instead of point straight up as in your photo it points from left to right? Again, a diagram will help.

And even if that is true I don't see why its not a case of simply directing the appropriate servo to move to a specific angle with a simple Servo.write() or Servo.writeMicroseconds().

...R

MarkT:
Perhaps

for (int i = 0 ; i <= 360 ; i++)

{
  int posx = 90 + 20 * cos (iM_PI/180) ;
  int posy = 90 + 20 * sin (i
M_PI/180) ;
  ....
}

Sort of what i was thinking, though i would consider calculation the pulse length rather than the Angle for the sake of accuracy (servo.write() uses map() which is an integer calculation). Mind you the servos' probably aren't that accurate. I understand you don't have to much space for the servo connected to the inner ring, but somehow using less than 25% of the range of the servo is not ideal.

but the duct assembly has a third dimension,

it does ? I don't know if you put a laser pen in the center pointing upwards, and you do the 2D circle it will make a circle on the ceiling or whatever surface it is aimed at i'd say.

... agreed, but what is the geometry of that circle ?
Dependent on the distance from the origin.

Deva_Rishi:
I don't know if you put a laser pen in the center pointing upwards, and you do the 2D circle it will make a circle on the ceiling or whatever surface it is aimed at i'd say.

Until the OP explains clearly what he is trying to do all the is just speculation (IMHO).

What would be the point of moving a ducted fan so that a hypothetical laser pointer could draw a circle on a ceiling?

...R

Robin2:
What would be the point of moving a ducted fan so that a hypothetical laser pointer could draw a circle on a ceiling?

...R

Control surface pre-flight check - shows smooth and independent operation of both gimbal axes.

Robin2:
Until the OP explains clearly what he is trying to do all the is just speculation (IMHO).

Sorry if It's not been clear. Not sure how better illustrate it. I'll capture a video a video of the motion I wish to achieve by moving the motor by hand once the structure has been re printed.

Are there any suggestions as to a more accurate system that isn't excessively expensive or larger. Steppers simply wouldn't fit the project.

That won't be until a few days so heres a little capture of the motion in cad (different to the initial image). This should show how the EDF will be moved. The fuselage will restrict the movement to 20 degrees. out of centre. The idea is that it can pivot 20 degrees in any direction between the two servo controlled axis... which would create a theoretical circle of which the motor is able to be moved within (refer to the horrifically drawn out diagram) The outer circle represents the limit of how far from the centre position the motor can move. I want to be able to move the motor along that line essentially to circularly gimbal the motor.

Perhaps "circular" is the wrong term, as there is in-fact a 3rd dimension that the motor will move in which I hadn't paid much attention to but I can see how that changes things and adds a layer of complexity.