Fawkes API Fawkes Development Version
|
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 uint32_t MOTOR_ENABLED; 00041 static const uint32_t MOTOR_DISABLED; 00042 static const uint32_t DRIVE_MODE_RPM; 00043 static const uint32_t DRIVE_MODE_TRANS; 00044 static const uint32_t DRIVE_MODE_ROT; 00045 static const uint32_t DRIVE_MODE_TRANS_ROT; 00046 static const uint32_t DRIVE_MODE_ORBIT; 00047 static const uint32_t DRIVE_MODE_LINE_TRANS_ROT; 00048 00049 private: 00050 #pragma pack(push,4) 00051 /** Internal data storage, do NOT modify! */ 00052 typedef struct { 00053 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00054 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00055 uint32_t motor_state; /**< 00056 The current state of the motor. 00057 */ 00058 uint32_t drive_mode; /**< 00059 The current drive mode of the motor. 00060 */ 00061 int32_t right_rpm; /**< 00062 RPM of the motor on the right front of the robot. 00063 */ 00064 int32_t rear_rpm; /**< 00065 RPM of motor on the rear of the robot. 00066 */ 00067 int32_t left_rpm; /**< 00068 RPM of the motor on the left front of the robot. 00069 */ 00070 float odometry_path_length; /**< 00071 The actual length of the robot's trajectory since the last ResetOdometry. 00072 */ 00073 float odometry_position_x; /**< 00074 The actual position of the robot relative to the position at the last ResetOdometry. 00075 */ 00076 float odometry_position_y; /**< 00077 The actual position of the robot relative to the position at the last ResetOdometry. 00078 */ 00079 float odometry_orientation; /**< 00080 The actual orientation of the robot relative to the orientation at the last ResetOdometry. 00081 */ 00082 float vx; /**< 00083 VX of the robot in m/s. Forward. 00084 */ 00085 float vy; /**< 00086 VY of the robot in m/s. Left. 00087 */ 00088 float omega; /**< 00089 Rotation speed of the robot in rad/s. 00090 */ 00091 uint32_t controller; /**< 00092 The ID of the controller. The controller ID is the instance serial of the sending 00093 interface. Only from this interface instance command messages are accepted. 00094 */ 00095 char controller_thread_name[64]; /**< 00096 The name of the controlling thread, for easier debugging. This is informative only 00097 and actually two threads may share an interface instance (although this should be 00098 avoided since the interface locking has to be reproduced for these threads then). 00099 */ 00100 } MotorInterface_data_t; 00101 #pragma pack(pop) 00102 00103 MotorInterface_data_t *data; 00104 00105 public: 00106 /* messages */ 00107 class SetMotorStateMessage : public Message 00108 { 00109 private: 00110 #pragma pack(push,4) 00111 /** Internal data storage, do NOT modify! */ 00112 typedef struct { 00113 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00114 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00115 uint32_t motor_state; /**< 00116 The new motor state to set. Use the MOTOR_* constants. 00117 */ 00118 } SetMotorStateMessage_data_t; 00119 #pragma pack(pop) 00120 00121 SetMotorStateMessage_data_t *data; 00122 00123 public: 00124 SetMotorStateMessage(const uint32_t ini_motor_state); 00125 SetMotorStateMessage(); 00126 ~SetMotorStateMessage(); 00127 00128 SetMotorStateMessage(const SetMotorStateMessage *m); 00129 /* Methods */ 00130 uint32_t motor_state() const; 00131 void set_motor_state(const uint32_t new_motor_state); 00132 size_t maxlenof_motor_state() const; 00133 virtual Message * clone() const; 00134 }; 00135 00136 class AcquireControlMessage : public Message 00137 { 00138 private: 00139 #pragma pack(push,4) 00140 /** Internal data storage, do NOT modify! */ 00141 typedef struct { 00142 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00143 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00144 uint32_t controller; /**< 00145 The ID of the controller. The controller ID is the instance serial of the sending 00146 interface. Only from this interface instance command messages are accepted. 00147 */ 00148 char controller_thread_name[64]; /**< 00149 The name of the controlling thread, for easier debugging. This is informative only 00150 and actually two threads may share an interface instance (although this should be 00151 avoided since the interface locking has to be reproduced for these threads then). 00152 */ 00153 } AcquireControlMessage_data_t; 00154 #pragma pack(pop) 00155 00156 AcquireControlMessage_data_t *data; 00157 00158 public: 00159 AcquireControlMessage(const uint32_t ini_controller, const char * ini_controller_thread_name); 00160 AcquireControlMessage(); 00161 ~AcquireControlMessage(); 00162 00163 AcquireControlMessage(const AcquireControlMessage *m); 00164 /* Methods */ 00165 uint32_t controller() const; 00166 void set_controller(const uint32_t new_controller); 00167 size_t maxlenof_controller() const; 00168 char * controller_thread_name() const; 00169 void set_controller_thread_name(const char * new_controller_thread_name); 00170 size_t maxlenof_controller_thread_name() const; 00171 virtual Message * clone() const; 00172 }; 00173 00174 class ResetOdometryMessage : public Message 00175 { 00176 private: 00177 #pragma pack(push,4) 00178 /** Internal data storage, do NOT modify! */ 00179 typedef struct { 00180 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00181 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00182 } ResetOdometryMessage_data_t; 00183 #pragma pack(pop) 00184 00185 ResetOdometryMessage_data_t *data; 00186 00187 public: 00188 ResetOdometryMessage(); 00189 ~ResetOdometryMessage(); 00190 00191 ResetOdometryMessage(const ResetOdometryMessage *m); 00192 /* Methods */ 00193 virtual Message * clone() const; 00194 }; 00195 00196 class DriveRPMMessage : public Message 00197 { 00198 private: 00199 #pragma pack(push,4) 00200 /** Internal data storage, do NOT modify! */ 00201 typedef struct { 00202 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00203 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00204 float front_right; /**< Rotation in RPM of the right front wheel. */ 00205 float front_left; /**< Rotation in RPM of the left front wheel. */ 00206 float rear; /**< Rotation in RPM of the rear wheel. */ 00207 } DriveRPMMessage_data_t; 00208 #pragma pack(pop) 00209 00210 DriveRPMMessage_data_t *data; 00211 00212 public: 00213 DriveRPMMessage(const float ini_front_right, const float ini_front_left, const float ini_rear); 00214 DriveRPMMessage(); 00215 ~DriveRPMMessage(); 00216 00217 DriveRPMMessage(const DriveRPMMessage *m); 00218 /* Methods */ 00219 float front_right() const; 00220 void set_front_right(const float new_front_right); 00221 size_t maxlenof_front_right() const; 00222 float front_left() const; 00223 void set_front_left(const float new_front_left); 00224 size_t maxlenof_front_left() const; 00225 float rear() const; 00226 void set_rear(const float new_rear); 00227 size_t maxlenof_rear() const; 00228 virtual Message * clone() const; 00229 }; 00230 00231 class GotoMessage : public Message 00232 { 00233 private: 00234 #pragma pack(push,4) 00235 /** Internal data storage, do NOT modify! */ 00236 typedef struct { 00237 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00238 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00239 float x; /**< X distance in m. */ 00240 float y; /**< Y distance in m. */ 00241 float phi; /**< Angle relative to current angle in rad. */ 00242 float time_sec; /**< When to reach the desired location. */ 00243 } GotoMessage_data_t; 00244 #pragma pack(pop) 00245 00246 GotoMessage_data_t *data; 00247 00248 public: 00249 GotoMessage(const float ini_x, const float ini_y, const float ini_phi, const float ini_time_sec); 00250 GotoMessage(); 00251 ~GotoMessage(); 00252 00253 GotoMessage(const GotoMessage *m); 00254 /* Methods */ 00255 float x() const; 00256 void set_x(const float new_x); 00257 size_t maxlenof_x() const; 00258 float y() const; 00259 void set_y(const float new_y); 00260 size_t maxlenof_y() const; 00261 float phi() const; 00262 void set_phi(const float new_phi); 00263 size_t maxlenof_phi() const; 00264 float time_sec() const; 00265 void set_time_sec(const float new_time_sec); 00266 size_t maxlenof_time_sec() const; 00267 virtual Message * clone() const; 00268 }; 00269 00270 class TransMessage : public Message 00271 { 00272 private: 00273 #pragma pack(push,4) 00274 /** Internal data storage, do NOT modify! */ 00275 typedef struct { 00276 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00277 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00278 float vx; /**< Speed in X direction in m/s. */ 00279 float vy; /**< Speed in Y direction in m/s. */ 00280 } TransMessage_data_t; 00281 #pragma pack(pop) 00282 00283 TransMessage_data_t *data; 00284 00285 public: 00286 TransMessage(const float ini_vx, const float ini_vy); 00287 TransMessage(); 00288 ~TransMessage(); 00289 00290 TransMessage(const TransMessage *m); 00291 /* Methods */ 00292 float vx() const; 00293 void set_vx(const float new_vx); 00294 size_t maxlenof_vx() const; 00295 float vy() const; 00296 void set_vy(const float new_vy); 00297 size_t maxlenof_vy() const; 00298 virtual Message * clone() const; 00299 }; 00300 00301 class RotMessage : public Message 00302 { 00303 private: 00304 #pragma pack(push,4) 00305 /** Internal data storage, do NOT modify! */ 00306 typedef struct { 00307 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00308 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00309 float omega; /**< Angle rotation in rad/s. */ 00310 } RotMessage_data_t; 00311 #pragma pack(pop) 00312 00313 RotMessage_data_t *data; 00314 00315 public: 00316 RotMessage(const float ini_omega); 00317 RotMessage(); 00318 ~RotMessage(); 00319 00320 RotMessage(const RotMessage *m); 00321 /* Methods */ 00322 float omega() const; 00323 void set_omega(const float new_omega); 00324 size_t maxlenof_omega() const; 00325 virtual Message * clone() const; 00326 }; 00327 00328 class TransRotMessage : public Message 00329 { 00330 private: 00331 #pragma pack(push,4) 00332 /** Internal data storage, do NOT modify! */ 00333 typedef struct { 00334 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00335 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00336 float vx; /**< Speed in X direction in m/s. */ 00337 float vy; /**< Speed in Y direction in m/s. */ 00338 float omega; /**< Angle rotation in rad/s. */ 00339 } TransRotMessage_data_t; 00340 #pragma pack(pop) 00341 00342 TransRotMessage_data_t *data; 00343 00344 public: 00345 TransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega); 00346 TransRotMessage(); 00347 ~TransRotMessage(); 00348 00349 TransRotMessage(const TransRotMessage *m); 00350 /* Methods */ 00351 float vx() const; 00352 void set_vx(const float new_vx); 00353 size_t maxlenof_vx() const; 00354 float vy() const; 00355 void set_vy(const float new_vy); 00356 size_t maxlenof_vy() const; 00357 float omega() const; 00358 void set_omega(const float new_omega); 00359 size_t maxlenof_omega() const; 00360 virtual Message * clone() const; 00361 }; 00362 00363 class OrbitMessage : public Message 00364 { 00365 private: 00366 #pragma pack(push,4) 00367 /** Internal data storage, do NOT modify! */ 00368 typedef struct { 00369 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00370 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00371 float px; /**< Point's X coordinate to orbit. */ 00372 float py; /**< Point's Y coordinate to orbit. */ 00373 float omega; /**< Angular speed around point in rad/s. */ 00374 } OrbitMessage_data_t; 00375 #pragma pack(pop) 00376 00377 OrbitMessage_data_t *data; 00378 00379 public: 00380 OrbitMessage(const float ini_px, const float ini_py, const float ini_omega); 00381 OrbitMessage(); 00382 ~OrbitMessage(); 00383 00384 OrbitMessage(const OrbitMessage *m); 00385 /* Methods */ 00386 float px() const; 00387 void set_px(const float new_px); 00388 size_t maxlenof_px() const; 00389 float py() const; 00390 void set_py(const float new_py); 00391 size_t maxlenof_py() const; 00392 float omega() const; 00393 void set_omega(const float new_omega); 00394 size_t maxlenof_omega() const; 00395 virtual Message * clone() const; 00396 }; 00397 00398 class LinTransRotMessage : public Message 00399 { 00400 private: 00401 #pragma pack(push,4) 00402 /** Internal data storage, do NOT modify! */ 00403 typedef struct { 00404 int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */ 00405 int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */ 00406 float vx; /**< Speed for translation in X direction in m/s. */ 00407 float vy; /**< Speed for translation in Y direction in m/s. */ 00408 float omega; /**< Rotational speed in rad/s. */ 00409 } LinTransRotMessage_data_t; 00410 #pragma pack(pop) 00411 00412 LinTransRotMessage_data_t *data; 00413 00414 public: 00415 LinTransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega); 00416 LinTransRotMessage(); 00417 ~LinTransRotMessage(); 00418 00419 LinTransRotMessage(const LinTransRotMessage *m); 00420 /* Methods */ 00421 float vx() const; 00422 void set_vx(const float new_vx); 00423 size_t maxlenof_vx() const; 00424 float vy() const; 00425 void set_vy(const float new_vy); 00426 size_t maxlenof_vy() const; 00427 float omega() const; 00428 void set_omega(const float new_omega); 00429 size_t maxlenof_omega() const; 00430 virtual Message * clone() const; 00431 }; 00432 00433 virtual bool message_valid(const Message *message) const; 00434 private: 00435 MotorInterface(); 00436 ~MotorInterface(); 00437 00438 public: 00439 /* Methods */ 00440 uint32_t motor_state() const; 00441 void set_motor_state(const uint32_t new_motor_state); 00442 size_t maxlenof_motor_state() const; 00443 uint32_t drive_mode() const; 00444 void set_drive_mode(const uint32_t new_drive_mode); 00445 size_t maxlenof_drive_mode() const; 00446 int32_t right_rpm() const; 00447 void set_right_rpm(const int32_t new_right_rpm); 00448 size_t maxlenof_right_rpm() const; 00449 int32_t rear_rpm() const; 00450 void set_rear_rpm(const int32_t new_rear_rpm); 00451 size_t maxlenof_rear_rpm() const; 00452 int32_t left_rpm() const; 00453 void set_left_rpm(const int32_t new_left_rpm); 00454 size_t maxlenof_left_rpm() const; 00455 float odometry_path_length() const; 00456 void set_odometry_path_length(const float new_odometry_path_length); 00457 size_t maxlenof_odometry_path_length() const; 00458 float odometry_position_x() const; 00459 void set_odometry_position_x(const float new_odometry_position_x); 00460 size_t maxlenof_odometry_position_x() const; 00461 float odometry_position_y() const; 00462 void set_odometry_position_y(const float new_odometry_position_y); 00463 size_t maxlenof_odometry_position_y() const; 00464 float odometry_orientation() const; 00465 void set_odometry_orientation(const float new_odometry_orientation); 00466 size_t maxlenof_odometry_orientation() const; 00467 float vx() const; 00468 void set_vx(const float new_vx); 00469 size_t maxlenof_vx() const; 00470 float vy() const; 00471 void set_vy(const float new_vy); 00472 size_t maxlenof_vy() const; 00473 float omega() const; 00474 void set_omega(const float new_omega); 00475 size_t maxlenof_omega() const; 00476 uint32_t controller() const; 00477 void set_controller(const uint32_t new_controller); 00478 size_t maxlenof_controller() const; 00479 char * controller_thread_name() const; 00480 void set_controller_thread_name(const char * new_controller_thread_name); 00481 size_t maxlenof_controller_thread_name() const; 00482 virtual Message * create_message(const char *type) const; 00483 00484 virtual void copy_values(const Interface *other); 00485 virtual const char * enum_tostring(const char *enumtype, int val) const; 00486 00487 }; 00488 00489 } // end namespace fawkes 00490 00491 #endif