i'm trying to port a library i wrote for an hexapod robot from Python to Node. The hardware is a Raspberry PI with a PCA9685 driver (https://github.com/101100/pca9685).
I'm facing a problem on when the servo are activated.
There's a loop that estimate the frequencies for every servo and a function that set the frequency for every channel.
The main problem is that the servos dont moves until the loop stops, so i've to use a setTimeout to re-launch the main routine.
the most relevant parts of the code are the walk function, called by a Redis message:
function walk(){
if(walking){
step();
}
setTimeout(walk,2500);
}
And the stride function, that calculates the frequencies:
function step() {
(loop for every leg){
calculate servo frequencies
pwm.setPulseLength(leg,frequency);
}
}
All the movements are executed by the servos only after the setTimeout in the walk() function.
I've tried to understand how to use the async library or how to create a callback structure but i probably lack something, and i'm not able to understand where the problem is (maybe in the I2C communication flow).
As a last thing, the setTimeout() method works in some way, but should need to exactly knows when the loop ends, so i can start another loop without overlapping or interruptions from one steps and the next.
Thank you!
via Alessio Bernesco Làvore
No comments:
Post a Comment