fill_trajectory_parameters.cpp
Go to the documentation of this file.
1 #include <mutex>
2 
3 #include <ram_msgs/AdditiveManufacturingTrajectory.h>
4 #include <ram_utils/GetFillParameters.h>
5 #include <ros/ros.h>
6 
7 #include <ram_utils/AddEntryExitStrategies.h>
8 
9 std::mutex params_mutex;
10 ram_msgs::AdditiveManufacturingParams params;
11 std::mutex trajectory_mutex;
12 ram_msgs::AdditiveManufacturingTrajectory trajectory;
13 
16 
18 {
19  if (trajectory.poses.empty())
20  return;
21 
22  for (auto &pose : trajectory.poses)
23  pose.params = params;
24 
25  // Add exit and entry Strategies
26  ram_utils::AddEntryExitStrategies srv;
27  srv.request.poses = trajectory.poses;
28  bool success = entry_exit_strategies_client.call(srv);
29  if (success)
30  trajectory.poses = srv.response.poses;
31 
32  // Now that the trajectory is complete, we set the time stamp to now and publish
33  trajectory.generated = ros::Time::now();
34  trajectory.modified = trajectory.generated;
35  pub_trajectory.publish(trajectory);
36 }
37 
38 void updateParams(const ram_msgs::AdditiveManufacturingParams::ConstPtr& msg)
39 {
40  std::lock_guard<std::mutex> lock_1(params_mutex);
41  std::lock_guard<std::mutex> lock_2(trajectory_mutex);
42  params = *msg;
43 }
44 
45 void tempTrajReceived(const ram_msgs::AdditiveManufacturingTrajectory::ConstPtr& msg)
46 {
47  std::lock_guard<std::mutex> lock_1(params_mutex);
48  std::lock_guard<std::mutex> lock_2(trajectory_mutex);
49  trajectory = *msg;
51 }
52 
53 bool getFillParams(ram_utils::GetFillParametersRequest &, ram_utils::GetFillParametersResponse &res)
54 {
55  std::lock_guard<std::mutex> lock(params_mutex);
56  res.parameters = params;
57  return true;
58 }
59 
60 int main(int argc, char** argv)
61 {
62  ros::init(argc, argv, "fill_trajectory_parameters");
64 
65  // Default parameters
66  params.approach_type = 1;
67  params.laser_power = 4000;
68  params.feed_rate = 2.0 / 60.0; // Wire - 2 meters / minute
69  params.movement_type = 1;
70  params.blend_radius = 0;
71  params.speed = 0.01; // meters / second
72 
74  spinner.start();
75 
76  // Subscribe to update internal parameters
77  ros::Subscriber sub_params = nh.subscribe("ram/fill_trajectory/parameters", 5, updateParams);
78 
79  // Subscribe to receive trajectory from path_planning
80  ros::Subscriber sub_traj = nh.subscribe("ram/trajectory_tmp", 5, tempTrajReceived);
81 
82  // Publish "ram/trajectory" to every node that listens
83  pub_trajectory = nh.advertise<ram_msgs::AdditiveManufacturingTrajectory>("ram/trajectory", 5, true);
84 
85  // Service to add strategies
86  entry_exit_strategies_client = nh.serviceClient<ram_utils::AddEntryExitStrategies>(
87  "ram/information/add_entry_exit_strategies");
88 
89 // Get fill parameters stored internally
90  ros::ServiceServer server = nh.advertiseService("ram/fill_trajectory/get_parameters", getFillParams);
91 
93  spinner.stop();
94  return 0;
95 }
96 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher pub_trajectory
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ram_msgs::AdditiveManufacturingParams params
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
void updateParams(const ram_msgs::AdditiveManufacturingParams::ConstPtr &msg)
std::mutex params_mutex
ram_msgs::AdditiveManufacturingTrajectory trajectory
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceClient entry_exit_strategies_client
void spinner()
int main(int argc, char **argv)
void tempTrajReceived(const ram_msgs::AdditiveManufacturingTrajectory::ConstPtr &msg)
std::mutex trajectory_mutex
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getFillParams(ram_utils::GetFillParametersRequest &, ram_utils::GetFillParametersResponse &res)
static Time now()
void publishModifiedTrajectory()
ROSCPP_DECL void waitForShutdown()


ram_utils
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:49:54