Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

My car does not move

Hello Here is what I'm trying to : I'm using an rplidar, arduino connected to Raspberry with ROS kinetic, to do autonomous mapping and navigation.

First, i run the rplidar with

roslaunch rplidar_ros view_rplidar.launch

then , slam mapping with

roslaunch rplidar_ros view_slam.launch

then I used hector_exploration with

roslaunch hector_exploration_node exploration_planner.launch

Final, to publish the cmd_vel topic I run

rosrun hector_exploration_controller simple_exploration_controller

Here is the Arduino code

#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>


ros::NodeHandle nh;
int STBY = 10; //standby

//Motor A
int PWMA = 4; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction

//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction


// __________________________RPLidar data_______________

void messageCb( const geometry_msgs::Twist& msg){


  if(msg.angular.z>0)
   {
      move(2, 255, 1);
   }
   else if(msg.angular.z<0)
   {
     move(2, 255, 1);
   }
   else if(msg.angular.z == 0)
   {
     move(2, 120, 1);
   }
   else{
      move(1, 30, 1);
}

}
// _________________________________________
ros::Subscriber<geometry_msgs::Twist> sub("cmd_vel1", &messageCb );

void setup(){
pinMode(STBY, OUTPUT);

pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);

pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);

nh.initNode();
nh.subscribe(sub);
}

void loop(){

nh.spinOnce();
delay(20);
}

void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise

digitalWrite(STBY, HIGH); //disable standby

boolean inPin1 = LOW;
boolean inPin2 = HIGH;

if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}

if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}

The car does not move at all, I'm not even sure if the cmd_vel are imported ? Can someone help