I was using servo.write and I got a fine result, but I needed more resolution/slower speed so I wanted to use writeMicroseconds() instead.
This part of code succesfully moves the motors. Depending on that flag 'occupied' the motors must take positions of either lowPos or highPos. I shift 1 us at the time every 20ms.
That repeat macro just uses millis(), nothing fancies.
void moveArms()
{
REPEAT_MS( 20 )
{
uint16_t setpoint ;
if( occupied ) setpoint = highPos ;
else setpoint = lowPos ;
if( pulseUs < setpoint ) pulseUs ++ ; // close
if( pulseUs > setpoint ) pulseUs -- ; // open
arm1.writeMicroseconds(pulseUs) ; // replace by write microseconds
arm2.writeMicroseconds(pulseUs) ;
arm3.writeMicroseconds(pulseUs) ;
arm4.writeMicroseconds(pulseUs) ;
}
END_REPEAT
}
Now the part where I suspect I am doing something wrong.
In the initialisation I use this code to calculate pulse durations. I insert degrees in the map function and I expect correct pulse times comming out.
I map 0-180 degrees to 1000-2000us and I want lowPos to be 20 degrees and highPos 100 degrees.
lowPos = map( 20, 0, 180, 1000, 2000 ) ;
highPos = map( 100, 0, 180, 1000, 2000 ) ;
As far as internet tells me, I think I have entered the correct numbers in map()
The motor should rotate 80 degrees, but from the looks of it, they rotate about 35 degrees.
Serial printout of the outcome gives me 1111 and 1555 respectively. This appears to be correct.
I also printed the pulseUs values during movement and every step between 1111 and 1555 is used as parameter with writeMicroseconds();
lowPos
highPos
Am I making some horrible mistake here or is writeMicroseconds() doing something else I think it should?
I use an atmega328, Arduino's Servo library and Mg90 analog servo motors
Kind regards,
Bas



