test_ronex_transmission.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 3.0 of the License, or (at your option) any later version.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library.
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   //get urdf from param
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   //add ronex
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   //get urdf from param
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   //add ronex
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   //setting effort for the joint
00080   state.joint_states_["joint1"].commanded_effort_ = 5.1;
00081 
00082   general_io->command_.pwm_[1].period =  64000;  //setting period too
00083 
00084   state.propagateJointEffortToActuatorEffort();
00085   state.propagateJointEffortToActuatorEffort();
00086 
00087   //reading the command from the RoNeX
00088   EXPECT_EQ(general_io->command_.pwm_[1].on_time_0, 3264);
00089   EXPECT_FALSE(general_io->command_.digital_[5]);  //Positive commanded effort should set direction pin to 0
00090 }
00091 
00092 
00093 TEST(RonexTransmission, propagateState)
00094 {
00095   //get urdf from param
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   //add ronex
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   //setting analogue data on the ronex for generating joint position / effort
00118   general_io->state_.analogue_[0] = 1.0; //position according to urdf
00119   general_io->state_.analogue_[1] = 1.0; //mapped to effort
00120   //propagating
00121   state.propagateActuatorPositionToJointPosition();
00122   state.propagateActuatorPositionToJointPosition();
00123   //reading the position and effort from the RoNeX
00124   EXPECT_DOUBLE_EQ(state.joint_states_["joint1"].position_, 1.0); //scale is 1.0, offset 0.0
00125   EXPECT_DOUBLE_EQ(state.joint_states_["joint1"].measured_effort_, 3.0); //scale is 2.0, offset 1.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; // init the node
00133     return RUN_ALL_TESTS();
00134 }
00135 
00136 /* For the emacs weenies in the crowd.
00137    Local Variables:
00138    c-basic-offset: 2
00139    End:
00140 */
00141 


sr_ronex_transmissions
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Fri Aug 28 2015 13:12:29