ev3_joint_settings_interface.h
1 /*
2  * This file (ev3_joint_settings_interface.h) is part of h4r_ev3_manager.
3  * Date: 19.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_ev3_joint_setting. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef EV3_JOINT_SETTINGS_INTERFACE_H
24 #define EV3_JOINT_SETTINGS_INTERFACE_H
25 
26 
27 #include <iostream>
28 #include <ros/duration.h>
29 #include <ros/ros.h>
30 #include <boost/shared_ptr.hpp>
31 #include <list>
32 #include <hardware_interface/controller_info.h>
33 #include <hardware_interface/joint_command_interface.h>
34 #include <hardware_interface/internal/resource_manager.h>
35 
36 #include <ev3dev.h>
37 #include "../../../h4r_ev3_manager/include/h4r_ev3_joint_setup/ev3_joint_settings.h"
38 #include "../../../h4r_ev3_manager/include/h4r_ev3_joint_setup/ev3_joint_settings_exception.h"
39 #include "../../../h4r_ev3_manager/include/h4r_ev3_joint_setup/ev3_joint_settings_params.h"
40 
41 
42 
43 namespace ev3_control
44 {
45 using namespace hardware_interface;
46 using namespace std;
47 
48 
50 {
51 public:
52 
53 
54 
56  :settings_(0){}
57 
59  const JointHandle& jh,
60  Ev3JointSettings *settings)
61  :jh_(jh)
62  ,settings_(settings)
63  {}
64 
65  std::string getName() const
66  {
67  return jh_.getName();
68  }
69 
70  Ev3JointSettings &getSettings()
71  {
72  return *settings_;
73  }
74 
75 
76 private:
77 
78 
79  Ev3JointSettings *settings_;
80  JointHandle jh_;
81 };
82 
83 class Ev3JointInterface : public ResourceManager<Ev3JointInterfaceHandle>
84 {
85 public:
86  Ev3JointInterfaceHandle getHandle(const std::string& name)
87  {
88  // Rethrow exception with a meaningful type
89  try
90  {
91  return this->ResourceManager<Ev3JointInterfaceHandle>::getHandle(name);
92  }
93  catch(const std::logic_error& e)
94  {
95  throw Ev3JointInterfaceException(e.what());
96  }
97  }
98 
99  bool ControllerTestChange(const std::list<ControllerInfo> &start_list) const
100  {
101  return true;
102  }
103 
104 
105  bool ControllerChange(const std::list<ControllerInfo> &start_list)
106  {
107  ROS_INFO("Controller Change");
108  for (std::list<ControllerInfo>::const_iterator it = start_list.begin(); it != start_list.end(); it++)
109  {
110  for (std::set<std::string>::const_iterator res = it->resources.begin(); res != it->resources.end(); res++)
111  {
112  ROS_INFO_STREAM(it->type<<" requests Joint "<<it->name<<" "<<*res);
113 
114  try
115  {
116  Ev3JointInterfaceHandle handle=getHandle(*res);
118 
119  handle.getSettings().port.setMotorCommand(Ev3Strings::EV3MOTORCOMMANDS_RESET);
120  getJointSettings(*res, ev3settings);
121  ROS_INFO("----------------------------------------------<");
122  handle.getSettings().load(ev3settings,true);
123  }
124  catch(const Ev3JointInterfaceException& e)
125  {
126  ROS_ERROR_STREAM("Did not find handle: "<<*res);
127  }
128  }
129  }
130  return true;
131  }
132 
133 
134 };
135 
136 
137 
138 }
139 
140 #endif /* EV3_JOINT_SETTINGS_INTERFACE_H */
Definition: ev3_joint_settings.h:29
Definition: ev3_joint_settings_interface.h:83
Definition: ev3_joint_settings_interface.h:49
Definition: ev3_joint_settings.h:41
bool setMotorCommand(Ev3Strings::Ev3MotorCommands command)
Definition: H4REv3Port.h:339
Definition: ev3_joint_settings_exception.h:33