fastcat 0.13.15
C++ EtherCAT Device Command & Control Library
Loading...
Searching...
No Matches
manager.h
Go to the documentation of this file.
1#ifndef FASTCAT_MANAGER_H_
2#define FASTCAT_MANAGER_H_
3
4// Include related header (for cc files)
5
6// Include c then c++ libraries
7#include <memory>
8#include <mutex>
9#include <queue>
10#include <unordered_map>
11#include <vector>
12
13// Include external then project includes
14#include <yaml-cpp/yaml.h>
15
16#include "fastcat/thread_safe_queue.h"
17#include "fastcat/device_base.h"
18#include "fastcat/jsd/actuator.h"
19#include "fastcat/jsd/jsd_device_base.h"
20#include "jsd/jsd.h"
21
22namespace fastcat
23{
24typedef std::pair<std::string, std::shared_ptr<DeviceBase>> DevicePair;
25typedef std::pair<std::string, jsd_t*> JSDPair;
26
31{
32 public:
33 Manager();
34 ~Manager();
35
41 void Shutdown();
42
48 bool ConfigFromYaml(const YAML::Node& node, double external_time = -1);
49
54 bool CreateConfigFromYaml(const YAML::Node& node, double external_time = -1);
55
60 bool InitHardware();
61
85 bool Process(double external_time = -1);
86
96 void QueueCommand(DeviceCmd& cmd);
97
102 std::vector<DeviceState> GetDeviceStates();
103
111 std::vector<std::shared_ptr<const DeviceState>> GetDeviceStatePointers();
112
116 double GetTargetLoopRate();
117
121 bool IsFaulted();
122
132 bool RecoverBus(std::string ifname);
133
140 bool ExecuteDeviceReset(std::string device_name);
141
148 bool ExecuteDeviceFault(std::string device_name);
149
158
168
173
181 bool PopSdoResponseQueue(SdoResponse& res);
182
187 bool GetActuatorParams(const std::string& name,
189
192 void GetDeviceNamesByType(std::vector<std::string>&,
193 fastcat::DeviceStateType);
194
198
202
207
212
219 bool SetExplicitInterpolationCyclesDelay(size_t delay);
220
223 bool SetInterpolationCyclesStale(size_t cycles);
224
225
226 private:
227 bool ConfigJSDBusFromYaml(const YAML::Node& node, double external_time);
228 bool ConfigFastcatBusFromYaml(const YAML::Node& node, double external_time);
229 bool ConfigOfflineBusFromYaml(const YAML::Node& node, double external_time);
230 bool WriteCommands();
231 bool ConfigSignals();
232 bool SortFastcatDevice(
233 std::shared_ptr<DeviceBase> device,
234 std::vector<std::shared_ptr<DeviceBase>>& sorted_devices,
235 std::vector<std::string> parents);
236
237 bool LoadActuatorPosFile();
238 bool ValidateActuatorPosFile();
239 bool SetActuatorPositions();
240 void GetActuatorPositions();
241 void SaveActuatorPosFile();
242 bool CheckDeviceNameIsUnique(std::string name);
243 struct JsdBusInitParams {
244 std::string ifname;
245 jsd_t* jsd;
246 bool enable_autorecovery;
247 };
248
249 double target_loop_rate_hz_ = 0.0;
250 bool zero_latency_required_ = true;
251 bool faulted_ = true;
252 bool actuator_fault_on_missing_pos_file_ = true;
253 bool online_devices_exist_ = false;
254 std::string actuator_position_directory_;
255 std::map<std::string, jsd_t*> jsd_map_;
256
257 std::map<std::string, std::shared_ptr<DeviceBase>> device_map_;
258 std::vector<std::shared_ptr<DeviceBase>> fastcat_device_list_;
259 std::vector<std::shared_ptr<JsdDeviceBase>> jsd_device_list_;
260 std::shared_ptr<ThreadSafeQueue<DeviceCmd>> cmd_queue_;
261 std::vector<DeviceState> states_;
262 std::map<std::string, ActuatorPosData> actuator_pos_map_;
263 std::unordered_map<std::string, bool> unique_device_map_;
264 std::shared_ptr<std::queue<SdoResponse>> sdo_response_queue_;
265
266 std::vector<JsdBusInitParams> pending_jsd_inits_;
267
268 std::mutex parameter_mutex_;
269
270};
271} // namespace fastcat
272
273#endif
Fastcat::Manager is the main application interface to manage all fastcat devices.
Definition manager.h:31
bool RecoverBus(std::string ifname)
Attempts to recover a faulty JSD bus by name.
Definition manager.cc:419
std::vector< std::shared_ptr< const DeviceState > > GetDeviceStatePointers()
Returns list of device state pointers.
Definition manager.cc:375
double GetTargetLoopRate()
Public getter to the YAML target_loop_rate_hz parameter.
Definition manager.cc:389
bool ExecuteDeviceFault(std::string device_name)
Triggers a single device to fault.
Definition manager.cc:950
bool CreateConfigFromYaml(const YAML::Node &node, double external_time=-1)
Parses YAML configuration and creates device objects (no hardware init)
Definition manager.cc:100
void SetExplicitInterpolationAlgorithmLinear()
Set interpolation algorithm to use 1st order linear interpolation between knot points for both positi...
Definition manager.cc:1314
bool IsSdoResponseQueueEmpty()
checks if the SdoResponse Queue is empty
Definition manager.cc:1021
void ExecuteAllDeviceFaults()
Triggers all devices to Fault.
Definition manager.cc:990
bool ConfigFromYaml(const YAML::Node &node, double external_time=-1)
Method that accepts a fastcat topology yaml and intializes bus.
Definition manager.cc:214
void ExecuteAllDeviceResets()
Triggers all devices to Reset.
Definition manager.cc:1008
void QueueCommand(DeviceCmd &cmd)
Interface to command devices on the bus.
Definition manager.cc:359
void SetExplicitInterpolationAlgorithmCubic()
Set interpolation algorithm to use 3rd order cubic interpolation between knot points for all actuator...
Definition manager.cc:1301
bool InitHardware()
Initializes EtherCAT hardware (executes deferred jsd_init calls)
Definition manager.cc:223
void SetExplicitInterpolationTimestampSourceClock()
Set interpolation algorithm to use the timestamp when the CSP message was received according to fastc...
Definition manager.cc:1340
bool GetActuatorParams(const std::string &name, fastcat::Actuator::ActuatorParams &param)
get actuator parameters
Definition manager.cc:404
void Shutdown()
Shutdown the bus and joins all threads.
Definition manager.cc:94
bool IsFaulted()
Public getter retrieve fault status.
Definition manager.cc:391
void SetExplicitInterpolationTimestampSourceCspMessage()
Set interpolation algorithm to use the timestamp in the CSP message generated by the calling module f...
Definition manager.cc:1327
std::vector< DeviceState > GetDeviceStates()
Returns list of device states.
Definition manager.cc:361
bool ExecuteDeviceReset(std::string device_name)
Triggers a single device to reset.
Definition manager.cc:970
bool Process(double external_time=-1)
Updates synchronous PDO and background async SDO requests.
Definition manager.cc:254
void GetDeviceNamesByType(std::vector< std::string > &, fastcat::DeviceStateType)
names of actuator devices
Definition manager.cc:393
bool SetInterpolationCyclesStale(size_t cycles)
CSP interpolation will transition to a holding state if it has not received a CSP message within the ...
Definition manager.cc:1370
bool SetExplicitInterpolationCyclesDelay(size_t delay)
Set number of cycles of the calling module to delay the onset of explicit interpolation,...
Definition manager.cc:1353
Manager()
Definition manager.cc:78
~Manager()
Definition manager.cc:84
bool PopSdoResponseQueue(SdoResponse &res)
get the result of a background SDO operation
Definition manager.cc:1026
Definition device_base.h:18
std::pair< std::string, std::shared_ptr< DeviceBase > > DevicePair
Definition manager.h:24
std::pair< std::string, jsd_t * > JSDPair
Definition manager.h:25
Definition actuator.h:109