Arduino AccelStepper Losing ROSSerial Connection

asked 2022-05-03 10:32:47 -0600

Mattisha gravatar image

Hi all! I am trying to run an Arduino Mega and am using stepper motors controlled with the AccelStepper library. I have found that when running one of the motors for any longer than about three seconds, my ROS network loses connection with ROSSerial. Any other time I run a motor for less than three seconds or so, it is fine. I think it has to do with AccelStepper's functions blocking out the rest of the code, not allowing ROS to spin. Anyone have any other ideas or solutions?

Code is below for the specific motor.

void pusher_move_toPosition(long dist) {   
pusherStepperMotor.moveTo(dist);
pusherStepperMotor.runToPosition();

if (pusherStepperMotor.currentPosition( ) == pusherStepperMotor.targetPosition()) {
    pusherStepperMotor.stop();
    response.data = "Pusher_Done";
    positionFeedback.publish(&response);
    response.data = "";
 }
}

This code is effectively being run in the loop() function, which is also calling nh.spinOnce(); I am using ROS Melodic, and am running it on a Raspberry Pi.

Thanks!

edit retag flag offensive close merge delete