plcopen 0.22.0
载入中...
搜索中...
未找到
mode_manager.h
浏览该文件的文档.
1#pragma once
2
3// BS6.3: CSP/CSV/CST mode-management skeleton (bumpless switching). The
4// library's setpoints carry the full kinematic state every cycle, so a
5// bumpless switch means: at the switch instant the field the next mode hands
6// to the drive equals the drive's current state — no position, velocity, or
7// torque step. This skeleton latches the last emitted setpoints on a switch
8// and asserts the continuity contract; the drive-side handshake (modes of
9// operation / display polling over the object dictionary) is B5 scope in the
10// real-drive context.
11
12#include <cmath>
13
14#include "adapters/servo.h"
15#include "rt/error.h"
16
18{
19
20enum class OperationMode : std::uint8_t
21{
22 csp, // cyclic synchronous position
23 csv, // cyclic synchronous velocity
24 cst, // cyclic synchronous torque
25};
26
28{
29public:
31 {
32 return mode_;
33 }
34
35 // Bumpless switch: only defined when the stream is live (a latched
36 // last-setpoints state exists) — the next mode continues from it.
38 {
39 if(!primed_) {
41 }
42 mode_ = next;
43 return rt::ErrorCode::ok;
44 }
45
46 // Per-cycle emission: passes the full-order setpoints through and
47 // latches them for the next switch; the primary field per mode is the
48 // continuity-asserted channel.
50 {
51 last_ = setpoints;
52 primed_ = true;
53 return setpoints;
54 }
55
56 const ServoSetpoints &latched() const
57 {
58 return last_;
59 }
60
61 // The channel the drive consumes in the current mode.
62 double primary_channel(const ServoSetpoints &setpoints) const
63 {
64 switch(mode_) {
66 return setpoints.position;
68 return setpoints.velocity;
70 return setpoints.torque;
71 }
72 return setpoints.position;
73 }
74
75private:
77 ServoSetpoints last_{};
78 bool primed_ = false;
79};
80
81} // namespace plcopen::core::adapters
double primary_channel(const ServoSetpoints &setpoints) const
const ServoSetpoints & latched() const
rt::ErrorCode switch_mode(OperationMode next)
ServoSetpoints emit(const ServoSetpoints &setpoints)