Motorcortex Core  version: 2.7.6
drive_base.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2018 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_LIB_DRIVE_BASE_H
7 #define MOTORCORTEX_LIB_DRIVE_BASE_H
8 
9 #include "drive_mode.h"
10 #include "drive_state.h"
11 #include "drive_command.h"
12 
13 #include "ct_module.h"
14 
15 namespace mcx {
16 
17 namespace drive {
18 
19 struct DriveIn {
20  // new drive mode (user input)
21  DriveMode mode;
22  // new drive command (user input)
23  DriveCommand command;
24  // feedback from the drive
25  unsigned int status_word;
26  // timeout
27  double timeout_switch_on_sec;
28  double timeout_enable_op_sec;
29  double timeout_fault_ack_sec;
30  double timeout_switch_off_sec;
31  double delay_enable_op_sec_;
32 };
33 
34 struct DriveOut {
35  // drive specific opmode
36  unsigned int opmode;
37  // drive specific control word
38  unsigned int control_word;
39  // drive state
40  DriveState state;
41  // flag is temporarily set high, after error happened
42  bool upload_error_code;
43  // flag is set when drive is resetting;
44  bool drive_resetting;
45  // flag is set when drive is in operation enabled state
46  bool drive_enabled;
47  // flag is set when drive has active warning
48  bool has_warning;
49  // flag is set when drive has active error
50  bool has_error;
51 };
52 
53 class DriveBase {
54 public:
55  virtual ~DriveBase() = default;
56 
57  virtual void setName(const std::string& name) = 0;
58 
59  virtual bool update(double dt_sec, const DriveIn& drive_in, DriveOut* drive_out) = 0;
60 };
61 
62 } // namespace drive
63 
64 } // namespace mcx
65 
66 #endif // MOTORCORTEX_LIB_DRIVE_BASE_H
mcx::drive::DriveOut
Definition: drive_base.h:34
mcx::drive::DriveIn
Definition: drive_base.h:19
mcx::drive::DriveBase
Definition: drive_base.h:53