I am controlling some stepper motors with ROS. The stepper motor spins, but not continually. Like if i tell the motor to move 20 steps, it will move 10 and stop for a few seconds and then complete the rest of the steps. Does anyone know how to fix this?
Do you think that with the information you posted, there is someone in the world who can help you?
Read : " How to get the best out of this forum
and redo your post.
I think you should look for help on the ROS.org forum.
Ref: https://discourse.ros.org/
Show a wiring diagram of your project, and show your sketch.
6dof_robot_arm_3.ino (6.8 KB)
This is the arduino sketch
this is the schematics and code.
When posting your code, inside the REPLY box, click the < CODE > button to see '''type or paste code here''' and paste your code... like this (the .INO you sent):
#include <ros.h>
#include <std_msgs/UInt16MultiArray.h>
#include <AccelStepper.h>
#include <Servo.h>
#include <MultiStepper.h>
#include <std_msgs/Int16.h>
// steppermotor pinouts
// base_link stepper motor pinouts
#define BASE_STEPPER_PIN_STEP 2
#define BASE_STEPPER_PIN_DIR 3
// link_1 stepper motor pinouts
#define LINK_1_STEPPER_PIN_STEP 4
#define LINK_1_STEPPER_PIN_DIR 5
// link_2 stepper motor pinouts
#define LINK_2_STEPPER_PIN_STEP 6
#define LINK_2_STEPPER_PIN_DIR 7
// link_3 stepper motor pinouts
#define LINK_3_STEPPER_PIN_STEP 8
#define LINK_3_STEPPER_PIN_DIR 9
// link_4 stepper motor pinouts
#define LINK_4_STEPPER_PIN_STEP 10
#define LINK_4_STEPPER_PIN_DIR 11
// link_5 stepper motor pinouts
#define LINK_5_STEPPER_PIN_STEP 12
#define LINK_5_STEPPER_PIN_DIR 13
// Built-in LED pin on Arduino Mega
const int ledPin = 13;
/// gears and motor specs
const int stepsPerRevolution1 = 200;
const float gearRatio1 = 5.0;
const float microsteps_1 = 10.0;
const int motorhome_1 = 9000;
const int stepsPerRevolution2 = 200;
const float gearRatio2 = 5.0;
const float microsteps_2 = 10.0;
const int motorhome_2 = 2450;
const int stepsPerRevolution3 = 200;
const float gearRatio3 = 5.0;
const float microsteps_3 = 10.0;
const int motorhome_3 = 1350;
const int stepsPerRevolution4 = 200;
const float gearRatio4 = 5.0;
const float microsteps_4 = 10.0;
const int motorhome_4 = 4500;
const int stepsPerRevolution5 = 200;
const float gearRatio5 = 5.0;
const float microsteps_5 = 10.0;
const int motorhome_5 = 4500;
const int stepsPerRevolution6 = 200;
const float gearRatio6 = 5.0;
const float microsteps_6 = 10.0;
const int motorhome_6 = 4500;
// servo gripper pin
#define SERVO_GRIPPER_PIN 22
#define MIN_RANGE 0
#define MAX_RANGE 180
#define GRIPPER_START 0
AccelStepper stepper1(AccelStepper::FULL2WIRE, BASE_STEPPER_PIN_STEP, BASE_STEPPER_PIN_DIR);
AccelStepper stepper2(AccelStepper::FULL2WIRE, LINK_1_STEPPER_PIN_STEP, LINK_1_STEPPER_PIN_DIR);
AccelStepper stepper3(AccelStepper::FULL2WIRE, LINK_2_STEPPER_PIN_STEP, LINK_2_STEPPER_PIN_DIR);
AccelStepper stepper4(AccelStepper::FULL2WIRE, LINK_3_STEPPER_PIN_STEP, LINK_3_STEPPER_PIN_DIR);
AccelStepper stepper5(AccelStepper::FULL2WIRE, LINK_4_STEPPER_PIN_STEP, LINK_4_STEPPER_PIN_DIR);
AccelStepper stepper6(AccelStepper::FULL2WIRE, LINK_5_STEPPER_PIN_STEP, LINK_5_STEPPER_PIN_DIR);
Servo gripper;
MultiStepper steppers;
int joint_step[7];
int joint_status = 0;
ros::NodeHandle nh;
std_msgs::Int16 msg;
void reach_goal(int goal){
int angle = constrain(goal, 0, 180);
for (int pos = 0; pos <= angle; pos += 1) { // goes from 0 degrees to 180 degrees
gripper.write(pos); // tell servo to go to position in variable 'pos' ... vola
delay(15); // dont remove this delay mate
}
for (int pos = 180; pos >= angle; pos -= 1) { // goes from 180 degrees to 0 degrees
gripper.write(pos);
delay(15);
}
}
void arm_actuate_cb(const std_msgs::UInt16MultiArray &msg)
{
joint_status = 1;
// Extract angle values for motor 1 to motor 7
joint_step[0] = msg.data[0];
joint_step[1] = msg.data[1];
joint_step[2] = msg.data[2];
joint_step[3] = msg.data[3];
joint_step[4] = msg.data[4];
joint_step[5] = msg.data[5];
joint_step[6] = msg.data[6];
}
ros::Subscriber<std_msgs::UInt16MultiArray> sub("arduino/arm_actuate", &arm_actuate_cb);
void setup()
{
Serial.begin(115200);
Serial2.begin(115200);
// Connect to ROS
nh.getHardware()->setBaud(115200);
nh.initNode();
nh.subscribe(sub);
gripper.attach(SERVO_GRIPPER_PIN);
gripper.write(GRIPPER_START);
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.setCurrentPosition(motorhome_1);
stepper2.setMaxSpeed(2000.0);
stepper2.setAcceleration(500.0);
stepper2.setCurrentPosition(motorhome_2);
stepper3.setMaxSpeed(5000.0);
stepper3.setAcceleration(1000.0);
stepper3.setCurrentPosition(motorhome_3);
stepper4.setMaxSpeed(2000.0);
stepper4.setAcceleration(500.0);
stepper4.setCurrentPosition(motorhome_4);
stepper5.setMaxSpeed(2000.0);
stepper5.setAcceleration(500.0);
stepper5.setCurrentPosition(motorhome_5);
stepper6.setMaxSpeed(2000.0);
stepper6.setAcceleration(500.0);
stepper6.setCurrentPosition(motorhome_6);
// Add the 6th axis to the MultiStepper
steppers.addStepper(stepper1);
steppers.addStepper(stepper2);
steppers.addStepper(stepper3);
steppers.addStepper(stepper4);
steppers.addStepper(stepper5);
steppers.addStepper(stepper6);
// Initialize the built-in LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (joint_status == 1)
{
int receivedAngle1 = joint_step[0];
int receivedAngle2 = joint_step[1];
int receivedAngle3 = joint_step[2];
int receivedAngle4 = joint_step[3];
int receivedAngle5 = joint_step[4];
int receivedAngle6 = joint_step[5];
long positions[6]; // Array of desired stepper positions must be long
positions[0] = receivedAngle1 * gearRatio1 * microsteps_1;
positions[1] = receivedAngle2 * gearRatio2 * microsteps_2;
positions[2] = receivedAngle3 * gearRatio3 * microsteps_3;
positions[3] = receivedAngle4 * gearRatio4 * microsteps_4;
positions[4] = receivedAngle5 * gearRatio5 * microsteps_5;
positions[5] = receivedAngle6 * gearRatio6 * microsteps_6;
Serial2.println("steps to move: ");
for (int i = 0; i < 6; i++) {
Serial2.print(positions[i]);
Serial2.print(" ");
}
Serial2.println("");
stepper1.moveTo(positions[0]);
while (stepper1.distanceToGo() != 0) {
positions[0] = receivedAngle1 * gearRatio1 * microsteps_1;
stepper1.run();
}
stepper2.moveTo(positions[1]);
while (stepper2.distanceToGo() != 0) {
positions[1] = receivedAngle2 * gearRatio2 * microsteps_2;
stepper2.run();
}
stepper3.moveTo(positions[2]);
while (stepper3.distanceToGo() != 0) {
positions[2] = receivedAngle3 * gearRatio3 * microsteps_3;
stepper3.run();
}
stepper4.moveTo(positions[3]);
while (stepper4.distanceToGo() != 0) {
positions[3] = receivedAngle4 * gearRatio4 * microsteps_4;
stepper4.run();
}
stepper5.moveTo(positions[4]);
while (stepper5.distanceToGo() != 0) {
positions[4] = receivedAngle5 * gearRatio5 * microsteps_5;
stepper5.run();
}
stepper6.moveTo(positions[5]);
while (stepper6.distanceToGo() != 0) {
positions[5] = receivedAngle6 * gearRatio6 * microsteps_6;
stepper6.run();
}
reach_goal(joint_step[6]); // Move gripper after manipulator reaches the goal
Serial2.print(joint_step[6]);
}
digitalWrite(13, HIGH - digitalRead(13)); // Toggle LED
joint_status = 0;
nh.spinOnce();
delay(1);
}
You are using the same pin for two different devices. Did you write this or download it from ChatGPT?
You uploaded the wrong image. This is not a schematic.
Upload a drawing of the six motors, the DM556, the wires connecting them, the Arduino, the Power Supply... similar to this...
For information, posting the DM556 specifications.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.