Can't load custom controller

Hi, I have a problem in quiz 2.
I’m working on local in a virtual machine because it seems that the my simulation environment for the quiz does’t work.

I have spawned my robot with success for the part 1.
Now when it comes to the part 2 I’m facing the following problem when I launch:

Could not load controller 'joint2_position_controller' because controller type 'project_controller/PositionController' does not exist.
[ERROR] [1668903995.359815020, 0.186000000]: Use 'rosservice call controller_manager/list_controller_types' to get the available types

follow the code:
custom_controller.cpp

#include <controller_interface/controller.h>
#include <hardware_interface/joint_command_interface.h>
#include <pluginlib/class_list_macros.h>

namespace controller_ns {

class PositionController : public controller_interface::Controller<
                               hardware_interface::EffortJointInterface> {
public:
  bool init(hardware_interface::EffortJointInterface *hw, ros::NodeHandle &n) {
    std::string my_joint;
    if (!n.getParam("joint", my_joint)) {
      ROS_ERROR("Could not find joint name");
      return false;
    }

    joint_ = hw->getHandle(my_joint); // throws on failure
    return true;
  }

  void update(const ros::Time &time, const ros::Duration &period) {
    double error = setpoint_ - joint_.getPosition();
    joint_.setCommand(error * gain_);
  }

  void starting(const ros::Time &time) {}
  void stopping(const ros::Time &time) {}

private:
  hardware_interface::JointHandle joint_;
  static constexpr double gain_ = 2.25;
  static constexpr double setpoint_ = 1.00;
};
PLUGINLIB_EXPORT_CLASS(controller_ns::PositionController,
                       controller_interface::ControllerBase);
} // namespace controller_ns

plugin file

<?xml version="1.0"?>
<library path="lib/libmy_controller_lib">
  <class name="project_controller/PositionController" 
         type="controller_ns::PositionController"           
         base_class_type="controller_interface::ControllerBase" />
</library>

ur5_controller_custom.yaml

ur5:
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50  

  joint1_position_controller:
    type: position_controllers/JointPositionController
    joint: shoulder_pan_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

  joint2_position_controller:
    type: project_controller/PositionController 
    joint: shoulder_lift_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

  joint3_position_controller:
    type: position_controllers/JointPositionController
    joint: elbow_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

  joint4_position_controller:
    type: position_controllers/JointPositionController
    joint: wrist_1_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

  joint5_position_controller:
    type: position_controllers/JointPositionController
    joint: wrist_2_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

  joint6_position_controller:
    type: position_controllers/JointPositionController
    joint: wrist_3_joint
    pid: {p: 10.0, i: 0.01, d: 10.0}

quiz_control_custom.launch

<launch>

  <include file="$(find gazebo_ros)/launch/empty_world.launch"> 
        <!-- <arg name="world_name" value="worlds/mud.world"/> -->
  </include>
<!--
  <group ns = "/ur5">
-->
    <rosparam command = "load" file = "$(find project_controller)/config/ur5_controller_custom.yaml" />
    
    <param name = "robot_description" command = "$(find xacro)/xacro --inorder '$(find project_controller)/urdf/ur5_robot.urdf.xacro'" />
    <arg name = "x" default = "0" />
    <arg name = "y" default = "0" />
    <arg name = "z" default = "0.5" />

    <!-- spawn the robot in the world  -->
    <node name = "mybot_spawn" pkg = "gazebo_ros" type = "spawn_model" output = "screen"
      args = "-urdf -param robot_description -model ur5_robot -x $(arg x) -y $(arg y) -z $(arg z)" />



    <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
      output="screen" ns = "/ur5" args="--namespace=/ur5
                                        joint1_position_controller 
                                        joint2_position_controller
                                        joint3_position_controller
                                        joint4_position_controller
                                        joint5_position_controller
                                        joint6_position_controller 
                                        joint_state_controller
                                        --timeout 60"/>


    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
      respawn="false" output="screen">
      <remap from="/joint_states" to="/ur5/joint_states" />
    </node>

    <!-- rqt spawner-->
    <node name = "rqt_reconfigure" pkg = "rqt_reconfigure" type = "rqt_reconfigure" />
    <node name = "rqt_publisher" pkg = "rqt_publisher" type = "rqt_publisher" />

<!--
  </group>
-->
</launch>

Could anyone tell me what I’m doing wrong?
I have updated package.xml and CMakeLists.txt accordly
Thank you

Hi @Francesco_Rizzotti,

