I have the following code. I want it so it sets pos to zero again (without moving servos) and than it will make the robot go straight until I turn it off.
I have this. The robot, moved straight for the first time for 360 degrees. After that it wont move... help please. I am new to this. If someone could just give me some code that worked how I wanted it I could figure a lot out.
It may help you to understand how to control the direction if you write a function that moves the robot in a particular direction for a given amount of time. When you have that working you should be able to adapt the logic to do anything else you want.
Here is some pseudo code to get you started:
void move( int direction, int duration){
// write a value to the left and write servos appropriate to the direction
// your code here
delay(duration);
}
Your loop code does not change the value of the variable "pos". Therefore, the "if" condition will always be true, and the code inside the curly brackets will execute repeatedly (as "loop" gets called repeatedly). So, all it does is repeatedly set the servos to the same position., with an 11ms delay each time.
Could you please describe clearly what you want to do, and in what way this code does not work?
code that worked how I wanted
You have not actually told us what you want it to do!
The servos are modified and serve as the wheels. My question is, how do I code in 'C' so my servos will just keep on spinning in one way. If I get that I could probably get the other servo to move also in the opposite direction.
You don't need any of the code that increments the angle. The continuous rotation servos have no idea where they are, you can't set angles. All you can do is tell them to turn forward or reverse, and to some degree adjust the speed.
...will probably make the robot go in one direction forever. Change both numbers to 90 and the robot should stop, you might have to adjust the trimpots if your servos have them.
You don't say which servo library you are using. If it's the software serial library then you need to add the following to the end of macegr's code
Servo::refresh();
delay(20):
If you are using the servo library that is distributed with Arduino 0012 and later, try the example sketches and see if you can get the servos to turn. The servos could be drawing more power than your board can supply – if so then you will need to power them using an external power source.
The servos can move, they do with my old code, but they go back and forth or whatever. I just want my servos to go straight none stop, until I stop the power.
Also Servo::refresh(); does not exist or something. I am using Roboduino
Are you SURE that your servos are modified for continuous rotation? Most servos are designed to turn 180 degrees and no further, making them rotate continuously requires opening them up and cutting/soldering various things.
Any guide for modifying HS-311 servos for continuous rotation would have showed how to modify the potentiometer position sensor. You should find the instructions you used and see if you skipped that part.