Ask Your Question
0

test hardware interface without hardware

asked 2020-03-30 12:45:40 -0500

dinesh gravatar image

updated 2020-03-30 23:01:14 -0500

is it possible to test hardware interfce code without using the actual hardwre at the time? currently i tired this code but its not workign at all:

#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/joint_state_interface.h>
#include <hardware_interface/robot_hw.h>
#include <controller_manager/controller_manager.h>

class ROBOTHardwareInterface : public hardware_interface::RobotHW
{
public:
  ROBOTHardwareInterface() 
 { 
   // 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);

   hardware_interface::JointStateHandle state_handle_c("joint3", &pos[2], &vel[2], &eff[2]);
   jnt_state_interface.registerHandle(state_handle_c);

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

   hardware_interface::JointHandle pos_handle_c(jnt_state_interface.getHandle("joint3"), &cmd[2]);
   jnt_pos_interface.registerHandle(pos_handle_c);

   registerInterface(&jnt_pos_interface);
  }

  void read() { std::cout<<"read"<<std::endl; };
  void write() { std::cout<<"write"<<std::endl; };
  ros::Time get_time() {
      ros::Time t = ros::Time::now();
      return t; 
  }
  ros::Duration get_period() {
      ros::Duration duration(1);
      return duration; 
  }

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

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

    ROBOTHardwareInterface robot;
    controller_manager::ControllerManager cm(&robot);

    while (true)
    {
        robot.read();
        cm.update(robot.get_time(), robot.get_period());
        robot.write();
        sleep(1);
    }
}

configuration file ----------------- three_dof_planar_manipulator: # Publish all joint states ----------------------------------- joints_update: type: joint_state_controller/JointStateController publish_rate: 50

    # Position Controllers ---------------------------------------
    joint1:
      type: position_controllers/JointPositionController
      joint: joint1
      pid: {p: 1.0, i: 1.0, d: 0.0}
    joint2:
      type: position_controllers/JointPositionController
      joint: joint2
      pid: {p: 1.0, i: 1.0, d: 0.0}
    joint3:
      type: position_controllers/JointPositionController
      joint: joint3
      pid: {p: 1.0, i: 1.0, d: 0.0}

launch file ---------------- <launch>

  <rosparam file="$(find three_dof_planar_manipulator)/config/controllers.yaml" command="load"/>

  <arg name="model" default="$(find three_dof_planar_manipulator)/urdf/three_dof_planar_manipulator.urdf.xacro"/>
  <arg name="gui" default="true" />

  <param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
  <param name="use_gui" value="$(arg gui)"/>

  <node name="robot_hardware_interface" pkg="three_dof_planar_manipulator" type="robot_hardware_interface" output="screen"/>

  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" >
  </node>

  <node name="rviz" pkg="rviz" type="rviz"/>

  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen"
        args="
            /three_dof_planar_manipulator/joints_update
            /three_dof_planar_manipulator/joint1
            /three_dof_planar_manipulator/joint2
            /three_dof_planar_manipulator/joint3
        "/>
</launch>
edit retag flag offensive close merge delete

Comments

pedantic, but:

i tired this code but its not workign at all:

Please don't "tire" us by not telling us what "does not work" actually means.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-31 02:55:10 -0500 )edit

Also: is this not a duplicate of #q347800?

If it is: please don't post duplicates.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-31 02:55:57 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-03-31 06:13:54 -0500

dinesh gravatar image

updated 2020-03-31 06:16:05 -0500

Ok. finally after testing, dubugging, modifying and searchign through internet finally i found a good source/link to learn hardware interface in this page without depending on external hardware libraries and hardware.

edit flag offensive delete link more
0

answered 2020-03-30 14:50:52 -0500

You could start at gazebo_ros_control.

edit flag offensive delete link more

Comments

1

@Wilco Bonestroo: it would be good if you could expand your answer a little bit. As @dinesh is asking how to test a hardware_interface sub class without the actual hardware, and gazebo_ros_control actually provides a hardware_interface (ie: one which uses Gazebo as the hardware), what should he do with gazebo_ros_control?

gvdhoorn gravatar image gvdhoorn  ( 2020-03-30 15:01:57 -0500 )edit

Hmm. I think you are right @gvdhoorn. gazebo_ros_control only helps for simulating the whole hardware_interface but it does not help to test an own implementation of hardware_interface. Now I am not sure what @dinesh actually wants to test. You can observe the write function and manipulate the read function. However, you need to create some mockup for the hardware in that case.

Wilco Bonestroo gravatar image Wilco Bonestroo  ( 2020-03-30 15:18:57 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2020-03-30 12:45:40 -0500

Seen: 176 times

Last updated: Mar 31 '20