PowerCubeCtrl_OROCOS.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include "PowerCubeCtrl_OROCOS.h"
19 
20 using namespace RTT;
21 
22 PowerCubeCtrl_OROCOS::PowerCubeCtrl_OROCOS(std::string name, std::string xmlFile, int dof)
23 : TaskContext(name),
24  m_xmlFile(xmlFile),
25  m_dof(dof),
26  // initialize dataports:
27  m_in_Angles("in_Angles"),
28  m_in_Velocities("in_Velocities"),
29  m_in_Currents("in_Currents"),
30  m_out_Angles("out_Angles"), // note: initial value
31  m_out_Velocities("out_Velocities"), // note: initial value
32  // initialize method
33  m_stop_method("stop_movement",&PowerCubeCtrl_OROCOS::stopArm, this),
34  //m_moveJointSpace_method("moveJointSpace", &PowerCubeCtrl_OROCOS::moveJointSpace, this),
35  m_CanDev_prop("CanDev_n", "Can Device No.", 0),
36  m_CanBaud_prop("BaudRate", "Can Baud Rate", 1000),
37  m_dof_prop("DOF", "Degrees of Freedom", 7),
38  m_MaxVel_prop("Max_Vel", "Maximum Velocity", 0.5),
39  m_MaxAcc_prop("Max_Acc", "Maximum Acceleration", 0.8),
40  m_powercubectrl()
41 {
42  this->ports()->addPort( &m_in_Angles, "Port for desired Angles" );
43  m_in_Angles_connected = false;
44  this->ports()->addPort( &m_in_Velocities, "Port for desired velocities" );
46  this->ports()->addPort( &m_in_Currents, "Port for desired currents" );
48 
49  this->ports()->addPort( &m_out_Angles, "Port for current positions" );
50  this->ports()->addPort( &m_out_Velocities, "Port for current velocities" );
51 
52  this->methods()->addMethod(&m_stop_method, "Stop the Arm");
53  //this->methods()->addMethod(&m_moveJointSpace_method, "execute synchronized ramp commands");
54 
55  this->properties()->addProperty(&m_CanDev_prop);
56  this->properties()->addProperty(&m_CanBaud_prop);
57  this->properties()->addProperty(&m_dof_prop);
58  this->properties()->addProperty(&m_MaxVel_prop);
59  this->properties()->addProperty(&m_MaxAcc_prop);
60 
61  //m_mod_params.clear();
62 
63  m_modId_props.clear();
64  m_ul_props.clear();
65  m_ll_props.clear();
66  m_offset_props.clear();
67 
68  for (int i=0; i<m_dof; i++)
69  {
70  ostringstream os;
71 
72  os << "modId" << i+1;
73  m_modId_props.push_back( Property<int>( os.str(), os.str(), 0 ) );
74 
75  os.str(""); os.clear();
76  os << "upperLimit" << i+1;
77  m_ul_props.push_back( Property<double>( os.str(), os.str(), 0.0 ) );
78 
79  os.str(""); os.clear();
80  os << "lowerLimit" << i+1;
81  m_ll_props.push_back( Property<double>( os.str(), os.str(), 0.0 ) );
82 
83  os.str(""); os.clear();
84  os << "offset" << i+1;
85  m_offset_props.push_back( Property<double>( os.str(), os.str(), 0.0 ) );
86 
87  }
88 
89  m_mod_params.clear();
90  for (int i=0; i<m_dof; i++)
91  {
92  ostringstream os;
93  os << "modParams" << i+1;
94 
95  PropertyBag bag( os.str() );
96  bag.add( &m_modId_props[i] );
97  bag.add( &m_ul_props[i] );
98  bag.add( &m_ll_props[i] );
99  bag.add( &m_offset_props[i] );
100 
101  Property<PropertyBag> prop_of_bag( os.str(), "", bag);
102 
103  m_mod_params.push_back( prop_of_bag );
104  }
105 
106  for (int i=0; i<m_dof; i++)
107  {
108  this->properties()->addProperty( &(m_mod_params[i]) );
109  }
110  //m_stopped = false;
111 }
112 
114 {
115  stop();
116 }
117 
119 {
120  this->marshalling()->readProperties(m_xmlFile);
121 
122  // COPY PROPERTIES INTO STRUCT POWERCUBEPARAMETERS
123 
124  PowerCubeParameters pcparams;
125 
126  pcparams.modIds.resize(m_dof);
127  pcparams.upperlimits.resize(m_dof);
128  pcparams.lowerlimits.resize(m_dof);
129  pcparams.offsets.resize(m_dof);
130 
131  pcparams.dof=m_dof_prop.get();
132  pcparams.CanDevice=m_CanDev_prop.get();
133  pcparams.BaudRate=m_CanBaud_prop.get();
134  pcparams.maxVel=m_MaxVel_prop.get();
135  pcparams.maxAcc=m_MaxAcc_prop.get();
136 
137  int i;
138  if(m_dof != pcparams.dof)
139  {
140  log(Info) << "Degrees of freedom" << m_dof << "doesn't match with xml input DOF." << pcparams.dof << endlog();
141  return false;
142  }
143 
144  for (i=0 ; i< (m_dof) ; i++)
145  {
146  pcparams.modIds[i] = m_modId_props[i].get();
147  pcparams.upperlimits[i] = m_ul_props[i].get();
148  pcparams.lowerlimits[i] = m_ll_props[i].get();
149  pcparams.offsets[i] = m_offset_props[i].get();
150  }
151 
152 // int id = m_modId_props[3].get();
153 
154  if ( m_powercubectrl.Init(pcparams) )
155  {
156  log(Info) << "PowerCubeCtrl initialized successfully." << endlog();
157  return true;
158  }
159  else
160  {
161  log(Info) << "Error while initializing PowerCubeCtrl:" << endlog();
162  log(Info) << m_powercubectrl.getErrorMessage() << endlog();
163  return false;
164  }
165  return true;
166 }
167 
169 {
170  //m_stopped = true;
171  stopArm();
172 }
173 
175 {
176  if ( m_in_Angles.connected() )
177  {
178  // only one of the input ports should be used simultaniously
179  if ( m_in_Velocities.connected() || m_in_Currents.connected() ) {
180  log(Info) << "Error in PowerCubeSim.startHook(): more than one input port is connected!" << endlog();
181  return false;
182  }
183  m_in_Angles_connected = true;
184  log(Info) << "PowerCubeSim succesfully detected connection at in_Angles" << endlog();
185  //m_stopped = false;
186  return true;
187  }
188  if ( m_in_Velocities.connected() )
189  {
190  // only one of the input ports should be used simultaniously
191  if ( m_in_Angles.connected() || m_in_Currents.connected() ) {
192  log(Info) << "Error in PowerCubeSim.startHook(): more than one input port is connected!" << endlog();
193  return false;
194  }
196  log(Info) << "PowerCubeSim succesfully detected connection at in_Velocities" << endlog();
197  //m_stopped = false;
198  return true;
199  }
200  if ( m_in_Currents.connected() )
201  {
202  log(Info) << "Error, port \"setCur_R\" is connected to PowerCubeSim_OROCOS.\"";
203  log(Info) << "Current movement is not yet supported by PowerCubeSim." << endlog();
204  return false;
205  /*
206  // only one of the input ports should be used simultaniously
207  if ( m_in_Angles.connected() || m_in_Velocities.connected() ) {
208  log(Info) << "Error in PowerCubeSim.startHook(): more than one input port is connected!" << endlog();
209  return false;
210  }
211  m_in_Current_connected = true;
212  //m_stopped = false;
213  return true;
214  */
215  }
216  else
217  {
218  log(Info) << "No Input port is connected, PowerCubeSim will only return the current state." << endlog();
219  }
220  return true;
221 }
222 
224 {
225  // log(Info) << "updateHook is being executed." << endlog();
226 
227  // Execute desired movements:
228  if ( m_in_Angles_connected )
229  {
230  std::vector<double> angles_desired(7);
231  angles_desired = m_in_Angles.Get();
232  m_powercubectrl.MovePos( angles_desired );
233  }
234 
236  {
237  std::vector<double> vel_desired(7);
238  vel_desired = m_in_Velocities.Get();
239  m_powercubectrl.MoveVel( vel_desired );
240  }
242  {
243  std::vector<double> currents_desired(7);
244  currents_desired = m_in_Currents.Get();
245  m_powercubectrl.MoveCur( currents_desired );
246  }
247 
248  // get current angles & velocities
249  std::vector<double> curConfig(7);
250  m_powercubectrl.getConfig(curConfig);
251  m_out_Angles.Set(curConfig);
252 
253  std::vector<double> curVelocities(7);
254  m_powercubectrl.getJointVelocities(curVelocities);
255  m_out_Velocities.Set(curVelocities);
256 }
257 
259 {
260  //stop
262  return true;
263 }
264 
265 bool PowerCubeCtrl_OROCOS::moveJointSpace(std::vector<double> target)
266 {
267  return m_powercubectrl.MoveJointSpaceSync(target);
268 }
269 
271 {
272  return !m_powercubectrl.statusMoving();
273 }
RTT::Method< bool(void)> m_stop_method
RTT::Property< int > m_CanDev_prop
bool getJointVelocities(std::vector< double > &result)
get the current joint velocities (Rad/s)
RTT::ReadDataPort< std::vector< double > > m_in_Currents
RTT::ReadDataPort< std::vector< double > > m_in_Velocities
std::vector< RTT::Property< double > > m_ul_props
PowerCubeCtrl_OROCOS(std::string name, std::string file, int dof)
bool MoveVel(const std::vector< double > &velocities)
Moves all cubes by the given velocities.
RTT::ReadDataPort< std::vector< double > > m_in_Angles
RTT::Property< double > m_MaxAcc_prop
std::vector< RTT::Property< double > > m_offset_props
RTT::Property< int > m_dof_prop
bool Init(PowerCubeCtrlParams *params)
Initializing.
std::vector< RTT::Property< int > > m_modId_props
Info
std::vector< RTT::Property< double > > m_ll_props
RTT::WriteDataPort< std::vector< double > > m_out_Velocities
bool statusMoving()
Returns true if any of the Joints are still moving.
bool moveJointSpace(std::vector< double > target)
std::string getErrorMessage() const
Get error message.
Definition: PowerCubeCtrl.h:74
bool Stop()
Stops the Manipulator immediately.
RTT::Property< int > m_CanBaud_prop
std::vector< RTT::Property< RTT::PropertyBag > > m_mod_params
RTT::Property< double > m_MaxVel_prop
bool MoveJointSpaceSync(const std::vector< double > &angles)
Send position goals to powercubes, the final angles will be reached simultaneously.
RTT::WriteDataPort< std::vector< double > > m_out_Angles


schunk_powercube_chain
Author(s): Florian Weisshardt
autogenerated on Mon Nov 25 2019 03:48:21