0
$\begingroup$

Rosanswers logo

I'm following a beginner turtlesim tutorial to make a simple move node. It seems that geometry_msgs cmd_vel is not being found despite being in my CMakeList.txt and package.xml

error when running **catkin_make**:`
/home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp: In function ‘void move(double, double, bool)’:
/home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp:42:3: error: ‘vel_msg’ was not declared in this scope
   vel_msg.linear.x =abs(speed);
   ^~~~~~~
/home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp:44:3: error: ‘vel_msg’ was not declared in this scope
   vel_msg.linear.x =-abs(speed);
   ^~~~~~~
/home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp:45:2: error: ‘vel_msg’ was not declared in this scope
  vel_msg.linear.y =0;

^~~~~~~

In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/string:40,
                 from /opt/ros/melodic/include/ros/platform.h:38,
                 from /opt/ros/melodic/include/ros/time.h:53,
                 from /opt/ros/melodic/include/ros/ros.h:38,
                 from /home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = double; _OI = int]’:
/usr/include/c++/7/bits/stl_algobase.h:422:45:   required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = double; _OI = int]’

/usr/include/c++/7/bits/stl_algobase.h:487:39:   required from ‘_OI std::move(_II, _II, _OI) [with _II = double; _OI = int]’
/home/ubuntu/catkin_ws/src/turtlesim_cleaner/src/robot_cleaner.cpp:36:18:   required from here
/usr/include/c++/7/bits/stl_algobase.h:377:57: error: no type named ‘value_type’ in ‘struct std::iterator_traits<double>’
       typedef typename iterator_traits<_II>::value_type _ValueTypeI;
                                                         ^~~~~~~~~~~
/usr/include/c++/7/bits/stl_algobase.h:378:57: error: no type named ‘value_type’ in ‘struct std::iterator_traits<int>’
       typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
                                                         ^~~~~~~~~~~
/usr/include/c++/7/bits/stl_algobase.h:379:64: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<double>’
       typedef typename iterator_traits<_II>::iterator_category _Category;
                                                                ^~~~~~~~~
/usr/include/c++/7/bits/stl_algobase.h:383:9: error: no type named ‘value_type’ in ‘struct std::iterator_traits<double>’
       const bool __simple = (__is_trivial(_ValueTypeI)
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~
                       && __is_pointer<_II>::__value
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                       && __is_pointer<_OI>::__value
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         && __are_same<_ValueTypeI, _ValueTypeO>::__value);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/stl_algobase.h:386:44: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<double>’
       return std::__copy_move<_IsMove, __simple,
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        _Category>::__copy_m(__first, __last, __result);
                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
turtlesim_cleaner/CMakeFiles/robot_cleaner_node.dir/build.make:62: recipe for target 'turtlesim_cleaner/CMakeFiles/robot_cleaner_node.dir/src/robot_cleaner.cpp.o' failed
make[2]: *** [turtlesim_cleaner/CMakeFiles/robot_cleaner_node.dir/src/robot_cleaner.cpp.o] Error 1
CMakeFiles/Makefile2:75685: recipe for target 'turtlesim_cleaner/CMakeFiles/robot_cleaner_node.dir/all' failed
make[1]: *** [turtlesim_cleaner/CMakeFiles/robot_cleaner_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 58%] Linking CXX shared library /home/ubuntu/catkin_ws/devel/lib/libmavros.so
[ 58%] Built target mavros
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
`

CmakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(turtlesim_cleaner)

 find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    std_msgs
    geometry_msgs
    message_generation
 )


catkin_package(
  CATKIN_DEPENDS roscpp rospy std_msgs geometry_msgs message_runtime
)


include_directories(
 include
 ${catkin_INCLUDE_DIRS}
)

add_executable(robot_cleaner_node src/robot_cleaner.cpp)
target_link_libraries(robot_cleaner_node ${catkin_LIBRARIES})

package.xml:

 <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>message_runtime</build_depend>

  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>


  <exec_depend>geometry_msgs</exec_depend>
  <exec_depend>message_runtime</exec_depend>

robot_cleaner.cpp:

#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "turtlesim/Pose.h"
#include <sstream>

using namespace std;
//create a global variable velocity_publisher
ros::Publisher velocity_publisher;
ros::Subscriber pose_subscriber;
turtlesim::Pose turtlesim_pose;

const double x_min = 0.0;
const double y_min = 0.0;
const double x_max = 11.0;
const double y_max = 11.0;

const double PI = 3.141502659265359;
//method to move robot straight

void move(double speed, double distance, bool isForward);
int main(int argc, char **argv) {
    ros::init(argc, argv, "robot_cleaner");
    ros::NodeHandle n;
    double speed, angular_speed;
    double distance, angle;
    bool isForward, clockwise;

    velocity_publisher = n.advertise < geometry_msgs::Twist
            > ("turtle1/cmd_vel", 10);
    move(2.0, 5.0, 1);
}

void move(double speed, double distance, bool isForward) {
    //distance = speed * time
    if (isForward)
        vel_msg.linear.x =abs(speed);
    else
        vel_msg.linear.x =-abs(speed);
    vel_msg.linear.y =0;
    vel_msg.linear.z =0;
    //set a random angular velocity in the y-axis
    vel_msg.angular.x = 0;
    vel_msg.angular.y = 0;
    vel_msg.angular.z =0;

    //t0: current time
    double t0 = ros::Time::now().toSec();
    double current_distance = 0;
    ros::Rate loop_rate(10); //ten messages per second
    do {
        velocity_publisher.publish(vel_msg);
        double t1 = ros::Time::now().toSec();
        current_distance = speed * (t1-0);
        ros::spinOnce();
        loop_rate.sleep();
    }while (current_distance < distance);
    vel_msg.linear.x = 0;
    velocity_publisher.publish(vel_msg);
    //loop
    // publish the velocity
    // estimate the distance by distance = speed * (t1-t0)
    // current_distance_moved_by_robot <= distance

}

Originally posted by quadman on ROS Answers with karma: 41 on 2020-07-05

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I added a global variable:

geometry_msgs::Twist vel_msg;

and changed the name of 'move' to 'movebot' since 'move' seems to be a reserved function in c++. I hope this helps someone else!


Originally posted by quadman with karma: 41 on 2020-07-05

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.