10 #ifndef DYNAMIC_GRAPH_MANAGER_HH 11 #define DYNAMIC_GRAPH_MANAGER_HH 32 #include "yaml_cpp_catkin/yaml_cpp_fwd.hpp" 36 #include <std_srvs/Empty.h> 39 #include "real_time_tools/thread.hpp" 42 #include <real_time_tools/spinner.hpp> 45 #include "real_time_tools/timer.hpp" 48 #include "shared_memory/locked_condition_variable.hpp" 65 typedef std::chrono::steady_clock
clock;
194 std::runtime_error(std::string(
"DynamicGraphManager::") +
195 "initialize_hardware_communication_process(): " +
196 "this method needs to be overloaded"));
209 std::runtime_error(
"DynamicGraphManager::" 210 "get_sensors_to_map(VectorDGMap&): " 211 "this method needs to be overloaded"));
223 throw(std::runtime_error(
224 "DynamicGraphManager::" 225 "set_motor_controls_from_map(const VectorDGMap&): " 226 "this method needs to be overloaded"));
316 std::runtime_error(
"DynamicGraphManager::device():Try" 317 "accessing a device that has not been created"));
334 bool too_much_missed_control =
336 static bool once_tmmc =
false;
337 if (too_much_missed_control && !once_tmmc)
340 "HARDWARE: Too much missed control (%d/%d), going in safe " 348 static bool once_hdgd =
false;
349 if (dg_died && !once_hdgd)
352 "HARDWARE: Dynamic Graph process died, going in safe mode\n");
355 return too_much_missed_control || dg_died;
413 std_srvs::Empty::Response&)
425 std_srvs::Empty::Response&)
532 std::unique_ptr<dynamic_graph::RosPythonInterpreter>
545 std::unique_ptr<real_time_tools::RealTimeThread>
583 std::unique_ptr<shared_memory::LockedConditionVariable>
cond_var_;
785 std::mutex hwc_mutex_;
790 #endif // DYNAMIC_GRAPH_MANAGER_HH clock::time_point hw_time_loop_before_sleep_
hw_time_loop_before_sleep_ is the time measurement just before the hardware communication loop goes t...
Definition: dynamic_graph_manager.hh:613
Device & device()
device is a getter method on the Device internal pointer.
Definition: dynamic_graph_manager.hh:312
YAML::Node params_
params_ is the pool of parameters in a yaml tree
Definition: dynamic_graph_manager.hh:783
virtual void run_hardware_communication_process()
run_hardware_communication_process spawns the real time thread.
Definition: dynamic_graph_manager.cpp:431
void wait_stop_dynamic_graph()
wait_stop_dynamic_graph put the current thread to sleep until the user stop the dynamic graph ...
Definition: dynamic_graph_manager.cpp:273
virtual void get_sensors_to_map(VectorDGMap &)
get_sensors_to_map is the fonction that get the motor command from a map and that uses the drivers to...
Definition: dynamic_graph_manager.hh:206
std::deque< ros::ServiceServer > ros_user_commands_
Attribute shared with the daughter class.
Definition: dynamic_graph_manager.hh:772
std::string dg_active_timer_file_
dg_active_timer_file_ this is the path to the file that will contain the computation time of each of ...
Definition: dynamic_graph_manager.hh:650
unsigned max_missed_control_
max_missed_control_ if the missed_control_count_ reach the value of max_missed_control_ then we switc...
Definition: dynamic_graph_manager.hh:602
static const std::string dg_ros_node_name_
dg_ros_node_name_ this is the ros node name of the dynamic graph process
Definition: dynamic_graph_manager.hh:362
std::unique_ptr< real_time_tools::RealTimeThread > thread_hardware_communication_
thread_hardware_communication_ is the real thread that communicate with the hardware.
Definition: dynamic_graph_manager.hh:546
void * hardware_communication_real_time_loop()
hardware_communication_real_time_loop is the method that communicate with the hardware and send the c...
Definition: dynamic_graph_manager.cpp:541
ros::ServiceServer ros_service_start_dg_
ros_service_start_dg_ allows to start the dynamic graph on call.
Definition: dynamic_graph_manager.hh:501
virtual void run_single_process()
run_single_process spawns the real time thread.
Definition: dynamic_graph_manager.cpp:455
void python_prologue()
python_prologue get the pointer of the device in the the python interpretor.
Definition: dynamic_graph_manager.cpp:380
virtual void set_motor_controls_from_map(const VectorDGMap &)
set_motor_controls_from_map is the fonction that get the motor command from a map and that uses the d...
Definition: dynamic_graph_manager.hh:221
clock::duration hw_meas_active_time_
hw_meas_active_time_ is the time during which the hardware communication process is supposed to sleep...
Definition: dynamic_graph_manager.hh:637
real_time_tools::Timer dg_timer_
dg_timer_ is the timer measuring the duration time of the dynamic graph loop.
Definition: dynamic_graph_manager.hh:716
std::unique_ptr< Device > device_
device_ is the DynamicGraph device that manages the computation of the graph.
Definition: dynamic_graph_manager.hh:565
clock::time_point hw_time_loop_after_sleep_
hw_time_loop_after_sleep_ is the time measurement just after the hardware communication loop goes to ...
Definition: dynamic_graph_manager.hh:619
std::string hwc_timer_file_
hwc_timer_file_ this is the path to the file that will contain the computation time of each of the ha...
Definition: dynamic_graph_manager.hh:682
double maximum_time_for_user_cmd_
This the duration during which a user command can be executed.
Definition: dynamic_graph_manager.hh:757
bool is_dynamic_graph_stopped()
get the status of the dynamic graph (is running or not)
Definition: dynamic_graph_manager.hh:259
void initialize_dynamic_graph_process()
initialize_dynamic_graph_process instanciates all variables related to the dynamic_graph and user int...
Definition: dynamic_graph_manager.cpp:330
std::string hwc_active_timer_file_
hwc_active_timer_file_ this is the path to the file that will contain the computation time of each ac...
Definition: dynamic_graph_manager.hh:669
bool has_been_waken_by_dg_
has_been_waken_by_dg_ is a flag that indicates if the hardware communication process has been awaken ...
Definition: dynamic_graph_manager.hh:590
std::atomic< bool > is_dynamic_graph_stopped_
is_dynamic_graph_stopped_ is the flag reflecting the state of the dynamic graph.
Definition: dynamic_graph_manager.hh:517
static const std::string hw_com_ros_node_name_
hw_com_ros_node_name_ this is the ros node name of the harware communication process ...
Definition: dynamic_graph_manager.hh:368
real_time_tools::Timer hwc_active_timer_
hwc_active_timer is measuring the active time of the hardware communication loop
Definition: dynamic_graph_manager.hh:722
std::unique_ptr< real_time_tools::RealTimeThread > thread_dynamic_graph_
thread_dynamic_graph_ is the real time thread that runs the dynamic graph.
Definition: dynamic_graph_manager.hh:539
pid_t pid_hardware_communication_process_
pid_hardware_communication_process_ is the pid of the hardware communication process.
Definition: dynamic_graph_manager.hh:559
bool start_dynamic_graph(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
Method NOT inherited.
Definition: dynamic_graph_manager.hh:412
virtual void run_dynamic_graph_process()
run_dynamic_graph_process spawns the real time thread and becomes a ros spinner (thread in charge of ...
Definition: dynamic_graph_manager.cpp:411
bool stop_dynamic_graph(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
stop_dg is the callback method of the ROS service stop dynamic graph
Definition: dynamic_graph_manager.hh:424
clock::duration hw_meas_sleep_time_
hw_measured_sleep_time_ is the time during which the hardware communication process actually slept...
Definition: dynamic_graph_manager.hh:625
static const std::string cond_var_name_
cond_var_sensors_name_ is the name of the condition variable in the shared memory ...
Definition: dynamic_graph_manager.hh:392
void * dynamic_graph_real_time_loop()
dynamic_graph_real_time_loop is the method used to execute the dynamic graph.
Definition: dynamic_graph_manager.cpp:479
std::map< std::string, dynamicgraph::Vector > VectorDGMap
VectorDGMap is a shortcut for the very long type of the map.
Definition: tools.hh:22
double control_period_sec_
control_period_sec_ this is the control period in Seconds (S.I.
Definition: dynamic_graph_manager.hh:778
unsigned memory_buffer_timers_
memory_buffer_timers_ is the size of the memory buffers for the real_time_tools timers.
Definition: dynamic_graph_manager.hh:739
void stop_hardware_communication()
stop_hardware_communication stops the hardware communication.
Definition: dynamic_graph_manager.hh:267
virtual void compute_safety_controls()
compute_safety_controls computes safety controls very fast in case the dynamic graph is taking to muc...
Definition: dynamic_graph_manager.cpp:685
std::chrono::steady_clock clock
clock is the std::chrono::high_resolution_clock object.
Definition: dynamic_graph_manager.hh:65
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
real_time_tools::Timer hwc_sleep_timer_
hwc_sleep_timer is measuring the sleeping time of the hardware communication loop ...
Definition: dynamic_graph_manager.hh:728
std::string python_log_file_
This file will contain the python interpreter output.
Definition: dynamic_graph_manager.hh:693
virtual void initialize_hardware_communication_process()
initialize_hardware_communication_process instanciate all variables related to the hardware communica...
Definition: dynamic_graph_manager.hh:191
std::deque< std::function< void(void)> > user_commands_
This is the list of the user commands.
Definition: dynamic_graph_manager.hh:762
std::string log_dir_
log_folder_ is the folder where all the data of the current experiment will be saved.
Definition: dynamic_graph_manager.hh:688
real_time_tools::Timer dg_active_timer_
dg_active_timer_ is the timer measuring the computation time of the dynamic graph loop...
Definition: dynamic_graph_manager.hh:704
This class has for purpose to manage the different processes during run time.
Definition: dynamic_graph_manager.hh:92
std::string dg_sleep_timer_file_
dg_sleep_timer_file_ this is the path to the file that will contain the sleep duration of the dynamic...
Definition: dynamic_graph_manager.hh:656
std::unique_ptr< shared_memory::LockedConditionVariable > cond_var_
cond_var_sensors_ this condition variable allow the computation of the dynamic graph just after the a...
Definition: dynamic_graph_manager.hh:583
clock::duration hw_ref_sleep_time_
hw_ref_sleep_time_ is the time during which the hardware communication process is supposed to sleep...
Definition: dynamic_graph_manager.hh:631
unsigned missed_control_count_
missed_control_count_ is counting the number of iteration when the dynamic_graph failed to provide da...
Definition: dynamic_graph_manager.hh:596
static void * single_process_real_time_loop_helper(void *context)
dynamic_graph_real_time_loop_helper is a static member allowing to use the posix pthread_create.
Definition: dynamic_graph_manager.hh:486
static const std::string motor_controls_map_name_
motor_controls_map_name is the name of the motor controls map inside the shared memory segment ...
Definition: dynamic_graph_manager.hh:386
bool is_real_robot_
is_real_robot this boolean is a parameter to indicate if yes or no we are in simulation or in a real ...
Definition: dynamic_graph_manager.hh:643
ros::ServiceServer ros_service_stop_dg_
ros_service_stop_dg_ allows to stop the dynamic graph on call.
Definition: dynamic_graph_manager.hh:508
real_time_tools::Timer dg_sleep_timer_
dg_sleep_timer_ is the timer measuring the time during which the dynamic graph loop sleeps...
Definition: dynamic_graph_manager.hh:710
VectorDGMap motor_controls_map_
motor_controls_map_ is a map of dynamicgraph::Vector.
Definition: dynamic_graph_manager.hh:577
virtual ~DynamicGraphManager()
DynamicGraphManager, destructor of the class.
Definition: dynamic_graph_manager.cpp:69
real_time_tools::Spinner hwc_spinner_
This class allows us to time the real time thread for the hardware communication. ...
Definition: dynamic_graph_manager.hh:745
static const std::string shared_memory_name_
shared_memory_name is the name of the shared memory segment to be used
Definition: dynamic_graph_manager.hh:374
pid_t pid_dynamic_graph_process()
pid_dynamic_graph_process is an accessor on the pid of the process
Definition: dynamic_graph_manager.hh:293
clock::duration control_period_
control_period_ this is the control period in nanoseconds.
Definition: dynamic_graph_manager.hh:607
real_time_tools::Timer hwc_timer_
hwc_timer is measuring the time of the hardware communication loop
Definition: dynamic_graph_manager.hh:733
std::string dg_timer_file_
dg_timer_file_ this is the path to the file that will contain the time of the dynamic graph loop...
Definition: dynamic_graph_manager.hh:662
pid_t pid_hardware_communication_process()
pid_hardware_communication_process is an accessor on the pid of the process
Definition: dynamic_graph_manager.hh:303
void run_python_command(std::ostream &file, const std::string &command)
run_python_command
Definition: dynamic_graph_manager.cpp:359
std::string app_dir_
This is the application directory in the home directory.
Definition: dynamic_graph_manager.hh:698
double hwc_predicted_sleeping_time_
This corresponds to the predicted sleeping time for the hardware communication process.
Definition: dynamic_graph_manager.hh:752
void start_hardware_communication()
start_hardware_communication starts the hardware communication.
Definition: dynamic_graph_manager.hh:275
void run()
run() splits the process in the dynamic_graph process and the hadware_communication process...
Definition: dynamic_graph_manager.cpp:221
DynamicGraphManager()
DynamicGraphManager, constructor of the class.
Definition: dynamic_graph_manager.cpp:34
pid_t pid_dynamic_graph_process_
pid_dynamic_graph_process_ is the pid of the DynamicGraph process.
Definition: dynamic_graph_manager.hh:552
static void * dynamic_graph_real_time_loop_helper(void *context)
dynamic_graph_real_time_loop_helper is a static member allowing to use the posix pthread_create.
Definition: dynamic_graph_manager.hh:449
std::atomic< bool > is_hardware_communication_stopped_
is_hardware_communication_stopped_ is the flag reflecting the state of the hardware communication thr...
Definition: dynamic_graph_manager.hh:526
void initialize(YAML::Node param)
initialize the basic variables
Definition: dynamic_graph_manager.cpp:104
void start_ros_service(ros::NodeHandle &ros_node_handle)
start_ros_service is the method that advertise the different ros services.
Definition: dynamic_graph_manager.cpp:468
std::unique_ptr< dynamic_graph::RosPythonInterpreter > ros_python_interpreter_
ros_python_interpreter_ptr_ is a ROS wrapper around a python interpreter.
Definition: dynamic_graph_manager.hh:533
void add_user_command(std::function< void(void)> func)
Method inherited.
Definition: dynamic_graph_manager.cpp:722
static const std::string sensors_map_name_
sensors_map_name is the name of the sensor map inside the shared memory segment
Definition: dynamic_graph_manager.hh:380
virtual bool is_in_safety_mode()
is_in_safety_mode check if the dynamic graph is still alive and sending commands at a descent frequen...
Definition: dynamic_graph_manager.hh:332
void wait_stop_hardware_communication()
wait_stop_hardware_communication put the current thread to sleep until the user stop the hardware com...
Definition: dynamic_graph_manager.cpp:288
void stop_dynamic_graph()
stop_dynamic_graph stop the DynamicGraph.
Definition: dynamic_graph_manager.hh:242
void * single_process_real_time_loop()
single_process_real_time_loop is the method that performs the control but in one single process...
Definition: dynamic_graph_manager.cpp:696
void start_dynamic_graph()
start_dynamic_graph start the DynamicGraph.
Definition: dynamic_graph_manager.hh:250
static void * hardware_communication_real_time_loop_helper(void *context)
dynamic_graph_real_time_loop_helper is a static member allowing to use the posix pthread_create.
Definition: dynamic_graph_manager.hh:468
std::string hwc_sleep_timer_file_
hwc_sleep_timer_file_ this is the path to the file that will contain the sleeping time of the hardwar...
Definition: dynamic_graph_manager.hh:675
VectorDGMap sensors_map_
sensors_map_ is a map of dynamicgraph::Vector.
Definition: dynamic_graph_manager.hh:571
void wait_start_dynamic_graph()
wait_start_dynamic_graph put the current thread to sleep until the user start the dynamic graph ...
Definition: dynamic_graph_manager.cpp:264
bool is_hardware_communication_stopped()
get the status of the hardware communication (is running or not).
Definition: dynamic_graph_manager.hh:284
bool has_dynamic_graph_process_died()
has_dynamic_graph_process_died check if the process of the DynamicGraph has died or not...
Definition: dynamic_graph_manager.cpp:303