20 #ifndef MOTORCONTROLLERS_H
21 #define MOTORCONTROLLERS_H
23 #include "worldsimconfig.h"
30 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 #pragma GCC diagnostic ignored "-Wunused-parameter"
37 #ifdef FARSA_USE_YARP_AND_ICUB
38 #include <yarp/dev/ControlBoardInterfaces.h>
39 #include <yarp/dev/ControlBoardPid.h>
42 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
43 #pragma GCC diagnostic pop
45 #pragma GCC diagnostic warning "-Wunused-parameter"
59 class FARSA_WSIM_API
wPID {
66 double pidloop(
double currentvalue );
120 virtual void update() = 0;
180 #ifdef FARSA_USE_YARP_AND_ICUB
181 ,
public yarp::dev::DeviceDriver,
public yarp::dev::IPositionControl,
public yarp::dev::IVelocityControl,
public yarp::dev::IControlMode,
public yarp::dev::IEncoders,
public yarp::dev::IControlLimits,
public yarp::dev::IControlLimitsRaw
200 bool setEnableLimitsRaw(
int axis,
bool b );
202 virtual void update();
210 #ifdef FARSA_USE_YARP_AND_ICUB
212 virtual bool close( );
214 virtual bool configure( yarp::os::Searchable &config );
216 virtual bool open( yarp::os::Searchable &config );
222 virtual bool getAxes(
int *ax);
224 virtual bool getRefAcceleration(
int j,
double *acc);
226 virtual bool getRefAccelerations(
double *accs);
228 virtual bool setRefAcceleration(
int j,
double acc);
230 virtual bool setRefAccelerations(
const double *accs);
232 virtual bool stop(
int j);
239 virtual bool checkMotionDone(
int j,
bool *flag);
241 virtual bool checkMotionDone(
bool *flag);
243 virtual bool getRefSpeed(
int j,
double *ref);
245 virtual bool getRefSpeeds(
double *spds);
247 virtual bool positionMove(
int j,
double ref);
249 virtual bool positionMove(
const double *refs);
251 virtual bool relativeMove(
int j,
double delta);
253 virtual bool relativeMove(
const double *deltas);
255 virtual bool setPositionMode();
257 virtual bool setRefSpeed(
int j,
double sp);
259 virtual bool setRefSpeeds(
const double *spds);
264 virtual bool setVelocityMode();
266 virtual bool velocityMove(
int j,
double sp);
268 virtual bool velocityMove(
const double *sp);
273 virtual bool getControlMode(
int j,
int* mode );
275 virtual bool getControlModes(
int* modes );
281 virtual bool setOpenLoopMode(
int j);
283 virtual bool setPositionMode(
int j );
285 virtual bool setTorqueMode(
int j );
287 virtual bool setVelocityMode(
int j );
292 virtual bool getEncoder(
int j,
double *v );
294 virtual bool getEncoders(
double *encs);
296 virtual bool getEncoderAcceleration(
int j,
double *spds );
298 virtual bool getEncoderAccelerations(
double *accs );
300 virtual bool getEncoderSpeed(
int j,
double *sp );
302 virtual bool getEncoderSpeeds(
double *spds );
304 virtual bool resetEncoder(
int j );
306 virtual bool resetEncoders();
308 virtual bool setEncoder(
int j,
double val );
310 virtual bool setEncoders(
const double *vals );
315 virtual bool getLimits(
int axis,
double *
min,
double *
max );
317 virtual bool setLimits(
int axis,
double min,
double max );
322 virtual bool getLimitsRaw(
int axis,
double *
min,
double *
max );
324 virtual bool setLimitsRaw(
int axis,
double min,
double max );
328 QVector<PhyDOF*> motorsv;
334 QVector<int> controlModes;
336 QVector<real> refsacc;
342 QVector<real> refsvel;
344 QVector<real> xfx0, x0, dx0, t, T;
350 QVector<wPID*> pos_pids;
352 QVector<real> lastErrors, lastIs, lastTorques;
354 real fromRawPosition(
int i );
356 real toRawPosition( real noRawPos,
int i );
361 QVector<real> desiredVel;
363 QVector<wPID*> vel_pids;
368 QVector<double> loLimits;
370 QVector<double> hiLimits;
387 void wheeledRobotsComputeKinematicMovement(wMatrix &mtr, real leftWheelVelocity, real rightWheelVelocity, real wheelr, real axletrack, real timestep);
404 virtual void update();
408 void setSpeeds( QVector<double> speeds );
412 void setSpeeds(
double sp1,
double sp2 );
416 void getSpeeds( QVector<double>& speeds );
420 void getSpeeds(
double& sp1,
double& sp2 );
424 void setSpeedLimits( QVector<double> minSpeeds, QVector<double> maxSpeeds );
428 void setSpeedLimits(
double minSpeed1,
double minSpeed2,
double maxSpeed1,
double maxSpeed2 );
432 void getSpeedLimits( QVector<double>& minSpeeds, QVector<double>& maxSpeeds );
436 void getSpeedLimits(
double& minSpeed1,
double& minSpeed2,
double& maxSpeed1,
double& maxSpeed2 );
439 QVector<PhyDOF*> motorsv;
441 QVector<double> desiredVel;
443 QVector<double> minVel;
445 QVector<double> maxVel;
522 virtual void update();
531 bool attachmentDeviceEnabled()
const;
539 void setMaxVelocity(
double speed);
548 double getMaxVelocity()
const;
556 void setDesiredPosition(
double pos);
563 double getDesiredPosition()
const;
570 double getPosition()
const;
578 void setDesiredVelocity(
double vel);
585 double getDesiredVelocity()
const;
592 double getVelocity()
const;
601 void setDesiredStatus(Status status);
610 return m_desiredStatus;
632 bool attachmentPossible()
const
634 return (tryToAttach() != NULL);
642 bool attachedToRobot()
const
644 return (m_attachedRobot != NULL);
656 return m_attachedRobot;
668 return m_attachedRobot;
677 bool otherAttachedToUs()
const
679 return !m_otherAttachedRobots.isEmpty();
688 QVector<PhyMarXbot*> otherAttachedRobots()
690 return m_otherAttachedRobots;
709 void attachmentDeviceAboutToBeDestroyed();
724 Status m_desiredStatus;
746 QVector<PhyMarXbot*> m_otherAttachedRobots;