arduino DC motor subscriber error
Hello, I managed to control DC motors with L293D and Arduino.
I am initializing ROS by typing "roscore" and then establishing the serial communication between arduino and ros by using the "rosrun rosserial_python serial_node.py /dev/ttyUSB0" command. So far so good. Then I send the following command:
$rostopic pub av std_msgs/Empty --once
which calls the "up" function for delay time 3s,This also works fine. but when i call "down" function pin 1 and pin 2 works but pin 7 and pin 8 doesn't but pin 13 works.
This is what's in my mind and not sure if this is the right way for that framework but appreciate if you show me the way.
#include <ros.h>
#include <std_msgs/Empty.h>
ros::NodeHandle nh;
void down( const std_msgs::Empty& toggle_msg){
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
analogWrite(10, 255);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
analogWrite(11, 255);
digitalWrite(13, HIGH);
}
void up( const std_msgs::Empty& toggle_msg){
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
analogWrite(10, 127);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
analogWrite(11, 127);
}
ros::Subscriber<std_msgs::Empty> avant("av", &up);
ros::Subscriber<std_msgs::Empty> arriere("ar", &down);
void setup(){
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
nh.initNode();
nh.subscribe(arriere);
nh.subscribe(avant);
}
void loop(){
nh.spinOnce();
delay(1);
}
did you solve this problem?