ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Running Joy node with Accelstepper.h in Arduino

asked 2021-10-18 12:56:29 -0500

Mattisha gravatar image

updated 2021-10-18 13:23:22 -0500

Hi all,

I am trying to take input from the Joy node and use it to run a motor using Accelstepper.h in Arduino, yet with my code I am not able to get the stepper motor to run. It is able to run when I code it directly to move but not with the Joy node code. The Joy node is returning a value, it just is not setting the speed and running the motor. I am using ROS Melodic.

Here is my code:

#include <stdint.h> 
#include <stdlib.h>
#include <ros.h>
#include <std_msgs/Float32.h>
#include <sensor_msgs/Joy.h>
#include <AccelStepper.h>

ros::NodeHandle nh; //Node Handler
// Lower Platform Stepper Pins
int lowerPlatformEnable = 37;   // Active HIGH
int lowerPlatformPUL = 36; 
int lowerPlatformDIR = 35;      // (LOW: Forwards | HIGH: Backwards)
float lowerPlatformMaxSpeed = 10000;      // Steps per second 
float lowerPlatformAccel = 2250;  // Steps per second per second 
AccelStepper lowerStepperMotor(AccelStepper::DRIVER, lowerPlatformPUL, lowerPlatformDIR); 

//Joystick callback
char output[6];
char motorSpeed[10];

void joydata (const sensor_msgs::Joy& joy){
  dtostrf(joy.axes[1], 4, 3, output);
  nh.loginfo(output);
  lowerStepperMotor.setSpeed(joy.axes[1]*100);
  lowerStepperMotor.runSpeed();
}

//Joystick subscriber
ros::Subscriber<sensor_msgs::Joy> sub1("joy", joydata);

void setup(){
  // Lower Platform Stepper
  pinMode(lowerPlatformEnable, OUTPUT); 
  pinMode(lowerPlatformPUL, OUTPUT); 
  pinMode(lowerPlatformDIR, OUTPUT); 

  lowerStepperMotor.setMaxSpeed(lowerPlatformMaxSpeed); // In steps per second 
  lowerStepperMotor.setAcceleration(lowerPlatformAccel);
  nh.initNode();
  nh.subscribe(sub1);
}

void loop()   {
  nh.spinOnce();
  delay(10);
}

Thank you all!

EDIT: I added if(lowerStepperMotor.isRunning()){ nh.loginfo("Running"); }

below the runSpeed() call and it does say it is running when I move the joystick, yet the motors still don't move.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-10-18 14:56:19 -0500

Mattisha gravatar image

Hi all!

Found out my issue - I had to manually enable the ENABLE Input for the lowerStepperMotor. Things ran fine after that!

edit flag offensive delete link more

Comments

Good news!!

osilva gravatar image osilva  ( 2021-10-18 15:34:56 -0500 )edit

Question Tools

Stats

Asked: 2021-10-18 12:54:55 -0500

Seen: 336 times

Last updated: Oct 18 '21