Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
cia402_drive.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <expected>
5#include <string>
6
7#include "node/cia402.h"
9
10namespace mm::node {
11
27class Cia402Drive : public ProfileDevice {
28 public:
31
33 std::expected<cia402::State, std::string> state() const;
34
36 std::expected<uint16_t, std::string> statusword() const;
37
39 std::expected<uint16_t, std::string> controlword() const;
40
46 std::expected<void, std::string> setControlword(uint16_t value);
47
49 std::expected<cia402::OperationMode, std::string> operationMode() const;
50
52 std::expected<void, std::string> setOperationMode(cia402::OperationMode mode);
53
54 // --- State-machine transitions ------------------------------------------------------------
55 // Each issues exactly one controlword edge via a read-modify-write that touches only the
56 // command bits (cia402::kCommandMask), preserving mode-specific / halt / manufacturer bits.
57 // They command a transition; they do not wait for the drive to reach the target state.
58
60 std::expected<void, std::string> shutdown();
61
63 std::expected<void, std::string> switchOn();
64
66 std::expected<void, std::string> enableOperation();
67
69 std::expected<void, std::string> disableVoltage();
70
72 std::expected<void, std::string> quickStop();
73
80 std::expected<void, std::string> faultReset();
81
82 // --- Convenience walks ---------------------------------------------------------------------
83
95 std::expected<void, std::string> enable(
96 std::chrono::milliseconds timeout = std::chrono::milliseconds(2000));
97
99 std::expected<void, std::string> disable();
100
101 // --- Cyclic setpoints (typed convenience over the standard objects) ------------------------
102
104 std::expected<void, std::string> setTargetPosition(int32_t counts);
105
107 std::expected<void, std::string> setTargetVelocity(int32_t value);
108
110 std::expected<void, std::string> setTargetTorque(int16_t perMille);
111
113 std::expected<int32_t, std::string> positionActualValue() const;
114
116 std::expected<int32_t, std::string> velocityActualValue() const;
117
118 private:
121 std::expected<void, std::string> applyCommand(uint16_t command);
122};
123
133std::expected<Cia402Drive, std::string> createCia402Drive(Device& device);
134
135} // namespace mm::node
Pure CiA402 (CANopen drive profile, ETG.6010) vocabulary — object indices, control/status word bit la...
Borrowed view of a CiA402 drive — the device control state machine, operation modes,...
Definition cia402_drive.h:27
std::expected< void, std::string > quickStop()
Quick stop: → QuickStopActive.
Definition cia402_drive.cc:77
std::expected< void, std::string > enableOperation()
Enable operation: SwitchedOn → OperationEnabled.
Definition cia402_drive.cc:69
std::expected< void, std::string > faultReset()
Fault reset: asserts the rising edge of controlword bit 7 to clear a latched fault.
Definition cia402_drive.cc:81
std::expected< void, std::string > disable()
Brings the drive to SwitchOnDisabled (disable voltage). Single transition.
Definition cia402_drive.cc:98
std::expected< void, std::string > shutdown()
Shutdown: → ReadyToSwitchOn.
Definition cia402_drive.cc:61
Cia402Drive(Device &device)
Binds an (unchecked) CiA402 view to device. Prefer createCia402Drive.
Definition cia402_drive.h:30
std::expected< void, std::string > disableVoltage()
Disable voltage: → SwitchOnDisabled.
Definition cia402_drive.cc:73
std::expected< cia402::OperationMode, std::string > operationMode() const
Reads the active operation mode (display object 0x6061).
Definition cia402_drive.cc:39
std::expected< void, std::string > setTargetVelocity(int32_t value)
Writes target velocity (0x60FF, INTEGER32) — CSV / PV.
Definition cia402_drive.cc:156
std::expected< void, std::string > enable(std::chrono::milliseconds timeout=std::chrono::milliseconds(2000))
Drives the state machine to OperationEnabled, walking every intermediate transition.
Definition cia402_drive.cc:100
std::expected< void, std::string > switchOn()
Switch on: ReadyToSwitchOn → SwitchedOn (also disables operation from enabled).
Definition cia402_drive.cc:65
std::expected< int32_t, std::string > positionActualValue() const
Reads actual position (0x6064, INTEGER32).
Definition cia402_drive.cc:164
std::expected< void, std::string > setTargetTorque(int16_t perMille)
Writes target torque (0x6071, INTEGER16, per-mille of rated) — CST / PT.
Definition cia402_drive.cc:160
std::expected< void, std::string > setTargetPosition(int32_t counts)
Writes target position (0x607A, INTEGER32) — CSP / PP.
Definition cia402_drive.cc:152
std::expected< cia402::State, std::string > state() const
Reads and decodes the current state machine state (statusword 0x6041).
Definition cia402_drive.cc:35
std::expected< uint16_t, std::string > statusword() const
Reads the raw statusword (0x6041).
Definition cia402_drive.cc:23
std::expected< void, std::string > setOperationMode(cia402::OperationMode mode)
Requests an operation mode (0x6060). The drive reflects it in 0x6061 once accepted.
Definition cia402_drive.cc:47
std::expected< uint16_t, std::string > controlword() const
Reads the last-commanded controlword (0x6040).
Definition cia402_drive.cc:27
std::expected< void, std::string > setControlword(uint16_t value)
Writes the controlword (0x6040) verbatim.
Definition cia402_drive.cc:31
std::expected< int32_t, std::string > velocityActualValue() const
Reads actual velocity (0x606C, INTEGER32).
Definition cia402_drive.cc:168
Represents a single node on the fieldbus.
Definition device.h:36
Base of the drive-profile view hierarchy: a thin, borrowed view over a Device.
Definition profile_device.h:31
Device & device()
The underlying generic device this view operates on.
Definition profile_device.h:37
OperationMode
CiA402 operation modes (object 0x6060 / 0x6061 values).
Definition cia402.h:35
Definition http_server.h:16
std::expected< Cia402Drive, std::string > createCia402Drive(Device &device)
Validates that device implements the CiA402 profile, then binds a view to it.
Definition cia402_drive.cc:172