test hardware interface without hardware
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>
pedantic, but:
Please don't "tire" us by not telling us what "does not work" actually means.
Also: is this not a duplicate of #q347800?
If it is: please don't post duplicates.