Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #include "sr_ronex_transmissions/ronex_transmission.hpp"
00025 #include <sr_ronex_hardware_interface/mk2_gio_hardware_interface.hpp>
00026 #include <ros/ros.h>
00027 #include <ros_ethercat_model/robot_state.hpp>
00028 #include <gtest/gtest.h>
00029
00030 using namespace ronex;
00031
00032 TEST(RonexTransmission, constructor)
00033 {
00034
00035 ros::NodeHandle nh;
00036 std::string xml_string;
00037 ASSERT_TRUE( nh.getParam("robot_description", xml_string) );
00038 TiXmlDocument urdf_xml;
00039 urdf_xml.Parse(xml_string.c_str());
00040 ros_ethercat_model::RobotState state(0);
00041 TiXmlElement *root = urdf_xml.FirstChildElement("robot");
00042 ASSERT_TRUE(root != NULL);
00043
00044
00045 std::string name("/ronex/general_io/0");
00046 state.custom_hws_.insert(name, new ronex::GeneralIO());
00047 state.initXml(root);
00048
00049 ronex::GeneralIO* general_io = static_cast<ronex::GeneralIO*>( state.getCustomHW(name) );
00050 ASSERT_TRUE(general_io != NULL);
00051 }
00052
00053 TEST(RonexTransmission, propagateCommand)
00054 {
00055
00056 ros::NodeHandle nh;
00057 std::string xml_string;
00058 ASSERT_TRUE( nh.getParam("robot_description", xml_string) );
00059 TiXmlDocument urdf_xml;
00060 urdf_xml.Parse(xml_string.c_str());
00061 ros_ethercat_model::RobotState state(0);
00062 TiXmlElement *root = urdf_xml.FirstChildElement("robot");
00063 ASSERT_TRUE(root != NULL);
00064
00065
00066 std::string name("/ronex/general_io/0");
00067 state.custom_hws_.insert(name, new ronex::GeneralIO());
00068 state.initXml(root);
00069
00070 ronex::GeneralIO* general_io = static_cast<ronex::GeneralIO*>( state.getCustomHW(name) );
00071 ASSERT_TRUE(general_io != NULL);
00072 general_io->command_.pwm_clock_divider_ = 20;
00073 general_io->command_.pwm_.resize(6);
00074 general_io->state_.analogue_.resize(6);
00075 general_io->state_.digital_.resize(6);
00076 general_io->command_.pwm_.resize(6);
00077 general_io->command_.digital_.resize(6);
00078
00079
00080 state.joint_states_["joint1"].commanded_effort_ = 5.1;
00081
00082 general_io->command_.pwm_[1].period = 64000;
00083
00084 state.propagateJointEffortToActuatorEffort();
00085 state.propagateJointEffortToActuatorEffort();
00086
00087
00088 EXPECT_EQ(general_io->command_.pwm_[1].on_time_0, 3264);
00089 EXPECT_FALSE(general_io->command_.digital_[5]);
00090 }
00091
00092
00093 TEST(RonexTransmission, propagateState)
00094 {
00095
00096 ros::NodeHandle nh;
00097 std::string xml_string;
00098 ASSERT_TRUE( nh.getParam("robot_description", xml_string) );
00099 TiXmlDocument urdf_xml;
00100 urdf_xml.Parse(xml_string.c_str());
00101 ros_ethercat_model::RobotState state(0);
00102 TiXmlElement *root = urdf_xml.FirstChildElement("robot");
00103 ASSERT_TRUE(root != NULL);
00104
00105
00106 std::string name("/ronex/general_io/0");
00107 state.custom_hws_.insert(name, new ronex::GeneralIO());
00108 state.initXml(root);
00109
00110 ronex::GeneralIO* general_io = static_cast<ronex::GeneralIO*>( state.getCustomHW(name) );
00111 ASSERT_TRUE(general_io != NULL);
00112 general_io->command_.pwm_.resize(6);
00113 general_io->state_.analogue_.resize(6);
00114 general_io->state_.digital_.resize(6);
00115 general_io->command_.pwm_.resize(6);
00116
00117
00118 general_io->state_.analogue_[0] = 1.0;
00119 general_io->state_.analogue_[1] = 1.0;
00120
00121 state.propagateActuatorPositionToJointPosition();
00122 state.propagateActuatorPositionToJointPosition();
00123
00124 EXPECT_DOUBLE_EQ(state.joint_states_["joint1"].position_, 1.0);
00125 EXPECT_DOUBLE_EQ(state.joint_states_["joint1"].measured_effort_, 3.0);
00126 }
00127
00128 int main(int argc, char **argv)
00129 {
00130 testing::InitGoogleTest(&argc, argv);
00131 ros::init(argc, argv, "test_ronex_transmissions");
00132 ros::NodeHandle nh;
00133 return RUN_ALL_TESTS();
00134 }
00135
00136
00137
00138
00139
00140
00141