How to setup a C++ project for moveit?
Hi i'm a newbie of ROS and C++, i worked with python for some months and i would like to start to use C++ which is well supported. I am using ROS Kinetic with Ubuntu 16.04 and Qt-creator with ROS plugin as IDE.
I created a new workspace with: catkin build
and a new package with: catkin_create_pkg test1 roscpp rospy std_msgs
.
I opened the CMakeLists.txt
inside the package and i modified this in this way:
cmake_minimum_required(VERSION 3.0.2)
project(test1)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
find_package(moveit_ros_planning_interface)
include_directories(${moveit_ros_planning_interface_DIR})
find_package(Eigen3 REQUIRED)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIRS})
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES test1
# CATKIN_DEPENDS roscpp rospy std_msgs moveit_ros_planning_interface
# DEPENDS system_lib
)
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
add_executable(test1 src/moveit_tutorial.cpp)
I created this simple C++ script like the moveit tutorials in order to practice:
#include <ros/ros.h>
#include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>
#include <moveit_msgs/DisplayRobotState.h>
#include <moveit_msgs/DisplayTrajectory.h>
#include <moveit_msgs/AttachedCollisionObject.h>
#include <moveit_msgs/CollisionObject.h>
int main(int argc, char **argv)
{
// Inizializzazione nodo ROS
ros::init(argc, argv, "moveit_tutorial");
ros::NodeHandle node_handle;
ros::AsyncSpinner spinner(1);
spinner.start();
ROS_INFO("HELLO! NODO INIT");
// Nome del gruppo
static const std::string PLANNING_GROUP = "manipulator";
moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP);
// Raw pointers are frequently used to refer to the planning group for improved performance.
const robot_state::JointModelGroup* joint_model_group =
move_group.getCurrentState()->getJointModelGroup(PLANNING_GROUP);
geometry_msgs::Pose target_pose1;
target_pose1.orientation.w = 1.0;
target_pose1.position.x = 0.10;
target_pose1.position.y = -0.1;
target_pose1.position.z = 0.3;
move_group.setPoseTarget(target_pose1);
moveit::planning_interface::MoveGroupInterface::Plan plan1;
bool success = (move_group.plan(plan1) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
ROS_INFO_NAMED("tutorial", "visualizing plan 1 (pose goal) %s", success ? "" : "FAILED");
// usa move_group.move() quando usi un vero robot
// Pianificare un joint-space goal
// RobotState oggetto che contiene tutte le posizioni attuali pos/vel/acc
moveit::core::RobotStatePtr current_state = move_group.getCurrentState();
// Current set of joint values
std::vector<double> joint_group_position;
// copia da current state i valori dei giunti
current_state->copyJointGroupPositions(joint_model_group, joint_group_position);
// modifico un valore di un giunto
joint_group_position[0] = -1.0;
move_group.setJointValueTarget(joint_group_position);
moveit::planning_interface::MoveGroupInterface::Plan plan2;
success = (move_group.plan(plan2) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
ROS_INFO("HA AVUTO SUCCESSO? %s", success ? "SI" : "NO");
if (success)
{
move_group.execute(plan2);
}
ros::shutdown();
return 0;
}
On the IDE i receive this error: moveit_tutorial.cpp:40:43: error: member reference type 'robot_state::RobotStatePtr' (aka 'int') is not a pointer
And after sourcing the workspace and building i received:
Errors << test1:make /home/kappa95/ur5_tests/logs/test1/build.make.004.log
In file included from /opt/ros/kinetic/include/moveit/macros/class_forward.h:40:0,
from /opt/ros/kinetic/include/moveit/move_group_interface/move_group_interface.h:41,
from /home/kappa95/ur5_tests/src/test1/src/moveit_tutorial.cpp:13:
/opt/ros/kinetic ...
Can you link the tutorial you are following? This seems like a potential CMakeLists error, so I'd like to see where you got that from.
I'm following the basic tutorial on moveit site for Kinetic distribution: link moveit tutorial The code of the example is linked on their website and the link is: github
I substituted only the name of the group because i'm using an UR5 on Gazebo. I'm doing the same on Python and it works. I am using this "case study" for learning C++ with ROS
Great, thanks! I don't see any glaring issues and will try to run your code on my Kinetic distro in a bit. Before that, can you try running straight from the C++ move group interface tutorial (rather than your own code/package) and make sure that works?
Thanks a lot! I created another workspace and cloned the robot moveit package of the tutorial. The tutorial code works. I tried also to copy their CMakeLists.txt into mine but it doesn't work