So basically there's some slight drift in my robot that I'll be detecting using an IMU that I would like to correct by telling the servos to compensate.
However, I've been working using pyserial and a basic arduino servo library, but there's a roughly second delay between my entering the python command and the servo actually moving. I was wondering if anyone knew where that delay is coming from? Since it'd be a bit much, for what I wanted to do.
Setup is wired to the digital PWM pin 9, 5V, and ground using a Datan S1213 servo. With super basic code:
#include <Servo.h>
Servo myServo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myServo.attach(9);
Serial.begin(115200);
}
void loop() {
if(Serial.available() > 0)
{
int pos=Serial.parseInt();
// Serial.print(angulo);
myServo.write(pos);
}
}
import serial
ser = serial.Serial('/dev/cu.usbmodem1411', 115200) # Establish the connection on a specific port
def servoGoTo(pos):
ser.write(str(pos))
And as a separate issue that's really bizarre. When I step through the position below using this for loop, as long as the time.sleep is 1 or greater, it works. However, if I use time.sleep(0.99) the servo freezes there. However, if I manually call the servoGoto(0) and immediately (less than one second) call servoGoto(180), I can flip back and forth. It just queues them up to some degree. I don't expect it to queue commands, but I need to be able to send commands faster than 1 per second, to make small movements in small amounts of time to get better movement resolution.
for i in range(0,180, 45):
servoGoTo(i)
time.sleep(1)
If I needed to I could probably write some compensation software into the arduino code, but the weird issue where I can't send commands less than 1 second really hampers things. They might be related issues, but any help is super appreciated! I've looked through several dozen threads and multiple search terms and still haven't been able to find any leads.