So I have some code set up to move a robot in a straight line using a continuous rotation servo, I have set up two IR proximity sensors on either end so It wont run into the walls. The problem is controlling it, currently I can control it perfectly with a joystick because the joystick returns to neutral position, but what I'd like to do is control it with a dial (a more traditional potentiometer).
This causes the servo to continue rotating when I stop moving the pot, I'd like to get it to move with the dial and stop moving with the dial (much like original pong if anyone knows what that was like).
Please do not recommend the "Sweep" example, it does not work with continuous rotation servos (says experience and the internet)
#include <Servo.h>
const int analogInPinx = A0; // Analog input pin that the potentiometer is attached to
const int n = 30;
int sensorValuex = 0; // value read from the pot
int outputValuex = 0; // value output to the PWM (analog out)
int IRSwitchPin = 8;
int IRSwitchPin2 = 7;
boolean proximityL = false;
boolean proximityR = false;
Servo servo1;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
servo1.attach(10);
pinMode(IRSwitchPin, INPUT);
pinMode(IRSwitchPin2, INPUT);
}
void loop() {
// read the analog in value:
//for pot:
sensorValuex = analogRead(analogInPinx);
// map it to the range of the analog out:
outputValuex = map(sensorValuex, 0, 1023, n, 0);
if (outputValuex < n/2){
if(digitalRead(IRSwitchPin) == LOW){
servo1.write(n/2);
if(outputValuex > n/2){
servo1.write(outputValuex);
}
}
else{
servo1.write(outputValuex);
}
}
else{
if(digitalRead(IRSwitchPin2) == LOW){
servo1.write(n/2);
if(outputValuex < n/2){
servo1.write(outputValuex);
}
}
else{
servo1.write(outputValuex);
}
}
Serial.println(digitalRead(IRSwitchPin));
delay(2);
}
Hi, if you are trying to set the servo position with the position of the pot, then you should not be using the continuous servo, it should be a normal servo.
That is why you have the joystick with continuous servo, when you get to the position you want to let the joystick return to zero position.
I think you have better rethink what you need.
The only solution with the servo you have, would be to remap the signal to your servo you give you slower response and so more precise control.
You could possibly design your code so the robot only moves when you move the knob. If the knob stops moving so does the robot. However this may not be what you want either as it would get rather tedious. (as well as which, it would not be so easy to construct - it wouldn't work with a normal potentiometer).
A joystick is just a lever connected to a potentiometer with a spring to make the pot come back to its central position.
Another possibility might be to interpret the position of the potentiometer as the time (which is a rough proxy for distance) the robot has moved from the start point. So moving the pot a bit more to the right (say) will make the robot move a bit farther forward and turning the pot a bit to the left will make it move a bit in reverse. The problem is that without stepper motors you will lose the absolute position of the robot very quickly. Even with stepper motors it won't be foolproof.
I found this topic and although I don't have the very same problem, I hope someone here could take a look at it.
Here is the thing, I was calibrating my continuous rotation servo AR-3606HB, using the trim pot access port, but failed in the process though I did this very carefully. Now it seems to spin at the same speed and just can't find the stop pot.
What is a "trim pot access port" and how do you know you have failed? Can you post a link to the specs for the servo and a copy of your code (hoping it is as short as possible to demonstrate the problem).
I already fixed the problem, took me like an hour twisting the screw until it stayed still, also needed to open it to perform a better adjustment.
By trim pot I mean servo’s potentiometer access port (screw).
I though I had failed cause the servo was spinning only in one direction and not the other way around, possibly due to bad twisting and damage of the screw, but fortunately that was not my case.