1#ifndef FASTCAT_MANAGER_H_
2#define FASTCAT_MANAGER_H_
10#include <unordered_map>
14#include <yaml-cpp/yaml.h>
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"
24typedef std::pair<std::string, std::shared_ptr<DeviceBase>>
DevicePair;
25typedef std::pair<std::string, jsd_t*>
JSDPair;
48 bool ConfigFromYaml(
const YAML::Node& node,
double external_time = -1);
85 bool Process(
double external_time = -1);
193 fastcat::DeviceStateType);
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);
237 bool LoadActuatorPosFile();
238 bool ValidateActuatorPosFile();
239 bool SetActuatorPositions();
240 void GetActuatorPositions();
241 void SaveActuatorPosFile();
242 bool CheckDeviceNameIsUnique(std::string name);
243 struct JsdBusInitParams {
246 bool enable_autorecovery;
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_;
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_;
266 std::vector<JsdBusInitParams> pending_jsd_inits_;
268 std::mutex parameter_mutex_;
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 ¶m)
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