Guys, I am trying to write trigonometry function to control servo using PS2 Controller. The servo will move to angles calculated by the formula. I managed to write the formula, but the servo doesnt react well (slow response, even to the point of the servo trembling), while the servo works fine if I control it manually using serial monitor. I suspect I must change the float to int or maybe adding float to the formula. Any help will be appreciated.
Why do you initialize the Serial port and not use it?
You may want to use Serial.writeln to Monitor the values you are writing to the servos. You might see where the jitters are coming from.
The servo library defines the angle Parameter as int. Since you are using float, it will be converted to int and you may be encountering rounding Problems.
Here's how it works. The input will be xe,ye and ze, while the output is theta1, theta2 and theta3. Basically, I change the value of xe, ye and ze using PS2 controller to increase or decrease the value by 1. The arduino will do the math given the formula to calculate theta1, theta2 and theta3 and the servo will move. I have tried serial print to check the value of theta1 before actually use the value to move servo and nothing's wrong. So, do I have to convert every float to int instead of using float? I afraid that it will affect on how theta1 will be rounded to move servo.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
If you need finer servo control try servoWriteMicroseconds.
Thanks for the help, but still doesnt work. Is there any other way? I have tried using microseconds, but its not helping. The servo still shakes (maybe thats what you mean by confused).