ros2_canopen  master
C++ ROS CANopen Library
profiled_position_mode.hpp
Go to the documentation of this file.
1 #ifndef PROFILED_POSITION_MODE_HPP
2 #define PROFILED_POSITION_MODE_HPP
3 
4 #include <cstdint>
5 #include <memory>
7 #include "mode_target_helper.hpp"
8 
9 namespace ros2_canopen
10 {
11 class ProfiledPositionMode : public ModeTargetHelper<int32_t>
12 {
13  const uint16_t index = 0x607A;
14  std::shared_ptr<LelyDriverBridge> driver;
15 
16  double last_target_;
17  uint16_t sw_;
18 
19 public:
20  enum SW_masks
21  {
25  };
26  enum CW_bits
27  {
31  };
32  ProfiledPositionMode(std::shared_ptr<LelyDriverBridge> driver)
33  : ModeTargetHelper(MotorBase::Profiled_Position)
34  {
35  this->driver = driver;
36  }
37 
38  virtual bool start()
39  {
40  sw_ = 0;
41  last_target_ = std::numeric_limits<double>::quiet_NaN();
42  return ModeTargetHelper::start();
43  }
44  virtual bool read(const uint16_t & sw)
45  {
46  sw_ = sw;
47  return (sw & MASK_Error) == 0;
48  }
49  virtual bool write(OpModeAccesser & cw)
50  {
51  cw.set(CW_Immediate);
52  if (hasTarget())
53  {
54  int32_t target = getTarget();
55  if ((sw_ & MASK_Acknowledged) == 0 && target != last_target_)
56  {
57  if (cw.get(CW_NewPoint))
58  {
59  cw.reset(CW_NewPoint); // reset if needed
60  }
61  else
62  {
63  driver->universal_set_value(index, 0x0, target);
64  cw.set(CW_NewPoint);
65  last_target_ = target;
66  }
67  }
68  else if (sw_ & MASK_Acknowledged)
69  {
70  cw.reset(CW_NewPoint);
71  }
72  return true;
73  }
74  return false;
75  }
76 };
77 } // namespace ros2_canopen
78 
79 #endif // PROFILED_POSITION_MODE_HPP
@ CW_Operation_mode_specific3
Definition: command.hpp:52
@ CW_Operation_mode_specific1
Definition: command.hpp:48
@ CW_Operation_mode_specific0
Definition: command.hpp:47
Definition: mode_target_helper.hpp:20
virtual bool start()
Definition: mode_target_helper.hpp:66
bool hasTarget()
Definition: mode_target_helper.hpp:26
int32_t getTarget()
Definition: mode_target_helper.hpp:27
Motor Base Class.
Definition: base.hpp:16
Definition: profiled_position_mode.hpp:12
virtual bool write(OpModeAccesser &cw)
Definition: profiled_position_mode.hpp:49
CW_bits
Definition: profiled_position_mode.hpp:27
@ CW_NewPoint
Definition: profiled_position_mode.hpp:28
@ CW_Immediate
Definition: profiled_position_mode.hpp:29
@ CW_Blending
Definition: profiled_position_mode.hpp:30
ProfiledPositionMode(std::shared_ptr< LelyDriverBridge > driver)
Definition: profiled_position_mode.hpp:32
virtual bool start()
Definition: profiled_position_mode.hpp:38
virtual bool read(const uint16_t &sw)
Definition: profiled_position_mode.hpp:44
SW_masks
Definition: profiled_position_mode.hpp:21
@ MASK_Acknowledged
Definition: profiled_position_mode.hpp:23
@ MASK_Error
Definition: profiled_position_mode.hpp:24
@ MASK_Reached
Definition: profiled_position_mode.hpp:22
@ SW_Target_reached
Definition: state.hpp:25
@ SW_Operation_mode_specific0
Definition: state.hpp:27
@ SW_Operation_mode_specific1
Definition: state.hpp:28
Definition: word_accessor.hpp:10
bool reset(uint8_t bit)
Definition: word_accessor.hpp:21
bool set(uint8_t bit)
Definition: word_accessor.hpp:15
bool get(uint8_t bit) const
Definition: word_accessor.hpp:27
Definition: configuration_manager.hpp:28