Controlling continuous servo using joystick vary speed

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

( variable speed test continuous servo - YouTube )

can any one help with this please

Thank you

i'm facing a problem programming

And what exactly is the problem you're facing?

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);

}

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

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

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

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

Steve

The code in this link may help.

...R

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);

}

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

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.

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

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.

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.

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

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

The OP posted this question elsewhere

To demonstrate exactly what i need to do, i just found this video on youtube while looking for something similar and that exactly what i want my servo to do

please check the link ( https://www.youtube.com/watch?v=jjAXLSxl2Vo )

In that video the person is using a continuous rotation servo.

If you map the output of analogRead() to 0 to 180 and then use servo.write() a continuous rotation servo should behave like the video.

On the other hand, if you are using a sail-winch servo with a limited amount of movement the code in the link I gave you in Reply #7 should be suitable.

...R

That video shows a servo travelling for much more than 8 turns and at varying speeds. You can't do that with a sail winch servo which has only limited travel and also no control at all over the speed it moves at (though you can fudge that using Sweep-style loop techniques or the VarSpeedServo library if necessary).

But basically if that is really what is needed then the OP has the wrong servo.

Steve