Go Down

Topic: Controlling continuous servo using joystick vary speed (Read 1 time) previous topic - next topic

aams2018

Hello everyone, i'm new here! i'm facing a problem programming and controlling one 360 servo using an analog joystick or thumb stick varying speed and just like the one in this video

( https://www.youtube.com/watch?v=jjAXLSxl2Vo )

can any one help with this please

Thank you

AWOL

Quote
i'm facing a problem programming
And what exactly is the problem you're facing?

aams2018

the problem is when i leave the stick and it goes back to mid position the servo rotates back when i need it to stay where i moved it

here is the code

#include <Servo.h>
int t=10;
Servo SR04;  // Full rotational
int PinReading=0;
int stick=0;
void setup() {
 
SR04.attach(9);// servo connected to D9
pinMode(A0,INPUT);
}

void loop() {
 
  PinReading=analogRead(A0);
  delay(t);
  stick=map(PinReading,0,1023,0,180);
  stick=constrain(potentiometer,0,180);
  SR04.write(potentiometer);
  delay(50);
 
}

AWOL

How do you decide that a movement of the joystick towards the centre is not to be interpreted as a servo movement?

aams2018

That's the problem, i want to treat the servo as a motor rotating in a direction according to the stick

outsider

Do you have a 0 to 360 degree servo, or a continuous rotation servo?

slipstick

And whatever code you're using it isn't what you posted. That doesn't even compile.

Steve

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

aams2018

it is a continuous servo , and ya sorry the code is

#include <Servo.h>
int t=10;
Servo SR04;  // Full rotational
int PinReading=0;
int stick=0;
void setup() {
 
SR04.attach(9);// servo connected to D9
pinMode(A0,INPUT);
}

void loop() {
 
  PinReading=analogRead(A0);
  delay(t);
  stick=map(PinReading,0,1023,0,180);
  stick=constrain(stick,0,180);
  SR04.write(stick);
  delay(50);
 
}

aams2018

Sorry i guess my servo is a 360 servo with feed back it is (Hitec HS-785HB)

wildbill

For a first attempt, just check whether PinReading is over 520 or so - you'll need to experiment to get an appropriate deadband. If it is, increment the stick variable. If it's less than ~500, decrement the stick variable.

Once that works, you'll probably want to make the amount you change stick by to be proportional to how far the joystick is from the centre. 

slipstick

No the Hitec HS-785HB is not a continuous servo nor is it a 360 degree servo. It is a sail winch servo capable of rotating for 6-8 turns (up to 2880 degrees total) but with full positional control. Roughly speaking write(90) will centre it, write(180) will go 3-4 turns in one direction from the centre position and write(0) will go 3-4 turns in the other direction.

Now we have established that, what EXACTLY is it that you want it to do and what is it currently doing that is different.

Steve

wildbill

It looks to me as if the OP wants to control the sail winch servo so that moving the joystick left turns the servo (let's say) clockwise and moving it right does the reverse with a deadband in the middle when the joystick is centred. i.e. exactly what you would want if you were using it on a model sailboat.

Robin2

It looks to me as if the OP wants to control the sail winch servo so that moving the joystick left turns the servo (let's say) clockwise and moving it right does the reverse with a deadband in the middle when the joystick is centred. i.e. exactly what you would want if you were using it on a model sailboat.
With a model sailboat you would want the servo to stay where it is when you release the joystick. And that is how the code in my link in Reply #7 works.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

slipstick

We could make all sorts of guesses but it's probably easier to wait for the OP to tell us what he ACTUALLY wants.

Steve

Go Up