Fawkes API  Fawkes Development Version
MotorInterface.h
1 
2 /***************************************************************************
3  * MotorInterface.h - Fawkes BlackBoard Interface - MotorInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2007 Martin Liebenberg, Tim Niemueller
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __INTERFACES_MOTORINTERFACE_H_
25 #define __INTERFACES_MOTORINTERFACE_H_
26 
27 #include <interface/interface.h>
28 #include <interface/message.h>
29 #include <interface/field_iterator.h>
30 
31 namespace fawkes {
32 
33 class MotorInterface : public Interface
34 {
35  /// @cond INTERNALS
36  INTERFACE_MGMT_FRIENDS(MotorInterface)
37  /// @endcond
38  public:
39  /* constants */
40  static const uint32_t MOTOR_ENABLED;
41  static const uint32_t MOTOR_DISABLED;
42  static const uint32_t DRIVE_MODE_RPM;
43  static const uint32_t DRIVE_MODE_TRANS;
44  static const uint32_t DRIVE_MODE_ROT;
45  static const uint32_t DRIVE_MODE_TRANS_ROT;
46  static const uint32_t DRIVE_MODE_ORBIT;
47  static const uint32_t DRIVE_MODE_LINE_TRANS_ROT;
48 
49  private:
50  /** Internal data storage, do NOT modify! */
51  typedef struct __attribute__((packed)) {
52  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
53  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
54  uint32_t motor_state; /**<
55  The current state of the motor.
56  */
57  uint32_t drive_mode; /**<
58  The current drive mode of the motor.
59  */
60  int32_t right_rpm; /**<
61  RPM of the motor on the right front of the robot.
62  */
63  int32_t rear_rpm; /**<
64  RPM of motor on the rear of the robot.
65  */
66  int32_t left_rpm; /**<
67  RPM of the motor on the left front of the robot.
68  */
69  float odometry_path_length; /**<
70  The actual length of the robot's trajectory since the last ResetOdometry.
71  */
72  float odometry_position_x; /**<
73  The actual position of the robot relative to the position at the last ResetOdometry.
74  */
75  float odometry_position_y; /**<
76  The actual position of the robot relative to the position at the last ResetOdometry.
77  */
78  float odometry_orientation; /**<
79  The actual orientation of the robot relative to the orientation at the last ResetOdometry.
80  */
81  float vx; /**<
82  VX of the robot in m/s. Forward.
83  */
84  float vy; /**<
85  VY of the robot in m/s. Left.
86  */
87  float omega; /**<
88  Rotation speed of the robot in rad/s.
89  */
90  float des_vx; /**<
91  Desired VX of the robot in m/s. Forward.
92  */
93  float des_vy; /**<
94  Desired VY of the robot in m/s. Left.
95  */
96  float des_omega; /**<
97  Desired Rotation speed of the robot in rad/s.
98  */
99  uint32_t controller; /**<
100  The ID of the controller. The controller ID is the instance serial of the sending
101  interface. Only from this interface instance command messages are accepted.
102  */
103  char controller_thread_name[64]; /**<
104  The name of the controlling thread, for easier debugging. This is informative only
105  and actually two threads may share an interface instance (although this should be
106  avoided since the interface locking has to be reproduced for these threads then).
107  */
108  } MotorInterface_data_t;
109 
110  MotorInterface_data_t *data;
111 
112  public:
113  /* messages */
115  {
116  private:
117  /** Internal data storage, do NOT modify! */
118  typedef struct __attribute__((packed)) {
119  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
120  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
121  uint32_t motor_state; /**<
122  The new motor state to set. Use the MOTOR_* constants.
123  */
124  } SetMotorStateMessage_data_t;
125 
126  SetMotorStateMessage_data_t *data;
127 
128  public:
129  SetMotorStateMessage(const uint32_t ini_motor_state);
132 
134  /* Methods */
135  uint32_t motor_state() const;
136  void set_motor_state(const uint32_t new_motor_state);
137  size_t maxlenof_motor_state() const;
138  virtual Message * clone() const;
139  };
140 
142  {
143  private:
144  /** Internal data storage, do NOT modify! */
145  typedef struct __attribute__((packed)) {
146  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
147  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
148  uint32_t controller; /**<
149  The ID of the controller. The controller ID is the instance serial of the sending
150  interface. Only from this interface instance command messages are accepted.
151  */
152  char controller_thread_name[64]; /**<
153  The name of the controlling thread, for easier debugging. This is informative only
154  and actually two threads may share an interface instance (although this should be
155  avoided since the interface locking has to be reproduced for these threads then).
156  */
157  } AcquireControlMessage_data_t;
158 
159  AcquireControlMessage_data_t *data;
160 
161  public:
162  AcquireControlMessage(const uint32_t ini_controller, const char * ini_controller_thread_name);
165 
167  /* Methods */
168  uint32_t controller() const;
169  void set_controller(const uint32_t new_controller);
170  size_t maxlenof_controller() const;
171  char * controller_thread_name() const;
172  void set_controller_thread_name(const char * new_controller_thread_name);
173  size_t maxlenof_controller_thread_name() const;
174  virtual Message * clone() const;
175  };
176 
178  {
179  private:
180  /** Internal data storage, do NOT modify! */
181  typedef struct __attribute__((packed)) {
182  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
183  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
184  } ResetOdometryMessage_data_t;
185 
186  ResetOdometryMessage_data_t *data;
187 
188  public:
191 
193  /* Methods */
194  virtual Message * clone() const;
195  };
196 
198  {
199  private:
200  /** Internal data storage, do NOT modify! */
201  typedef struct __attribute__((packed)) {
202  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
203  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
204  float x; /**< Translation in x direction in m */
205  float y; /**< Translation in y direction in m */
206  float odometry_orientation; /**< OdometryOrientation in m */
207  } SetOdometryMessage_data_t;
208 
209  SetOdometryMessage_data_t *data;
210 
211  public:
212  SetOdometryMessage(const float ini_x, const float ini_y, const float ini_odometry_orientation);
215 
217  /* Methods */
218  float x() const;
219  void set_x(const float new_x);
220  size_t maxlenof_x() const;
221  float y() const;
222  void set_y(const float new_y);
223  size_t maxlenof_y() const;
224  float odometry_orientation() const;
225  void set_odometry_orientation(const float new_odometry_orientation);
226  size_t maxlenof_odometry_orientation() const;
227  virtual Message * clone() const;
228  };
229 
230  class DriveRPMMessage : public Message
231  {
232  private:
233  /** Internal data storage, do NOT modify! */
234  typedef struct __attribute__((packed)) {
235  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
236  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
237  float front_right; /**< Rotation in RPM of the right front wheel. */
238  float front_left; /**< Rotation in RPM of the left front wheel. */
239  float rear; /**< Rotation in RPM of the rear wheel. */
240  } DriveRPMMessage_data_t;
241 
242  DriveRPMMessage_data_t *data;
243 
244  public:
245  DriveRPMMessage(const float ini_front_right, const float ini_front_left, const float ini_rear);
246  DriveRPMMessage();
247  ~DriveRPMMessage();
248 
250  /* Methods */
251  float front_right() const;
252  void set_front_right(const float new_front_right);
253  size_t maxlenof_front_right() const;
254  float front_left() const;
255  void set_front_left(const float new_front_left);
256  size_t maxlenof_front_left() const;
257  float rear() const;
258  void set_rear(const float new_rear);
259  size_t maxlenof_rear() const;
260  virtual Message * clone() const;
261  };
262 
263  class GotoMessage : public Message
264  {
265  private:
266  /** Internal data storage, do NOT modify! */
267  typedef struct __attribute__((packed)) {
268  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
269  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
270  float x; /**< X distance in m. */
271  float y; /**< Y distance in m. */
272  float phi; /**< Angle relative to current angle in rad. */
273  float time_sec; /**< When to reach the desired location. */
274  } GotoMessage_data_t;
275 
276  GotoMessage_data_t *data;
277 
278  public:
279  GotoMessage(const float ini_x, const float ini_y, const float ini_phi, const float ini_time_sec);
280  GotoMessage();
281  ~GotoMessage();
282 
283  GotoMessage(const GotoMessage *m);
284  /* Methods */
285  float x() const;
286  void set_x(const float new_x);
287  size_t maxlenof_x() const;
288  float y() const;
289  void set_y(const float new_y);
290  size_t maxlenof_y() const;
291  float phi() const;
292  void set_phi(const float new_phi);
293  size_t maxlenof_phi() const;
294  float time_sec() const;
295  void set_time_sec(const float new_time_sec);
296  size_t maxlenof_time_sec() const;
297  virtual Message * clone() const;
298  };
299 
300  class TransMessage : public Message
301  {
302  private:
303  /** Internal data storage, do NOT modify! */
304  typedef struct __attribute__((packed)) {
305  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
306  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
307  float vx; /**< Speed in X direction in m/s. */
308  float vy; /**< Speed in Y direction in m/s. */
309  } TransMessage_data_t;
310 
311  TransMessage_data_t *data;
312 
313  public:
314  TransMessage(const float ini_vx, const float ini_vy);
315  TransMessage();
316  ~TransMessage();
317 
318  TransMessage(const TransMessage *m);
319  /* Methods */
320  float vx() const;
321  void set_vx(const float new_vx);
322  size_t maxlenof_vx() const;
323  float vy() const;
324  void set_vy(const float new_vy);
325  size_t maxlenof_vy() const;
326  virtual Message * clone() const;
327  };
328 
329  class RotMessage : public Message
330  {
331  private:
332  /** Internal data storage, do NOT modify! */
333  typedef struct __attribute__((packed)) {
334  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
335  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
336  float omega; /**< Angle rotation in rad/s. */
337  } RotMessage_data_t;
338 
339  RotMessage_data_t *data;
340 
341  public:
342  RotMessage(const float ini_omega);
343  RotMessage();
344  ~RotMessage();
345 
346  RotMessage(const RotMessage *m);
347  /* Methods */
348  float omega() const;
349  void set_omega(const float new_omega);
350  size_t maxlenof_omega() const;
351  virtual Message * clone() const;
352  };
353 
354  class TransRotMessage : public Message
355  {
356  private:
357  /** Internal data storage, do NOT modify! */
358  typedef struct __attribute__((packed)) {
359  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
360  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
361  float vx; /**< Speed in X direction in m/s. */
362  float vy; /**< Speed in Y direction in m/s. */
363  float omega; /**< Angle rotation in rad/s. */
364  } TransRotMessage_data_t;
365 
366  TransRotMessage_data_t *data;
367 
368  public:
369  TransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega);
370  TransRotMessage();
371  ~TransRotMessage();
372 
374  /* Methods */
375  float vx() const;
376  void set_vx(const float new_vx);
377  size_t maxlenof_vx() const;
378  float vy() const;
379  void set_vy(const float new_vy);
380  size_t maxlenof_vy() const;
381  float omega() const;
382  void set_omega(const float new_omega);
383  size_t maxlenof_omega() const;
384  virtual Message * clone() const;
385  };
386 
387  class OrbitMessage : public Message
388  {
389  private:
390  /** Internal data storage, do NOT modify! */
391  typedef struct __attribute__((packed)) {
392  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
393  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
394  float px; /**< Point's X coordinate to orbit. */
395  float py; /**< Point's Y coordinate to orbit. */
396  float omega; /**< Angular speed around point in rad/s. */
397  } OrbitMessage_data_t;
398 
399  OrbitMessage_data_t *data;
400 
401  public:
402  OrbitMessage(const float ini_px, const float ini_py, const float ini_omega);
403  OrbitMessage();
404  ~OrbitMessage();
405 
406  OrbitMessage(const OrbitMessage *m);
407  /* Methods */
408  float px() const;
409  void set_px(const float new_px);
410  size_t maxlenof_px() const;
411  float py() const;
412  void set_py(const float new_py);
413  size_t maxlenof_py() const;
414  float omega() const;
415  void set_omega(const float new_omega);
416  size_t maxlenof_omega() const;
417  virtual Message * clone() const;
418  };
419 
421  {
422  private:
423  /** Internal data storage, do NOT modify! */
424  typedef struct __attribute__((packed)) {
425  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
426  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
427  float vx; /**< Speed for translation in X direction in m/s. */
428  float vy; /**< Speed for translation in Y direction in m/s. */
429  float omega; /**< Rotational speed in rad/s. */
430  } LinTransRotMessage_data_t;
431 
432  LinTransRotMessage_data_t *data;
433 
434  public:
435  LinTransRotMessage(const float ini_vx, const float ini_vy, const float ini_omega);
438 
440  /* Methods */
441  float vx() const;
442  void set_vx(const float new_vx);
443  size_t maxlenof_vx() const;
444  float vy() const;
445  void set_vy(const float new_vy);
446  size_t maxlenof_vy() const;
447  float omega() const;
448  void set_omega(const float new_omega);
449  size_t maxlenof_omega() const;
450  virtual Message * clone() const;
451  };
452 
453  virtual bool message_valid(const Message *message) const;
454  private:
455  MotorInterface();
456  ~MotorInterface();
457 
458  public:
459  /* Methods */
460  uint32_t motor_state() const;
461  void set_motor_state(const uint32_t new_motor_state);
462  size_t maxlenof_motor_state() const;
463  uint32_t drive_mode() const;
464  void set_drive_mode(const uint32_t new_drive_mode);
465  size_t maxlenof_drive_mode() const;
466  int32_t right_rpm() const;
467  void set_right_rpm(const int32_t new_right_rpm);
468  size_t maxlenof_right_rpm() const;
469  int32_t rear_rpm() const;
470  void set_rear_rpm(const int32_t new_rear_rpm);
471  size_t maxlenof_rear_rpm() const;
472  int32_t left_rpm() const;
473  void set_left_rpm(const int32_t new_left_rpm);
474  size_t maxlenof_left_rpm() const;
475  float odometry_path_length() const;
476  void set_odometry_path_length(const float new_odometry_path_length);
477  size_t maxlenof_odometry_path_length() const;
478  float odometry_position_x() const;
479  void set_odometry_position_x(const float new_odometry_position_x);
480  size_t maxlenof_odometry_position_x() const;
481  float odometry_position_y() const;
482  void set_odometry_position_y(const float new_odometry_position_y);
483  size_t maxlenof_odometry_position_y() const;
484  float odometry_orientation() const;
485  void set_odometry_orientation(const float new_odometry_orientation);
486  size_t maxlenof_odometry_orientation() const;
487  float vx() const;
488  void set_vx(const float new_vx);
489  size_t maxlenof_vx() const;
490  float vy() const;
491  void set_vy(const float new_vy);
492  size_t maxlenof_vy() const;
493  float omega() const;
494  void set_omega(const float new_omega);
495  size_t maxlenof_omega() const;
496  float des_vx() const;
497  void set_des_vx(const float new_des_vx);
498  size_t maxlenof_des_vx() const;
499  float des_vy() const;
500  void set_des_vy(const float new_des_vy);
501  size_t maxlenof_des_vy() const;
502  float des_omega() const;
503  void set_des_omega(const float new_des_omega);
504  size_t maxlenof_des_omega() const;
505  uint32_t controller() const;
506  void set_controller(const uint32_t new_controller);
507  size_t maxlenof_controller() const;
508  char * controller_thread_name() const;
509  void set_controller_thread_name(const char * new_controller_thread_name);
510  size_t maxlenof_controller_thread_name() const;
511  virtual Message * create_message(const char *type) const;
512 
513  virtual void copy_values(const Interface *other);
514  virtual const char * enum_tostring(const char *enumtype, int val) const;
515 
516 };
517 
518 } // end namespace fawkes
519 
520 #endif
void set_des_vx(const float new_des_vx)
Set des_vx value.
SetMotorStateMessage Fawkes BlackBoard Interface Message.
static const uint32_t DRIVE_MODE_LINE_TRANS_ROT
DRIVE_MODE_LINE_TRANS_ROT constant.
size_t maxlenof_omega() const
Get maximum length of omega value.
RotMessage Fawkes BlackBoard Interface Message.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
static const uint32_t MOTOR_ENABLED
MOTOR_ENABLED constant.
float odometry_position_x() const
Get odometry_position_x value.
static const uint32_t DRIVE_MODE_RPM
DRIVE_MODE_RPM constant.
TransRotMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_odometry_position_x() const
Get maximum length of odometry_position_x value.
void set_odometry_position_y(const float new_odometry_position_y)
Set odometry_position_y value.
uint32_t controller() const
Get controller value.
Fawkes library namespace.
size_t maxlenof_rear_rpm() const
Get maximum length of rear_rpm value.
size_t maxlenof_vx() const
Get maximum length of vx value.
int32_t left_rpm() const
Get left_rpm value.
void set_motor_state(const uint32_t new_motor_state)
Set motor_state value.
float odometry_path_length() const
Get odometry_path_length value.
virtual Message * create_message(const char *type) const
Create message based on type name.
void set_controller(const uint32_t new_controller)
Set controller value.
void set_odometry_orientation(const float new_odometry_orientation)
Set odometry_orientation value.
void set_rear_rpm(const int32_t new_rear_rpm)
Set rear_rpm value.
OrbitMessage Fawkes BlackBoard Interface Message.
uint32_t drive_mode() const
Get drive_mode value.
size_t maxlenof_right_rpm() const
Get maximum length of right_rpm value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
size_t maxlenof_controller() const
Get maximum length of controller value.
int32_t rear_rpm() const
Get rear_rpm value.
size_t maxlenof_motor_state() const
Get maximum length of motor_state value.
size_t maxlenof_odometry_orientation() const
Get maximum length of odometry_orientation value.
void set_right_rpm(const int32_t new_right_rpm)
Set right_rpm value.
void set_left_rpm(const int32_t new_left_rpm)
Set left_rpm value.
float vx() const
Get vx value.
void set_des_omega(const float new_des_omega)
Set des_omega value.
ResetOdometryMessage Fawkes BlackBoard Interface Message.
void set_odometry_path_length(const float new_odometry_path_length)
Set odometry_path_length value.
size_t maxlenof_drive_mode() const
Get maximum length of drive_mode value.
float odometry_orientation() const
Get odometry_orientation value.
float odometry_position_y() const
Get odometry_position_y value.
AcquireControlMessage Fawkes BlackBoard Interface Message.
void set_des_vy(const float new_des_vy)
Set des_vy value.
float vy() const
Get vy value.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
static const uint32_t DRIVE_MODE_TRANS_ROT
DRIVE_MODE_TRANS_ROT constant.
void set_vy(const float new_vy)
Set vy value.
void set_vx(const float new_vx)
Set vx value.
static const uint32_t DRIVE_MODE_TRANS
DRIVE_MODE_TRANS constant.
void set_omega(const float new_omega)
Set omega value.
size_t maxlenof_des_vy() const
Get maximum length of des_vy value.
float omega() const
Get omega value.
int32_t right_rpm() const
Get right_rpm value.
void set_controller_thread_name(const char *new_controller_thread_name)
Set controller_thread_name value.
LinTransRotMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_controller_thread_name() const
Get maximum length of controller_thread_name value.
char * controller_thread_name() const
Get controller_thread_name value.
float des_vx() const
Get des_vx value.
DriveRPMMessage Fawkes BlackBoard Interface Message.
void set_drive_mode(const uint32_t new_drive_mode)
Set drive_mode value.
float des_omega() const
Get des_omega value.
static const uint32_t MOTOR_DISABLED
MOTOR_DISABLED constant.
void set_odometry_position_x(const float new_odometry_position_x)
Set odometry_position_x value.
float des_vy() const
Get des_vy value.
size_t maxlenof_left_rpm() const
Get maximum length of left_rpm value.
size_t maxlenof_odometry_position_y() const
Get maximum length of odometry_position_y value.
static const uint32_t DRIVE_MODE_ORBIT
DRIVE_MODE_ORBIT constant.
MotorInterface Fawkes BlackBoard Interface.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
size_t maxlenof_des_omega() const
Get maximum length of des_omega value.
size_t maxlenof_odometry_path_length() const
Get maximum length of odometry_path_length value.
GotoMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_des_vx() const
Get maximum length of des_vx value.
SetOdometryMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_vy() const
Get maximum length of vy value.
uint32_t motor_state() const
Get motor_state value.
static const uint32_t DRIVE_MODE_ROT
DRIVE_MODE_ROT constant.
virtual void copy_values(const Interface *other)
Copy values from other interface.
TransMessage Fawkes BlackBoard Interface Message.