ev3_joint_settings_params.h
1 /*
2  * This file (ev3_joint_params.h) is part of h4r_ev3_manager.
3  * Date: 16.11.2015
4  *
5  * Author: Christian Holl
6  * http://github.com/Hacks4ROS
7  *
8  * h4r_ev3_manager is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * h4r_ev3_manager is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with h4r_outport_setup. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef EV3_JOINT_SETTINGS_PARAMS_H_
24 #define EV3_JOINT_SETTINGS_PARAMS_H_
25 
26 #include <string>
27 #include <ros/ros.h>
28 
29 #include "../../../h4r_ev3_manager/include/h4r_ev3_joint_setup/ev3_joint_settings.h"
30 
31 
32 namespace ev3_control
33 {
34 
35  inline bool getJointSettings(const std::string& joint_name,
36  Ev3JointSettings::Ev3HwSettings& settings)
37  {
38 
39 
40 
41 
42  ros::NodeHandle setup_nh;
43  const std::string joint_setup = "Ev3devJoints/"+joint_name;
44  try
45  {
46  if (!setup_nh.hasParam(joint_setup))
47  {
48  ROS_WARN_STREAM("No ev3 port settings found for ev3 joint '" << joint_name <<" using velocity mode and automatic port mode");
49  return false;
50  }
51  setup_nh = ros::NodeHandle(setup_nh, joint_setup);
52  }
53  catch (const ros::InvalidNameException& e)
54  {
55  ROS_ERROR_STREAM(e.what());
56  return false;
57  }
58 
59  ROS_INFO_STREAM("<--------------EV3 Joint "<<joint_name<<"---------------->");
60 
61 
62  std::string mode;
63  if(setup_nh.getParam("mode", mode))
64  {
65  if(mode=="position")
66  {
67  settings.joint_mode=Ev3JointSettings::EV3_JOINT_POSITION;
68  }
69  else if(mode=="velocity")
70  {
71  settings.joint_mode=Ev3JointSettings::EV3_JOINT_VELOCITY;
72  }
73  else
74  {
75  ROS_WARN_STREAM("Unknown Mode for Ev3 Joint: "<<mode<<" expecting velocity");
76  settings.joint_mode=Ev3JointSettings::EV3_JOINT_VELOCITY;
77  }
78  ROS_INFO_STREAM("Joint control mode: "<<mode);
79  }
80 
81  // Driver Name
82  if(!setup_nh.getParam("driver_name", settings.driver_name))
83  {
84  settings.driver_name="";
85  }
86  else
87  {
88  ROS_INFO_STREAM("Driver_name: "<<settings.driver_name);
89  }
90 
91  //PID
92  settings.pid.clear();
93  if(!setup_nh.getParam("speed_pid", settings.pid))
94  {
95  settings.pid.resize(3);
96  ROS_INFO("No PID Settings found, using standard Kp:1000 Ki:60, Kd:0");
97  settings.pid[0]=1000;
98  settings.pid[1]=60;
99  settings.pid[2]=0;
100  }
101  else
102  {
103  if(settings.pid.size()!=3)
104  {
105  ROS_ERROR("PID Settings error! Wrong amount of settings, required exactly 3 for P, I and D");
106  return false;
107  }
108  else
109  {
110  ROS_INFO_STREAM("P: "<<settings.pid[0]<<" I: "<<settings.pid[1]<<" D: "<<settings.pid[2]);
111  }
112  }
113  //PID
114  ROS_INFO_STREAM("</-------------EV3 Joint "<<joint_name<<"---------------->");
115 
116  return true;
117  }
118 }
119 
120 
121 #endif /* EV3_JOINT_SETTINGS_PARAMS_H_ */