Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Maestro mini getMovingStatus() issue


I am using arduino pololu maestro library to control my servos it seems all the commands are working great except getMovingStatus() command.

like this on arduino

maestro.setSpeed(1, 10);
maestro.setTarget(1, 4000);
int x = maestro.getMovingState();

before running above code i always set servo to the highest position then run the above code so that it can replicate travelling of servo and give me required moving status.
its always returning 1 sometimes 0 and 192 randomly but mostly 1…even when it reaches the target position it gives 1 and some random 0 and 192 …i couldn’t figure out this random behaviour…please solve the issue



I tried to reproduce the problem based on your description, but I was not able to. Could you post the simplest complete version of your code that does not work as you expect it to?


#include <PololuMaestro.h>

#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(10, 11);

//MicroMaestro maestro(maestroSerial);
MiniMaestro maestro(maestroSerial);

void setup()
  // Set the serial baud rate.
  maestro.setSpeed(0, 0);
  maestro.setTarget(0, 3000); // start with minimum position

void loop() {

  maestro.setSpeed(0, 10);//setting lower speed
  maestro.setTarget(0, 8000);//move to max position with given speed
  if (maestro.getMovingState() == 1) { //check if moving
  else if (maestro.getMovingState() == 0) { //if reached to position print


i want to produce this result if its moving print moving if its not moving it will print reached


Thank you for posting that code. That code is resetting the servo target position everytime it loops through and checking the moving state after each set target. I suspect the Maestro is receiving the getmovingstate() command before it has time to process the target position and update the moving state variable. Could you try adding a small delay (e.g. 10ms) between setting the target position and sending getmovingstate() and see if that helps? Alternatively, you can move your set target command to the end of your setup() loop, so it is only called once. If this does not fix the problem, can you post an example of what your serial monitor is outputting? Also, what Arduino board are you using?



Hello Brandon
I modified my code according to you by including some delays between sending target position and getMovingStatus() and it seems to have solved my problem …thanks for the kind help.