simulatedMotor.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 
19 #include <math.h>
20 
21 simulatedMotor::simulatedMotor(double lowLimit, double upLimit, double maxAcc, double maxVel)
22  : m_lastMove(0, 0, 0, 1, 1)
23 {
24  m_ll = lowLimit;
25  m_ul = upLimit;
26  m_amax = fabs(maxAcc);
27  m_vmax = fabs(maxVel);
28  // deb = NULL;
29  m_lastMove.start(); // Will be finished immediately, so that motor is at x=0, v=0
30  T0 = 0.0008;
31 }
32 
34 // Zunächst die Steuerungs-Funktionen: //
36 
38 void simulatedMotor::moveRamp(double targetAngle, double vmax, double amax)
39 {
40  double x = m_lastMove.pos();
41  double v = m_lastMove.vel();
42 
43  // Range Check:
44  if (targetAngle < m_ll)
45  targetAngle = m_ll;
46  else if (targetAngle > m_ul)
47  targetAngle = m_ul;
48 
49  double vm = fabs(vmax);
50  double am = fabs(amax);
51 
52  if (vm > m_vmax)
53  vm = m_vmax;
54  if (am > m_amax)
55  am = m_amax;
56 
57  m_lastMove = RampCommand(x, v, targetAngle, am, vm);
58  m_lastMove.start();
59 }
60 
62 void simulatedMotor::moveVel(double vel)
63 {
64  double x = m_lastMove.pos();
65  double v = m_lastMove.vel();
66 
67  double targetAngle = x;
68 
69  // Move with constant v is RampMove to the corresponding limit!
70  if (vel > 0)
71  targetAngle = m_ul;
72  else if (vel < 0)
73  targetAngle = m_ll;
74 
75  double vm = fabs(vel);
76  if (vm > m_vmax)
77  vm = m_vmax;
78 
79  double a = fabs(vel - v) / T0;
80 
81  m_lastMove = RampCommand(x, v, targetAngle, a, vm);
82  m_lastMove.start();
83 }
84 
86 void simulatedMotor::movePos(double pos)
87 {
88  double x = m_lastMove.pos();
89  double v = m_lastMove.vel();
90 
91  double targetAngle = pos;
92 
93  // Range Check:
94  if (targetAngle < m_ll)
95  targetAngle = m_ll;
96  else if (targetAngle > m_ul)
97  targetAngle = m_ul;
98 
99  double vm = fabs(m_vmax);
100 
101  // move backwards?
102  if (pos < x)
103  vm = -vm;
104 
105  double a = fabs(vm - v) / T0;
106 
107  m_lastMove = RampCommand(x, v, targetAngle, a, vm);
108  m_lastMove.start();
109 }
110 
113 {
114  // Stops immediately (would not be possible with a real motor)
115  double x = m_lastMove.pos();
116  double v = 0;
117 
118  m_lastMove = RampCommand(x, v, x, 1, 1);
119  m_lastMove.start();
120 }
121 
123 RampCommand simulatedMotor::getRampMove(double targetAngle, double vmax, double amax)
124 {
125  double x = m_lastMove.pos();
126  double v = m_lastMove.vel();
127 
128  // Range Check:
129  if (targetAngle < m_ll)
130  targetAngle = m_ll;
131  else if (targetAngle > m_ul)
132  targetAngle = m_ul;
133 
134  double vm = fabs(vmax);
135  double am = fabs(amax);
136 
137  if (vm > m_vmax)
138  vm = m_vmax;
139  if (am > m_amax)
140  am = m_amax;
141 
142  RampCommand rc(x, v, targetAngle, am, vm);
143  return rc;
144 }
RampCommand m_lastMove
virtual void stop()
Stops the motor immediately.
virtual RampCommand getRampMove(double targetAngle, double v, double a)
Get a representation of the rampMove that the motor WOULD execute if told so at the time of function ...
virtual void moveVel(double vel)
Moves the motor with the given velocity.
simulatedMotor(double lowLimit, double upLimit, double maxAcc, double maxVel)
virtual void movePos(double pos)
Moves the motor with the given velocity.
virtual void moveRamp(double targetAngle, double vmax, double amax)
any messages useful for debug are sent to this stream:
virtual double pos()
returns the planned position at time of function call (desired position)
Definition: moveCommand.h:75
virtual double vel()
returns the planned velocity at time of function call (desired velocitys)
Definition: moveCommand.h:84
virtual void start()
sets the starttime for the movement to the current time
Definition: moveCommand.h:57


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