How to pilot a continuous Servo SM S4315R

Hi there !

So to put it simple, I want to create a system that pulls a brake cable when I press a force sensor. I have a pretty good force sensor and a powerful servo, but it's continuous, meaning I can't choose its position. Here's my actual code :

const int flexpin = 0; 


void setup() 
{ 

   
  Serial.begin(9600);
  


  servo1.attach(9);
} 


void loop() 
{ 
  int flexposition;    // Input value from the analog pin.
  int servoposition;   // Output value to the servo.

  
  
  flexposition = analogRead(flexpin);

  servoposition = map(flexposition, 100, 1023, 0, 92);
  servoposition = constrain(servoposition, 0, 92);


  servo1.write(servoposition);


  
  Serial.print("sensor: ");
  Serial.print(flexposition);
  Serial.print("  servo: ");
  Serial.println(servoposition);
  

  
  delay(20);  // wait 20ms between servo updates
}

With that, I can pull the cable very hard, and then stop(92 is neutral for my servo) when I stop pressing the sensor. Amazing isn't it ? Yeah I know it's pity but I'm a beginner ... Here's my problem : I want it to be able to go back to its previous position ( to put the cable back in neutral position, where the brakes aren't activated). I would be satisfied if you were able just to make it go backward for a definite time after going forward, because I can easily mesure how much time is needed to go back into position. However if you were able to help finding a more "precise position" it would be incredible ...

Thank you very much for your time, and have a nice day !

You need to sense position, that requires a sensor / encoder.

The force sensor should go back to it's original resistance when you let off of it, thus the servo command should change. If this is a continuous rotation servo, one side of neutral will drive one way, and the other side of neutral will drive the opposite way. So far so good, except that the servo would rotate too long the opposite way. To solve this, a cheap solution would be a micro switch that signals the Arduino when the logical brake off position is reached, and prevent further travel in that direction. Then the program would only allow movement in the servo brake direction.

However, you could easily make the full rotation servo back into a normal servo by adding an external potientiometer, thus solving the problem.

Unless there's a compelling reason you haven't told us about for using a continuous servo, I'd be very inclined to replace it with a normal one.

Hi guys, thank you very much for your answer ! It is a continuous because well it was the one with the most torque that was drivable by arduino without a shield...

I think I will use the little switch technique, that's so simple but brillant ! How can I implement that into my already existing program ? To be honest I'm a little bit lost, I'm pretty fluent with python but using the sensors is very different and I'm not very proficient at it for the moment ....

I have an idea also : I have a much smaller servo ( the starter kit one ) which works as expected with the program ( it's a classic servo, but it doesn't have enough torque). Maybe I can synchronise the two ? Meaning if one goes forward the other does the same. So the smaller one leads the bigger one. How can I achieve that in my program ?

Thank you very much !

Hi folks !

So I tried with a classic servo and he doesn't have enough torque to do what I want. I have to stick to the continuous one.

Here is my current problem : It pulls the cable as I want, but I don't know how I can make it go backward for a definite time after he pulled the cable ( to replace it in its normal state). Does anybody know how to do that ? Here is my current code. He goes forward and goes backwards very slowly ( it's the only trick i was able to achieve but it's not good since at a given moment he will start to pull the cable in the other direction).

So to sum it up : How can I implement a command into my code that makes my servo go backward for a definite time after he pulled the cable ?

Thank you very much :)