Robotics StackExchange | Archived questions

problem using hardware interface

I am trying to implement a hardware interface for my robot.

Right now i'm tyring to make a hardware interface for rrbotrobot as a testing purpose. But i'm not able to list the command parametrs like that when i use rrbotrobot in simulation. i.e launching the robot in gazebo. To launch the hardwareinterface alsong with the controllers and controller manager. github repository
i'm using thsi files: rrbot
control.yaml

rrbot:
  # Publish all joint states -----------------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50  

  # Position Controllers ---------------------------------------
  joint1_position_controller:
    type: effort_controllers/JointPositionController
    joint: joint1
    pid: {p: 100.0, i: 0.01, d: 10.0}
  joint2_position_controller:
    type: effort_controllers/JointPositionController
    joint: joint2
    pid: {p: 100.0, i: 0.01, d: 10.0}

rrbot_control.launch

<?xml version="1.0"?>

<launch>

  <!-- Load joint controller configurations from YAML file to parameter server -->
  <rosparam file="$(find rrbot_control)/config/rrbot_control.yaml" command="load"/>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
    args="-urdf -model rrbot -param robot_description"/>


  <!-- launch our hardware interface -->
    <node pkg="rrbot_control"
          type="rrbot_control"
          name="rrbot_control" output="screen" clear_params="true"
          required="true"/>


  <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
    output="screen" ns="/rrbot" args="joint_state_controller
                      joint1_position_controller
                      joint2_position_controller"/>

  <!-- convert joint states to TF transforms for rviz, etc -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
    respawn="false" output="screen">
    <remap from="/joint_states" to="/rrbot/joint_states" />
  </node>

</launch>

rrbot_control.cpp

#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/joint_state_interface.h>
#include <hardware_interface/robot_hw.h>
#include <ros/ros.h>
#include <controller_manager/controller_manager.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);

   hardware_interface::JointStateHandle state_handle_b("joint2", &pos[1], &vel[1], &eff[1]);
   jnt_state_interface.registerHandle(state_handle_b);

   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);

   hardware_interface::JointHandle pos_handle_b(jnt_state_interface.getHandle("joint2"), &cmd[1]);
   jnt_pos_interface.registerHandle(pos_handle_b);

   registerInterface(&jnt_pos_interface);
  }

  void read() { std::cout<<"read"<<std::endl; };
  void write() { std::cout<<"write"<<std::endl; }; 

private:
  hardware_interface::JointStateInterface jnt_state_interface;
  hardware_interface::PositionJointInterface jnt_pos_interface;
  double cmd[2];
  double pos[2];
  double vel[2];
  double eff[2];
};

int main(int argc, char **argv)
{
  ros::init(argc, argv, "rrbot");
  ros::NodeHandle nh;  

  MyRobot robot;
  controller_manager::ControllerManager cm(&robot);
ros::Duration d(0.5);
  while (ros::ok())
  {
     robot.read();
     //cm.update(ros::Time::now().toSec(),d);
     robot.write();
     sleep(1);
  }
}

CMakeLIsts.txt

cmake_minimum_required(VERSION 2.8.3)

project(rrbot_control)

find_package(catkin REQUIRED
  roscpp
  urdf
  std_msgs
  message_generation
  hardware_interface
  controller_manager
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  include
)


catkin_package()

install(DIRECTORY config
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

install(DIRECTORY launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

add_executable(${PROJECT_NAME} src/rrbot_control.cpp)
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) 

When i run the command :

roslaunch rrbotcontrol rrbotcontrol

i'm not getting any error. but when i type the cmd rostopic list i can't find any ros controllers related parametrs like that when i launch the same robot in gazebo.

Asked by dinesh on 2020-03-29 07:09:58 UTC

Comments

Hi @dinesh,

You may need to launch Gazebo, at least the Gzserver to properly control the robot. If you do not launch Gazebo there is no hardware interface to read and write.

Asked by Weasfas on 2020-03-29 08:03:23 UTC

i am trying to implement hardwre interface for the real robot. right now i'm testing its core functality.

Asked by dinesh on 2020-03-29 08:52:54 UTC

Well, it does not matter, real or simulated. You may need a hardware interface to read and write. In case of Gazebo the communication is already provided but for a real platform you should implement the hardware communication with the real robot or at least implement a layer with the drivers running in the robot to communicate with ROS_control.

Asked by Weasfas on 2020-03-29 09:47:56 UTC

Answers