MotorInterface.h

00001
00002 /***************************************************************************
00003  *  MotorInterface.h - Fawkes BlackBoard Interface - MotorInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2007  Martin Liebenberg, Tim Niemueller
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __INTERFACES_MOTORINTERFACE_H_
00025 #define __INTERFACES_MOTORINTERFACE_H_
00026 
00027 #include <interface/interface.h>
00028 #include <interface/message.h>
00029 #include <interface/field_iterator.h>
00030
00031 namespace fawkes {
00032
00033 class MotorInterface : public Interface
00034 {
00035  /// @cond INTERNALS
00036  INTERFACE_MGMT_FRIENDS(MotorInterface)
00037  /// @endcond
00038  public:
00039   /* constants */
00040   static const unsigned int MOTOR_ENABLED;
00041   static const unsigned int MOTOR_DISABLED;
00042   static const unsigned int DRIVE_MODE_RPM;
00043   static const unsigned int DRIVE_MODE_TRANS;
00044   static const unsigned int DRIVE_MODE_ROT;
00045   static const unsigned int DRIVE_MODE_TRANS_ROT;
00046   static const unsigned int DRIVE_MODE_ORBIT;
00047   static const unsigned int DRIVE_MODE_LINE_TRANS_ROT;
00048
00049  private:
00050   /** Internal data storage, do NOT modify! */
00051   typedef struct {
00052     unsigned int motor_state; /**< 
00053       The current state of the motor.
00054      */
00055     unsigned int drive_mode; /**< 
00056       The current drive mode of the motor.
00057      */
00058     unsigned int controller; /**< 
00059      The ID of the controller. The controller ID is the instance serial of the sending
00060      interface. Only from this interface instance command messages are accepted.
00061      */
00062     int right_rpm; /**< 
00063       RPM of the motor on the right front of the robot.
00064      */
00065     int rear_rpm; /**< 
00066       RPM of motor on the rear of the robot.
00067      */
00068     int left_rpm; /**< 
00069       RPM of the motor on the left front of the robot.
00070      */
00071     float odometry_path_length; /**< 
00072       The actual length of the robot's trajectory since the last ResetOdometry.
00073      */
00074     float odometry_position_x; /**< 
00075       The actual position of the robot relative to the position at the last ResetOdometry.
00076      */
00077     float odometry_position_y; /**< 
00078       The actual position of the robot relative to the position at the last ResetOdometry.
00079      */
00080     float odometry_orientation; /**< 
00081       The actual orientation of the robot relative to the orientation at the last ResetOdometry.
00082      */
00083     float vx; /**< 
00084       VX of the robot in m/s. Forward.
00085      */
00086     float vy; /**< 
00087       VY of the robot in m/s. Left.
00088      */
00089     float omega; /**< 
00090       Rotation speed of the robot in rad/s.
00091      */
00092     char controller_thread_name[64]; /**< 
00093      The name of the controlling thread, for easier debugging. This is informative only
00094      and actually two threads may share an interface instance (although this should be
00095      avoided since the interface locking has to be reproduced for these threads then).
00096    */
00097   } MotorInterface_data_t;
00098
00099   MotorInterface_data_t *data;
00100
00101  public:
00102   /* messages */
00103   class SetMotorStateMessage : public Message
00104   {
00105    private:
00106     /** Internal data storage, do NOT modify! */
00107     typedef struct {
00108       unsigned int motor_state; /**< 
00109       The new motor state to set. Use the MOTOR_* constants.
00110      */
00111     } SetMotorStateMessage_data_t;
00112
00113     SetMotorStateMessage_data_t *data;
00114
00115    public:
00116     SetMotorStateMessage(const unsigned int ini_motor_state);
00117     SetMotorStateMessage();
00118     ~SetMotorStateMessage();
00119
00120     SetMotorStateMessage(const SetMotorStateMessage *m);
00121     /* Methods */
00122     unsigned int motor_state() const;
00123     void set_motor_state(const unsigned int new_motor_state);
00124     size_t maxlenof_motor_state() const;
00125     virtual Message * clone() const;
00126   };
00127
00128   class AcquireControlMessage : public Message
00129   {
00130    private:
00131     /** Internal data storage, do NOT modify! */
00132     typedef struct {
00133       unsigned int controller; /**< 
00134      The ID of the controller. The controller ID is the instance serial of the sending
00135      interface. Only from this interface instance command messages are accepted.
00136      */
00137       char controller_thread_name[64]; /**< 
00138      The name of the controlling thread, for easier debugging. This is informative only
00139      and actually two threads may share an interface instance (although this should be
00140      avoided since the interface locking has to be reproduced for these threads then).
00141    */
00142     } AcquireControlMessage_data_t;
00143
00144     AcquireControlMessage_data_t *data;
00145
00146    public:
00147     AcquireControlMessage(const unsigned int ini_controller, const char * ini_controller_thread_name);
00148     AcquireControlMessage();
00149     ~AcquireControlMessage();
00150
00151     AcquireControlMessage(const AcquireControlMessage *m);
00152     /* Methods */
00153     unsigned int controller() const;
00154     void set_controller(const unsigned int new_controller);
00155     size_t maxlenof_controller() const;
00156     char * controller_thread_name() const;
00157     void set_controller_thread_name(const char * new_controller_thread_name);
00158     size_t maxlenof_controller_thread_name() const;
00159     virtual Message * clone() const;
00160   };
00161
00162   class ResetOdometryMessage : public Message
00163   {
00164    public:
00165     ResetOdometryMessage();
00166     ~ResetOdometryMessage();
00167
00168     ResetOdometryMessage(const ResetOdometryMessage *m);
00169     /* Methods */
00170     virtual Message * clone() const;
00171   };
00172
00173   class DriveRPMMessage : public Message
00174   {
00175    private:
00176     /** Internal data storage, do NOT modify! */
00177     typedef struct {
00178       float front_right; /**< Rotation in RPM of the right front wheel. */
00179       float front_left; /**< Rotation in RPM of the left front wheel. */
00180       float rear; /**< Rotation in RPM of the rear wheel. */
00181     } DriveRPMMessage_data_t;
00182
00183     DriveRPMMessage_data_t *data;
00184
00185    public:
00186     DriveRPMMessage(const float ini_front_right, const float ini_front_left, const float ini_rear);
00187     DriveRPMMessage();
00188     ~DriveRPMMessage();
00189
00190     DriveRPMMessage(const DriveRPMMessage *m);
00191     /* Methods */
00192     float front_right() const;
00193     void set_front_right(const float new_front_right);
00194     size_t maxlenof_front_right() const;
00195     float front_left() const;
00196     void set_front_left(const float new_front_left);
00197     size_t maxlenof_front_left() const;
00198     float rear() const;
00199     void set_rear(const float new_rear);
00200     size_t maxlenof_rear() const;
00201     virtual Message * clone() const;
00202   };
00203
00204   class GotoMessage : public Message
00205   {
00206    private:
00207     /** Internal data storage, do NOT modify! */
00208     typedef struct {
00209       float x; /**< X distance in m. */
00210       float y; /**< Y distance in m. */
00211       float phi; /**< Angle relative to current angle in rad. */
00212       float time_sec; /**< When to reach the desired location. */
00213     } GotoMessage_data_t;
00214
00215     GotoMessage_data_t *data;
00216
00217    public:
00218     GotoMessage(const float ini_x, const float ini_y, const float ini_phi, const float ini_time_sec);
00219     GotoMessage();
00220     ~GotoMessage();
00221
00222     GotoMessage(const GotoMessage *m);
00223     /* Methods */
00224     float x() const;
00225     void set_x(const float new_x);
00226     size_t maxlenof_x() const;
00227     float y() const;
00228     void set_y(const float new_y);
00229     size_t maxlenof_y() const;
00230     float phi() const;
00231     void set_phi(const float new_phi);
00232     size_t maxlenof_phi() const;
00233     float time_sec() const;
00234     void set_time_sec(const float new_time_sec);
00235     size_t maxlenof_time_sec() const;
00236     virtual Message * clone() const;
00237   };
00238
00239   class TransMessage : public Message
00240   {
00241    private:
00242     /** Internal data storage, do NOT modify! */
00243     typedef struct {
00244       float vx; /**< Speed in X direction in m/s. */
00245       float vy; /**< Speed in Y direction in m/s. */
00246     } TransMessage_data_t;
00247
00248     TransMessage_data_t *data;
00249
00250    public:
00251     TransMessage(const float ini_vx, const float ini_vy);
00252     TransMessage();
00253     ~TransMessage();
00254
00255     TransMessage(const TransMessage *m);
00256     /* Methods */
00257     float vx() const;
00258     void set_vx(const float new_vx);
00259     size_t maxlenof_vx() const;
00260     float vy() const;
00261     void set_vy(const float new_vy);
00262     size_t maxlenof_vy() const;
00263     virtual Message * clone() const;
00264   };
00265
00266   class RotMessage : public Message
00267   {
00268    private:
00269     /** Internal data storage, do NOT modify! */
00270     typedef struct {
00271       float omega; /**< Angle rotation in rad/s. */
00272     } RotMessage_data_t;
00273
00274     RotMessage_data_t *data;
00275
00276    public:
00277     RotMessage(const float ini_omega);
00278     RotMessage();
00279     ~RotMessage();
00280
00281     RotMessage(const RotMessage *m);
00282     /* Methods */
00283     float omega() const;
00284     void set_omega(const float new_omega);
00285     size_t maxlenof_omega() const;
00286     virtual Message * clone() const;
00287   };
00288
00289   class TransRotMessage : public Message
00290   {
00291    private:
00292     /** Internal data storage, do NOT modify! */
00293     typedef struct {
00294       float vx; /**< Speed in X direction in m/s. */
00295       float vy; /**< Speed in Y direction in m/s. */
00296       float omega; /**< Angle rotation in rad/s. */
00297     } TransRotMessage_data_t;
00298
00299     TransRotMessage_data_t *data;
00300
00301    public:
00302     TransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega);
00303     TransRotMessage();
00304     ~TransRotMessage();
00305
00306     TransRotMessage(const TransRotMessage *m);
00307     /* Methods */
00308     float vx() const;
00309     void set_vx(const float new_vx);
00310     size_t maxlenof_vx() const;
00311     float vy() const;
00312     void set_vy(const float new_vy);
00313     size_t maxlenof_vy() const;
00314     float omega() const;
00315     void set_omega(const float new_omega);
00316     size_t maxlenof_omega() const;
00317     virtual Message * clone() const;
00318   };
00319
00320   class OrbitMessage : public Message
00321   {
00322    private:
00323     /** Internal data storage, do NOT modify! */
00324     typedef struct {
00325       float px; /**< Point's X coordinate to orbit. */
00326       float py; /**< Point's Y coordinate to orbit. */
00327       float omega; /**< Angular speed around point in rad/s. */
00328     } OrbitMessage_data_t;
00329
00330     OrbitMessage_data_t *data;
00331
00332    public:
00333     OrbitMessage(const float ini_px, const float ini_py, const float ini_omega);
00334     OrbitMessage();
00335     ~OrbitMessage();
00336
00337     OrbitMessage(const OrbitMessage *m);
00338     /* Methods */
00339     float px() const;
00340     void set_px(const float new_px);
00341     size_t maxlenof_px() const;
00342     float py() const;
00343     void set_py(const float new_py);
00344     size_t maxlenof_py() const;
00345     float omega() const;
00346     void set_omega(const float new_omega);
00347     size_t maxlenof_omega() const;
00348     virtual Message * clone() const;
00349   };
00350
00351   class LinTransRotMessage : public Message
00352   {
00353    private:
00354     /** Internal data storage, do NOT modify! */
00355     typedef struct {
00356       float vx; /**< Speed for translation in X direction in m/s. */
00357       float vy; /**< Speed for translation in Y direction in m/s. */
00358       float omega; /**< Rotational speed in rad/s. */
00359     } LinTransRotMessage_data_t;
00360
00361     LinTransRotMessage_data_t *data;
00362
00363    public:
00364     LinTransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega);
00365     LinTransRotMessage();
00366     ~LinTransRotMessage();
00367
00368     LinTransRotMessage(const LinTransRotMessage *m);
00369     /* Methods */
00370     float vx() const;
00371     void set_vx(const float new_vx);
00372     size_t maxlenof_vx() const;
00373     float vy() const;
00374     void set_vy(const float new_vy);
00375     size_t maxlenof_vy() const;
00376     float omega() const;
00377     void set_omega(const float new_omega);
00378     size_t maxlenof_omega() const;
00379     virtual Message * clone() const;
00380   };
00381
00382   virtual bool message_valid(const Message *message) const;
00383  private:
00384   MotorInterface();
00385   ~MotorInterface();
00386
00387  public:
00388   /* Methods */
00389   unsigned int motor_state() const;
00390   void set_motor_state(const unsigned int new_motor_state);
00391   size_t maxlenof_motor_state() const;
00392   unsigned int drive_mode() const;
00393   void set_drive_mode(const unsigned int new_drive_mode);
00394   size_t maxlenof_drive_mode() const;
00395   int right_rpm() const;
00396   void set_right_rpm(const int new_right_rpm);
00397   size_t maxlenof_right_rpm() const;
00398   int rear_rpm() const;
00399   void set_rear_rpm(const int new_rear_rpm);
00400   size_t maxlenof_rear_rpm() const;
00401   int left_rpm() const;
00402   void set_left_rpm(const int new_left_rpm);
00403   size_t maxlenof_left_rpm() const;
00404   float odometry_path_length() const;
00405   void set_odometry_path_length(const float new_odometry_path_length);
00406   size_t maxlenof_odometry_path_length() const;
00407   float odometry_position_x() const;
00408   void set_odometry_position_x(const float new_odometry_position_x);
00409   size_t maxlenof_odometry_position_x() const;
00410   float odometry_position_y() const;
00411   void set_odometry_position_y(const float new_odometry_position_y);
00412   size_t maxlenof_odometry_position_y() const;
00413   float odometry_orientation() const;
00414   void set_odometry_orientation(const float new_odometry_orientation);
00415   size_t maxlenof_odometry_orientation() const;
00416   float vx() const;
00417   void set_vx(const float new_vx);
00418   size_t maxlenof_vx() const;
00419   float vy() const;
00420   void set_vy(const float new_vy);
00421   size_t maxlenof_vy() const;
00422   float omega() const;
00423   void set_omega(const float new_omega);
00424   size_t maxlenof_omega() const;
00425   unsigned int controller() const;
00426   void set_controller(const unsigned int new_controller);
00427   size_t maxlenof_controller() const;
00428   char * controller_thread_name() const;
00429   void set_controller_thread_name(const char * new_controller_thread_name);
00430   size_t maxlenof_controller_thread_name() const;
00431   virtual Message * create_message(const char *type) const;
00432
00433   virtual void copy_values(const Interface *other);
00434
00435 };
00436
00437 } // end namespace fawkes
00438
00439 #endif