one possible cause is that ROS can’t find the package with your custom controller. Have you build your workspace and sourced all terminals where you execute your launch files?

Additionally could you please paste the content of your CMakeLists.txt and package.xml files here?

Cheers,

Roberto

Hi @rzegers , thank you for your reply.
Every joint works, exept the joint2_position_controller: in config file as follows:

joint2_position_controller:
   type: project_controller/PositionController 
   joint: shoulder_lift_joint
   pid: {p: 10.0, i: 0.01, d: 10.0}

The package for the quiz2 is in the same workspace of the quiz1.
I have source the code in my ws with source devel/setup.bash and build the package.xml with catkin_make
her my package file:

<?xml version="1.0"?>
<package format="2">
  <name>project_controller</name>
  <version>0.0.0</version>
  <description>The project_controller package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  <maintainer email="ros@todo.todo">ros</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>TODO</license>


  <!-- Url tags are optional, but multiple are allowed, one per tag -->
  <!-- Optional attribute type can be: website, bugtracker, or repository -->
  <!-- Example: -->
  <!-- <url type="website">http://wiki.ros.org/project_controller</url> -->


  <!-- Author tags are optional, multiple are allowed, one per tag -->
  <!-- Authors do not have to be maintainers, but could be -->
  <!-- Example: -->
  <!-- <author email="jane.doe@example.com">Jane Doe</author> -->


  <!-- The *depend tags are used to specify dependencies -->
  <!-- Dependencies can be catkin packages or system dependencies -->
  <!-- Examples: -->
  <!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
  <!--   <depend>roscpp</depend> -->
  <!--   Note that this is equivalent to the following: -->
  <!--   <build_depend>roscpp</build_depend> -->
  <!--   <exec_depend>roscpp</exec_depend> -->
  <!-- Use build_depend for packages you need at compile time: -->
  <!--   <build_depend>message_generation</build_depend> -->
  <!-- Use build_export_depend for packages you need in order to build against this package: -->
  <!--   <build_export_depend>message_generation</build_export_depend> -->
  <!-- Use buildtool_depend for build tool packages: -->
  <!--   <buildtool_depend>catkin</buildtool_depend> -->
  <!-- Use exec_depend for packages you need at runtime: -->
  <!--   <exec_depend>message_runtime</exec_depend> -->
  <!-- Use test_depend for packages you need only for testing: -->
  <!--   <test_depend>gtest</test_depend> -->
  <!-- Use doc_depend for packages you need only for building documentation: -->
  <!--   <doc_depend>doxygen</doc_depend> -->
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>controller_interface</build_depend>
  <build_depend>hardware_interface</build_depend>
  <build_depend>pluginlib</build_depend>
  <build_depend>roscpp</build_depend>
  <build_export_depend>controller_interface</build_export_depend>
  <build_export_depend>hardware_interface</build_export_depend>
  <build_export_depend>pluginlib</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <exec_depend>controller_interface</exec_depend>
  <exec_depend>hardware_interface</exec_depend>
  <exec_depend>pluginlib</exec_depend>
  <exec_depend>roscpp</exec_depend>


  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->
    <controller_interface plugin="${prefix}/custom_controller_plugins.xml"/>

  </export>
</package>

and here my CMa[keLists.txt

cmake_minimum_required(VERSION 3.0.2)

project(project_controller)

## 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

controller_interface

hardware_interface

pluginlib

roscpp

)

## System dependencies are found with CMake's conventions

# find_package(Boost REQUIRED COMPONENTS system)

## Uncomment this if the package has a setup.py. This macro ensures

## modules and global scripts declared therein get installed

## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html

# catkin_python_setup()

################################################

## Declare ROS messages, services and actions ##

################################################

## To declare and build messages, services or actions from within this

## package, follow these steps:

## * Let MSG_DEP_SET be the set of packages whose message types you use in

## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).

## * In the file package.xml:

## * add a build_depend tag for "message_generation"

## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET

## * If MSG_DEP_SET isn't empty the following dependency has been pulled in

## but can be declared for certainty nonetheless:

## * add a exec_depend tag for "message_runtime"

## * In this file (CMakeLists.txt):

## * add "message_generation" and every package in MSG_DEP_SET to

## find_package(catkin REQUIRED COMPONENTS ...)

## * add "message_runtime" and every package in MSG_DEP_SET to

## catkin_package(CATKIN_DEPENDS ...)

## * uncomment the add_*_files sections below as needed

## and list every .msg/.srv/.action file to be processed

## * uncomment the generate_messages entry below

## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder

# add_message_files(

# FILES

# Message1.msg

# Message2.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 # Or other packages containing msgs

# )

################################################

## Declare ROS dynamic reconfigure parameters ##

################################################

## To declare and build dynamic reconfigure parameters within this

## package, follow these steps:

## * In the file package.xml:

## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"

## * In this file (CMakeLists.txt):

## * add "dynamic_reconfigure" to

## find_package(catkin REQUIRED COMPONENTS ...)

## * uncomment the "generate_dynamic_reconfigure_options" section below

## and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder

# generate_dynamic_reconfigure_options(

# cfg/DynReconf1.cfg

# cfg/DynReconf2.cfg

# )

###################################

## catkin specific configuration ##

###################################

## The catkin_package macro generates cmake config files for your package

## Declare things to be passed to dependent projects

## INCLUDE_DIRS: uncomment this if your package contains header files

## LIBRARIES: libraries you create in this project that dependent projects also need

## CATKIN_DEPENDS: catkin_packages dependent projects also need

## DEPENDS: system dependencies of this project that dependent projects also need

catkin_package(

# INCLUDE_DIRS include

# LIBRARIES project_controller

# CATKIN_DEPENDS controller_interface hardware_interface pluginlib roscpp

# DEPENDS system_lib

)

###########

## Build ##

###########

## Specify additional locations of header files

## Your package locations should be listed before other locations

include_directories(

include

${catkin_INCLUDE_DIRS}

)

## Declare a C++ library

# add_library(${PROJECT_NAME}

# src/${PROJECT_NAME}/project_controller.cpp

# )

add_compile_options(-std=c++11)

add_library(my_controller_lib src/custom_controller.cpp)

target_link_libraries(my_controller_lib ${catkin_LIBRARIES})

## Add cmake target dependencies of the library

## as an example, code may need to be generated before libraries

## either from message generation or dynamic reconfigure

# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable

## With catkin_make all packages are built within a single CMake context

## The recommended prefix ensures that target names across packages don't collide

# add_executable(${PROJECT_NAME}_node src/project_controller_node.cpp)

## Rename C++ executable without prefix

## The above recommended prefix causes long target names, the following renames the

## target back to the shorter version for ease of user use

## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"

# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable

## same as for the library above

# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against

# target_link_libraries(${PROJECT_NAME}_node

# ${catkin_LIBRARIES}

# )

#############

## Install ##

#############

# all install targets should use catkin DESTINATION variables

# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation

## in contrast to setup.py, you can choose the destination

# catkin_install_python(PROGRAMS

# scripts/my_python_script

# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

# )

## Mark executables for installation

## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html

# install(TARGETS ${PROJECT_NAME}_node

# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

# )

## Mark libraries for installation

## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html

# install(TARGETS ${PROJECT_NAME}

# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}

# )

## Mark cpp header files for installation

# install(DIRECTORY include/${PROJECT_NAME}/

# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}

# FILES_MATCHING PATTERN "*.h"

# PATTERN ".svn" EXCLUDE

# )

## Mark other files for installation (e.g. launch and bag files, etc.)

# install(FILES

# # myfile1

# # myfile2

# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}

# )

#############

## Testing ##

#############

## Add gtest based cpp test target and link libraries

# catkin_add_gtest(${PROJECT_NAME}-test test/test_project_controller.cpp)

# if(TARGET ${PROJECT_NAME}-test)

# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})

# endif()

## Add folders to be run by python nosetests

# catkin_add_nosetests(test)

Furthermore, my account on the construct seems to not loading the simulation environment.
Is it possible to check it out?

Thank you
Francesco

good morning @rzegers
do you have any update about that? I’m stucked in to figure it out what’s going on…

Hello @Francesco_Rizzotti,

I am checking throught the unit and verifying that you haven’t missed any step and that everything is properly implemented in the code. One of the checks is to verify that the filenames match with the code, for instance what is the name for the XML plugin file that you are using? Please post it here so that I can check against what is inside the tags inside the package.xml file.

Also, very important as part of the debugging, please post the output of the command shown below since it will tell us if the controller was installed successfully.

rospack plugins --attrib=plugin controller_interface

Cheers,

Roberto

Hello @Francesco_Rizzotti,
I have loaded Unit 7 and the simulation takes a while to load, but then it’s ok.

Could you please provide a screenshot of how your simulation environment on “The Construct” looks like?

This is a screenshot of how the unit and simulation looks like at my end:

Regards,

Roberto