simulatedArm.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 
20 #include <math.h>
21 
22 #define PSIM_CHECK_INITIALIZED() \
23  if (isInitialized() == false) \
24  { \
25  m_ErrorMessage.assign("Manipulator not initialized."); \
26  return false; \
27  }
28 
30 {
31  std::cerr << "==============Starting Simulated Powercubes\n";
32  m_DOF = 0;
33  m_Initialized = false;
34  m_motors.clear();
35 }
36 
38 {
39  // nothing to do...
40  ;
41 }
42 
44 {
45  m_DOF = params->GetNumberOfDOF();
46  ;
47 
48  double vmax = 1.0;
49  double amax = 1.5;
50 
51  setMaxVelocity(vmax);
52  setMaxAcceleration(amax);
53  m_maxVel.resize(m_DOF);
54  m_maxAcc.resize(m_DOF);
55 
56  std::vector<double> ul(m_DOF);
57  std::vector<double> ll(m_DOF);
58  ul = params->GetUpperLimits();
59  ll = params->GetLowerLimits();
60  m_maxVel = params->GetMaxVel();
61  m_maxAcc = params->GetMaxAcc();
62 
63  for (int i = 0; i < m_DOF; i++)
64  {
65  m_motors.push_back(simulatedMotor(ll[i], ul[i], amax, vmax));
66  }
67  std::cerr << "===========Initializing Simulated Powercubes\n";
68  m_Initialized = true;
69  return true;
70 }
71 
74 {
75  for (int i = 0; i < m_DOF; i++)
76  m_motors[i].stop();
77  return true;
78 }
79 
80 bool simulatedArm::MoveJointSpaceSync(const std::vector<double>& target)
81 {
82  std::cerr << "======================TUTUTUTUT\n";
84 
85  std::vector<double> acc(m_DOF);
86  std::vector<double> vel(m_DOF);
87 
88  double TG = 0;
89 
90  try
91  {
92  // Ermittle Joint, der bei max Geschw. und Beschl. am längsten braucht:
93 
94  std::vector<double> posnow;
95  posnow.resize(m_DOF);
96  if (getConfig(posnow) == false)
97  return false;
98 
99  std::vector<double> velnow;
100  velnow.resize(m_DOF);
101  if (getJointVelocities(velnow) == false)
102  return false;
103 
104  std::vector<double> times(m_DOF);
105 
106  for (int i = 0; i < m_DOF; i++)
107  {
108  RampCommand rm(posnow[i], velnow[i], target[i], m_maxAcc[i], m_maxVel[i]);
109  times[i] = rm.getTotalTime();
110  }
111 
112  // determine the joint index that has the greates value for time
113  int furthest = 0;
114 
115  double max = times[0];
116 
117  for (int i = 1; i < m_DOF; i++)
118  {
119  if (times[i] > max)
120  {
121  max = times[i];
122  furthest = i;
123  }
124  }
125 
126  RampCommand rm_furthest(posnow[furthest], velnow[furthest], target[furthest], m_maxAcc[furthest],
127  m_maxVel[furthest]);
128 
129  double T1 = rm_furthest.T1();
130  double T2 = rm_furthest.T2();
131  double T3 = rm_furthest.T3();
132 
133  // Gesamtzeit:
134  TG = T1 + T2 + T3;
135 
136  // Jetzt Geschwindigkeiten und Beschl. für alle:
137  acc[furthest] = m_maxAcc[furthest];
138  vel[furthest] = m_maxVel[furthest];
139 
140  for (int i = 0; i < m_DOF; i++)
141  {
142  if (i != furthest)
143  {
144  double a;
145  double v;
146  // a und v berechnen:
147  RampCommand::calculateAV(posnow[i], velnow[i], target[i], TG, T3, m_maxAcc[i], m_maxVel[i], a, v);
148 
149  acc[i] = a;
150  vel[i] = v;
151  }
152  }
153  }
154  catch (...)
155  {
156  m_ErrorMessage.assign("Problem during calculation of a and av.");
157  return false;
158  }
159 
160  // Jetzt Bewegung starten:
161  for (int i = 0; i < m_DOF; i++)
162  {
163  std::cout << "moving motor " << i << ": " << target[i] << ": " << vel[i] << ": " << acc[i] << "\n";
164  m_motors[i].moveRamp(target[i], vel[i], acc[i]);
165  }
166 
167  return true;
168 }
169 
170 bool simulatedArm::MoveVel(const std::vector<double>& Vel)
171 {
173 
174  // std::cerr << ".";
175  // std::cerr << "Vels: ";
176  for (int i = 0; i < m_DOF; i++)
177  {
178  // std::cerr << Vel[i] << " ";
179  m_motors[i].moveVel(Vel[i]);
180  }
181  // std::cerr << "\n";
182  return true;
183 }
184 
185 bool simulatedArm::MovePos(const std::vector<double>& Pos)
186 {
188 
189  for (int i = 0; i < m_DOF; i++)
190  m_motors[i].movePos(Pos[i]);
191 
192  return true;
193 }
194 
196 // Funktionen zum setzen von Parametern: //
198 
200 bool simulatedArm::setMaxVelocity(double radpersec)
201 {
203 
204  m_maxVel.resize(m_DOF);
205 
206  for (int i = 0; i < m_DOF; i++)
207  {
208  m_maxAcc[i] = radpersec;
209  m_motors[i].setMaxVelocity(radpersec);
210  }
211 
212  return true;
213 }
214 
215 bool simulatedArm::setMaxVelocity(const std::vector<double>& radpersec)
216 {
218 
219  m_maxAcc = radpersec;
220 
221  for (int i = 0; i < m_DOF; i++)
222  m_motors[i].setMaxVelocity(radpersec[i]);
223 
224  return true;
225 }
226 
228 bool simulatedArm::setMaxAcceleration(double radPerSecSquared)
229 {
231 
232  for (int i = 0; i < m_DOF; i++)
233  m_motors[i].setMaxAcceleration(radPerSecSquared);
234 
235  return true;
236 }
237 
238 bool simulatedArm::setMaxAcceleration(const std::vector<double>& radPerSecSquared)
239 {
241 
242  for (int i = 0; i < m_DOF; i++)
243  m_motors[i].setMaxAcceleration(radPerSecSquared[i]);
244 
245  return true;
246 }
247 
249 // hier die Funktionen zur Statusabfrage: //
251 
253 bool simulatedArm::getConfig(std::vector<double>& result)
254 {
256 
257  result.resize(m_DOF);
258  for (int i = 0; i < m_DOF; i++)
259  {
260  result[i] = m_motors[i].getAngle();
261  }
262 
263  return true;
264 }
265 
267 bool simulatedArm::getJointVelocities(std::vector<double>& result)
268 {
270 
271  result.resize(m_DOF);
272  for (int i = 0; i < m_DOF; i++)
273  {
274  result[i] = m_motors[i].getVelocity();
275  }
276 
277  return true;
278 }
279 
283 {
285 
286  for (int i = 0; i < m_DOF; i++)
287  {
288  if (m_motors[i].statusMoving())
289  return true;
290  }
291  return false;
292 }
293 
296 {
298 
299  for (int i = 0; i < m_DOF; i++)
300  {
301  if (m_motors[i].statusDec())
302  return true;
303  }
304  return false;
305 }
306 
309 {
311 
312  for (int i = 0; i < m_DOF; i++)
313  {
314  if (m_motors[i].statusAcc())
315  return true;
316  }
317  return false;
318 }
bool statusDec()
Returns true if any of the Joints are decelerating.
virtual ~simulatedArm()
std::vector< double > GetLowerLimits()
Gets the lower angular limits (rad) for the joints.
bool getConfig(std::vector< double > &result)
Returns the current Joint Angles.
bool MovePos(const std::vector< double > &)
moves all cubes to the given position
bool setMaxAcceleration(double radPerSecSquared)
Sets the maximum angular acceleration (rad/s^2) for the Joints, use with care! A Value of 0...
bool Init(PowerCubeCtrlParams *params)
std::string m_ErrorMessage
Definition: simulatedArm.h:122
virtual double T3()
Definition: moveCommand.h:163
std::vector< double > GetMaxAcc()
Gets the max. angular accelerations (rad/s^2) for the joints.
bool setMaxVelocity(double radpersec)
Sets the maximum angular velocity (rad/s) for the Joints, use with care! A Value of 0...
virtual double getTotalTime()
returns the planned total time for the movement (in seconds)
bool m_Initialized
Definition: simulatedArm.h:121
std::vector< simulatedMotor > m_motors
Definition: simulatedArm.h:124
bool getJointVelocities(std::vector< double > &result)
Returns the current Angular velocities (Rad/s)
static void calculateAV(double x0, double v0, double xtarget, double time, double T3, double amax, double vmax, double &a, double &v)
Calculate the necessary a and v of a rampmove, so that the move will take the desired time...
bool Stop()
current movement currently not supported in simulation
#define PSIM_CHECK_INITIALIZED()
bool statusMoving()
Returns true if any of the Joints are still moving Should also return true if Joints are accelerating...
virtual double T1()
Return the times of the different phases of the ramp move.
Definition: moveCommand.h:155
bool statusAcc()
Returs true if any of the Joints are accelerating.
virtual double T2()
Definition: moveCommand.h:159
bool MoveVel(const std::vector< double > &)
Moves all cubes by the given velocities.
std::vector< double > GetMaxVel()
Gets the max. angular velocities (rad/s) for the joints.
std::vector< double > m_maxVel
Definition: simulatedArm.h:126
std::vector< double > GetUpperLimits()
Gets the upper angular limits (rad) for the joints.
std::vector< double > m_maxAcc
Definition: simulatedArm.h:127
bool MoveJointSpaceSync(const std::vector< double > &Angle)
same as MoveJointSpace, but final angles should by reached simultaniously! Returns the time that the ...
Parameters for cob_powercube_chain.


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