Robotics StackExchange | Archived questions

Arduino error lost sync device restatring..

hi , when i run my arduino code in previous arduino uno, the code is running well ...after changing the arduino board , when we upload the same code and try to execute , getting error like "Lost sync with device, restarting..."..actually when we run three stepper motors information we are getting issue, but when we eliminated 1 stepper information from the code the code is executing...please tell me the solution..arduino code

`#include

include

include

// Define the number of steps per revolution const int stepsPerRevolution = 800; const int gearRatio = 19; const int gearRatio_end = 14;

// Declare the PUL and DIR pins for each motor const int motor1pul = 2; const int motor1dir = 3;

const int motor2pul = 4; const int motor2dir = 5;

//const int motor3pul = 6; //const int motor3dir = 7;

// Create an AccelStepper object for each motor AccelStepper motor1(AccelStepper::DRIVER, motor1pul, motor1dir); AccelStepper motor2(AccelStepper::DRIVER, motor2pul, motor2dir); //AccelStepper motor3(AccelStepper::DRIVER, motor3pul, motor3dir);

// Initialize the ROS node ros::NodeHandle nh;

// Create a message to hold the steps for each motor // stdmsgs::UInt16MultiArray stepsmsg;

// Callback function for the arduinobot/armactuate subscriber void armactuatecb( const stdmsgs::UInt16MultiArray& angles_msg){

// Extract the angles from the message int angle1 = anglesmsg.data[0]; int angle2 = anglesmsg.data[1]; //int angle3 = angles_msg.data[2];

// Calculate the number of steps required to move each motor to the specified angle int steps1 = gearRatio * (angle1 / 360.0) * stepsPerRevolution; int steps2 = gearRatio * (angle2 / 360.0) * stepsPerRevolution; //int steps3 = gearRatio_end * (angle3 / 360.0) * stepsPerRevolution;

if (angle1 >= motor1.currentPosition()) { digitalWrite(motor1dir, HIGH); } else { digitalWrite(motor1dir, LOW); } if (angle2 >= motor2.currentPosition()) { digitalWrite(motor2dir, HIGH); } else { digitalWrite(motor2dir, LOW); } // if (angle3 >= motor3.currentPosition()) { // digitalWrite(motor3dir, HIGH); // } else { // digitalWrite(motor3dir, LOW); //}

// Move the motors the specified number of steps motor1.moveTo(steps1); motor2.moveTo(steps2); //motor3.moveTo(steps3); // stepsmsg.data[0] = steps1; // stepsmsg.data[1] = steps2; // steps_msg.data[2] = steps3; }

// Define the subscriber to the topic /servoactuate where are published UInt16MultiArray messages // Define the function that will be triggered each time a new message is published on this topic ros::Subscriber<stdmsgs::UInt16MultiArray> sub("arduino/armactuate", &armactuate_cb );

void setup(){

// Set the maximum speed and acceleration for each motor motor1.setMaxSpeed(10000); motor1.setAcceleration(5000);

motor2.setMaxSpeed(10000); motor2.setAcceleration(5000);

// motor3.setMaxSpeed(10000); // motor3.setAcceleration(5000);

// Inizialize the ROS node on the Arduino nh.initNode(); // Inform ROS that this node will subscribe to messages on a given topic nh.subscribe(sub); }

void loop() { // Run the motor update functions motor1.run(); motor2.run(); //motor3.run();

// Keep the ROS node up and running nh.spinOnce(); delay(1); }`

Asked by jagilamkumar on 2023-01-28 06:48:42 UTC

Comments

Answers