motorcontrollers.h
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifndef MOTORCONTROLLERS_H
21 #define MOTORCONTROLLERS_H
22 
23 #include "worldsimconfig.h"
24 #include "phyjoint.h"
25 #include "ownable.h"
26 #include <QVector>
27 
28 namespace farsa {
29 
30 class World;
31 
38 class FARSA_WSIM_API wPID {
39 public:
41  wPID();
45  double pidloop( double currentvalue );
48  void reset();
50  double p_gain;
52  double i_gain;
54  double d_gain;
56  double acc_ff;
58  double fri_ff;
60  double vel_ff;
62  double bias;
64  double accel_r;
66  double setpt;
68  double min;
70  double max;
72  double slew;
73 private:
74  double this_target;
75  double next_target;
76  double integral;
77  double last_error;
78  double last_output;
79 };
80 
90 class FARSA_WSIM_API MotorController : public Ownable {
91 public:
95  MotorController( World* world );
97  virtual ~MotorController();
99  virtual void update() = 0;
101  bool isEnabled() {
102  return enabled;
103  };
105  void setEnabled( bool b ) {
106  enabled = b;
107  };
110  return worldv;
111  };
112 
113 private:
115  World* worldv;
117  bool enabled;
118 
120  MotorController(const MotorController& other);
121 
123  MotorController& operator=(const MotorController& other);
124 };
125 
140 void FARSA_WSIM_API wheeledRobotsComputeKinematicMovement(wMatrix &mtr, real leftWheelVelocity, real rightWheelVelocity, real wheelr, real axletrack, real timestep);
141 
163 bool FARSA_WSIM_API wheeledRobotsComputeWheelsSpeed(const wMatrix& start, const wMatrix& end, real wheelr, real axletrack, real timestep, real& leftWheelVelocity, real& rightWheelVelocity);
164 
167 class FARSA_WSIM_API WheelMotorController : public MotorController {
168 public:
172  WheelMotorController( QVector<PhyDOF*> wheels, World* world );
174  virtual ~WheelMotorController();
176  QVector<PhyDOF*>& wheels() {
177  return motorsv;
178  };
180  virtual void update();
184  void setSpeeds( QVector<double> speeds );
188  void setSpeeds( double sp1, double sp2 );
192  void getSpeeds( QVector<double>& speeds ) const;
196  void getSpeeds( double& sp1, double& sp2 ) const;
200  void getDesiredSpeeds( QVector<double>& speeds ) const;
204  void getDesiredSpeeds( double& sp1, double& sp2 ) const;
208  void setSpeedLimits( QVector<double> minSpeeds, QVector<double> maxSpeeds );
212  void setSpeedLimits( double minSpeed1, double minSpeed2, double maxSpeed1, double maxSpeed2 );
216  void getSpeedLimits( QVector<double>& minSpeeds, QVector<double>& maxSpeeds ) const;
220  void getSpeedLimits( double& minSpeed1, double& minSpeed2, double& maxSpeed1, double& maxSpeed2 ) const;
223  void setMaxTorque( double maxTorque );
228  double getMaxTorque() const;
229 private:
231  QVector<PhyDOF*> motorsv;
233  QVector<double> desiredVel;
235  QVector<double> minVel;
237  QVector<double> maxVel;
238 };
239 
240 class PhyMarXbot;
241 class PhyFixed;
242 
285 {
286 public:
291  enum Status {
292  Open,
293  HalfClosed,
294  Closed
295  };
296 
297 public:
305 
310 
314  virtual void update();
315 
323  bool attachmentDeviceEnabled() const;
324 
331  void setMaxVelocity(double speed);
332 
340  double getMaxVelocity() const;
341 
348  void setDesiredPosition(double pos);
349 
355  double getDesiredPosition() const;
356 
362  double getPosition() const;
363 
370  void setDesiredVelocity(double vel);
371 
377  double getDesiredVelocity() const;
378 
384  double getVelocity() const;
385 
393  void setDesiredStatus(Status status);
394 
401  {
402  return m_desiredStatus;
403  }
404 
411  {
412  return m_status;
413  }
414 
424  bool attachmentPossible() const
425  {
426  return (tryToAttach() != NULL);
427  }
428 
434  bool attachedToRobot() const
435  {
436  return (m_attachedRobot != NULL);
437  }
438 
447  {
448  return m_attachedRobot;
449  }
450 
458  const PhyMarXbot* attachedRobot() const
459  {
460  return m_attachedRobot;
461  }
462 
469  bool otherAttachedToUs() const
470  {
471  return !m_otherAttachedRobots.isEmpty();
472  }
473 
480  QVector<PhyMarXbot*> otherAttachedRobots()
481  {
482  return m_otherAttachedRobots;
483  }
484 
485 private:
495  PhyMarXbot* tryToAttach() const;
496 
501  void attachmentDeviceAboutToBeDestroyed();
502 
506  PhyMarXbot* const m_robot;
507 
511  Status m_status;
512 
516  Status m_desiredStatus;
517 
524  PhyJoint* m_joint;
525 
531  PhyMarXbot* m_attachedRobot;
532 
538  QVector<PhyMarXbot*> m_otherAttachedRobots;
539 
544  friend class PhyMarXbot;
545 };
546 
547 } // end namespace farsa
548 
549 #endif
wPID class
The class modelling the motor for the attachment device of the MarXbot.
The MarXbot robot.
Definition: phymarxbot.h:55
QVector< PhyMarXbot * > otherAttachedRobots()
Returns the list of all robots that are attached to us.
bool otherAttachedToUs() const
Returns true if there are robots that are attached to us.
double fri_ff
'F' friction feed forward
Status
The possible status of the attachment device. See class description for more information.
double p_gain
'P' proportional gain
MotorController Class.
World class.
Definition: world.h:223
The base for all class that can have (and can be) an owner.
Definition: ownable.h:37
PhyMarXbot * attachedRobot()
Returns the robot to which we are attached.
PhyJoint class.
Definition: phyjoint.h:359
double max
'M' maximum output value
Status getStatus() const
Returns the current status of the attachment device.
void setEnabled(bool b)
Enable/Disable this motorcontroller.
double acc_ff
'A' acceleration feed forward
World * world()
return the world
bool isEnabled()
return true is if enable (hence if it is on)
Status getDesiredStatus() const
Returns the desired status of the attachment device.
double accel_r
'R' acceleration rate
float real
double vel_ff
'V' velocity feed forward
double min
'N' minimum output value
QVector< PhyDOF * > & wheels()
return the wheels controlled
double d_gain
'D' derivative gain
bool attachmentPossible() const
Returns true if this robot is near enough to another robot to attach to it.
bool attachedToRobot() const
Returns true if we are attached to another robot.
double slew
'W' maximum slew rate
const PhyMarXbot * attachedRobot() const
Returns the robot to which we are attached (const version)
Dedicated controller for wheeled robots.
double i_gain
'I' integral gain
double bias
'B' bias
double setpt
'S' set point