Error while building simple code from gidhub
I am trying to build this program https://github.com/ros-controls/ros_control/wiki/hardware_interface
libarmlib.h
#ifndef LIBARMLIB_H
#define LIBARMLIB_H
#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/joint_state_interface.h>
#include <hardware_interface/robot_hw.h>
class MyRobot : public hardware_interface::RobotHW
{
public:
MyRobot()
{
// connect and register the joint state interface
hardware_interface::JointStateHandle state_handle_a("joint1", &pos[0], &vel[0], &eff[0]);
jnt_state_interface.registerHandle(state_handle_a);
registerInterface(&jnt_state_interface);
// connect and register the joint position interface
hardware_interface::JointHandle pos_handle_a(jnt_state_interface.getHandle("joint1"), &cmd[0]);
jnt_pos_interface.registerHandle(pos_handle_a);
registerInterface(&jnt_pos_interface);
}
private:
hardware_interface::JointStateInterface jnt_state_interface;
hardware_interface::PositionJointInterface jnt_pos_interface;
double cmd[1];
double pos[1];
double vel[1];
double eff[1];
};
#endif
program1.cpp
#include <controller_manager/controller_manager.h>
#include <iostream>
#include <iomanip>
#include "libarmlib.h"
int main()
{
MyRobot robot;
controller_manager::ControllerManager cm(&robot);
while (true)
{
robot.read();
cm.update(robot.get_time(), robot.get_period());
robot.write();
sleep();
}
}
Cmakelists.txt
cmake_minimum_required(VERSION 2.8.3)
project(armbot_description)
find_package(catkin REQUIRED COMPONENTS
hardware_interface
controller_manager
joint_limits_interface
roscpp
)
add_library(armlib4 src/libarmlib.h)
target_link_libraries(armlib4 ${catkin_LIBRARIES})
set_target_properties(armlib4 PROPERTIES LINKER_LANGUAGE CXX)
catkin_package(
INCLUDE_DIRS include
LIBRARIES armlib4
CATKIN_DEPENDS
controller_manager
hardware_interface
joint_limits_interface
roscpp
DEPENDS Boost
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_executable(armbot_description src/program1.cpp)
target_link_libraries(armbot_description armlib4)
install(TARGETS armlib4
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
and I get this:
Base path: /home/sofia/catkin_ws
Source space: /home/sofia/catkin_ws/src
Build space: /home/sofia/catkin_ws/build
Devel space: /home/sofia/catkin_ws/devel
Install space: /home/sofia/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/sofia/catkin_ws/build"
####
####
#### Running command: "make -j2 -l2" in "/home/sofia/catkin_ws/build/armbot_description"
####
[ 0%] Built target armlib4
[100%] Building CXX object armbot_description/CMakeFiles/armbot_description.dir/src/program1.cpp.o
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp: In function ‘int main()’:
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:15:12: error: ‘class MyRobot’ has no member named ‘read’
robot.read();
^
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:16:22: error: ‘class MyRobot’ has no member named ‘get_time’
cm.update(robot.get_time(), robot.get_period());
^
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:16:40: error: ‘class MyRobot’ has no member named ‘get_period’
cm.update(robot.get_time(), robot.get_period());
^
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:17:12: error: ‘class MyRobot’ has no member named ‘write’
robot.write();
^
/home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:18:12: error: too few arguments to function ‘unsigned int sleep(unsigned int)’
sleep();
^
In file included from /usr/include/boost/config/stdlib/libstdcpp3.hpp:77:0,
from /usr/include/boost/config.hpp:44,
from /usr/include/boost/smart_ptr/shared_ptr.hpp:17,
from /usr/include/boost/shared_ptr.hpp:17,
from /opt/ros/indigo/include/ros/forwards.h:37,
from /opt/ros/indigo/include/ros/node_handle.h:31,
from /opt/ros/indigo/include/controller_interface/controller_base.h:36,
from /opt/ros/indigo/include/controller_manager/controller_spec.h:41,
from /opt/ros/indigo/include/controller_manager/controller_manager.h:36,
from /home/sofia/catkin_ws/src/armbot_description/src/program1.cpp:1:
/usr/include/unistd.h:444:21: note: declared here
extern unsigned int sleep (unsigned int __seconds);
^
make[2]: *** [armbot_description/CMakeFiles/armbot_description.dir/src/program1.cpp.o] Error 1
make[1]: *** [armbot_description/CMakeFiles/armbot_description.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j2 -l2" failed
Asked by SofiaGr on 2017-03-30 04:45:08 UTC
Comments
The errors are not related to building the
ros_controls
package that you linked to. The errors are related to issues with executables in thearmbot_description
package. Where did this package come from? Do you have a link to the code or a relevant snippet?Asked by jarvisschultz on 2017-03-30 14:20:01 UTC
I have added the executables. Sorry for tha delay. Thanks in advance
Asked by SofiaGr on 2017-05-11 10:03:14 UTC
HI, I had some doubts with this as well. I am also trying to do something similar. Would appreciate some help
Asked by Jalashwa on 2017-08-15 16:48:44 UTC