/base_controller/command topic

asked 2017-04-03 08:03:56 -0600

Dornier gravatar image

Hello, I have a university project and I have to read the data from the laser and to create a control signal to the wheels using the laser data. The cpp code and CMakeList file are shown bellow. I use rqt_graph command to visualize the nodes, unfortunately i can't see the topic /base_controller/command, i don't have a connection to the wheels. However, i use rostopic type /base_controller/command and see the published message type, additionally i use the command rostopic list and the topic /base_controller/command is viziable. Could you tell me where might be the problem? In my opinion the CMakeList file is wrong.

    #include "ros/ros.h"
    #include "std_msgs/String.h"
    #include "sensor_msgs/LaserScan.h"
    #include "geometry_msgs/Twist.h"



    class SubscribeAndPublish
    {
    public:
        SubscribeAndPublish()

    {
        sub = n.subscribe("scan", 50, &SubscribeAndPublish::chatterCallback, this);
        pub = n.advertise <geometry_msgs::Twist>("/base_controller/command", 50);
    }

void chatterCallback(const sensor_msgs::LaserScan::ConstPtr& laser)
{
        ROS_INFO("*");
        geometry_msgs::Twist msg;
    ROS_INFO("I heard1: [%f]",laser->ranges[100]);

    if (laser->ranges[100]<1)
    {
        ROS_INFO("--");
        msg.linear.x=-0.5;
        ROS_INFO_STREAM("Com: "<<msg.linear.x);
    pub.publish(msg);
    }
        else
    {
        ROS_INFO("++");
        msg.linear.x=0.5;
        ROS_INFO_STREAM("Com1: "<<msg.linear.x);
    }
    pub.publish(msg);

}

private:

        ros::NodeHandle n;
    ros::Publisher pub;
    ros::Subscriber sub;
};

int main(int argc, char** argv)
{
  ros::init(argc, argv, "program_2_1");

  SubscribeAndPublish SAPObjest;

  ros::spin();

  return 0;
}

cmake_minimum_required(VERSION 2.8.3)
project(program_2)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  sensor_msgs
  geometry_msgs
)

## Generate messages in the 'msg' folder
 #add_message_files(
 #  Vector3.msg
 #  Twist.msg
 #)

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
 generate_messages(
   DEPENDENCIES
   std_msgs  geometry_msgs  # Or other packages containing msgs
 )

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES program_2
#  CATKIN_DEPENDS roscpp rospy 
#  DEPENDS system_lib

)

# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)

# add_library(program_2
#   src/${PROJECT_NAME}/program_2.cpp
# )

add_executable(program_2_1 src/program_2_1.cpp)

target_link_libraries(program_2_1
   ${catkin_LIBRARIES}
 )

# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

# install(TARGETS program_2 program_2_node
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}

# )

# catkin_add_gtest(${PROJECT_NAME}-test test/test_program_2.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()


# catkin_add_nosetests(test)
edit retag flag offensive close merge delete