ros2_canopen master
C++ ROS CANopen Library
Loading...
Searching...
No Matches
command.hpp
Go to the documentation of this file.
1// Copyright 2023 Christoph Hellmann Santos
2// Copyright 2014-2022 Authors of ros_canopen
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16//
17
18#ifndef CANOPEN_402_DRIVER_COMMAND_HPP
19#define CANOPEN_402_DRIVER_COMMAND_HPP
20
21#include <boost/container/flat_map.hpp>
22#include <cstdint>
23#include <utility>
24#include "state.hpp"
25
26namespace ros2_canopen
27{
29{
30 struct Op
31 {
32 uint16_t to_set_;
33 uint16_t to_reset_;
34 Op(uint16_t to_set, uint16_t to_reset) : to_set_(to_set), to_reset_(to_reset) {}
35 void operator()(uint16_t & val) const { val = (val & ~to_reset_) | to_set_; }
36 };
37 class TransitionTable
38 {
39 boost::container::flat_map<std::pair<State402::InternalState, State402::InternalState>, Op>
40 transitions_;
41 void add(const State402::InternalState & from, const State402::InternalState & to, Op op)
42 {
43 transitions_.insert(std::make_pair(std::make_pair(from, to), op));
44 }
45
46 public:
47 TransitionTable();
48 const Op & get(const State402::InternalState & from, const State402::InternalState & to) const
49 {
50 return transitions_.at(std::make_pair(from, to));
51 }
52 };
53 static const TransitionTable transitions_;
54 static State402::InternalState nextStateForEnabling(State402::InternalState state);
55 Command402();
56
57public:
77 static bool setTransition(
78 uint16_t & cw, const State402::InternalState & from, const State402::InternalState & to,
80};
81} // namespace ros2_canopen
82
83#endif // CANOPEN_402_DRIVER_COMMAND_HPP
Definition command.hpp:29
ControlWord
Definition command.hpp:59
@ CW_Quick_Stop
Definition command.hpp:62
@ CW_Operation_mode_specific3
Definition command.hpp:69
@ CW_Switch_On
Definition command.hpp:60
@ CW_Manufacturer_specific1
Definition command.hpp:72
@ CW_Operation_mode_specific1
Definition command.hpp:65
@ CW_Manufacturer_specific2
Definition command.hpp:73
@ CW_Manufacturer_specific0
Definition command.hpp:71
@ CW_Operation_mode_specific0
Definition command.hpp:64
@ CW_Operation_mode_specific2
Definition command.hpp:66
@ CW_Manufacturer_specific4
Definition command.hpp:75
@ CW_Enable_Operation
Definition command.hpp:63
@ CW_Fault_Reset
Definition command.hpp:67
@ CW_Enable_Voltage
Definition command.hpp:61
@ CW_Manufacturer_specific3
Definition command.hpp:74
@ CW_Halt
Definition command.hpp:68
static bool setTransition(uint16_t &cw, const State402::InternalState &from, const State402::InternalState &to, State402::InternalState *next)
InternalState
Definition state.hpp:50
Definition configuration_manager.hpp:28