4 #include <ram_msgs/AdditiveManufacturingTrajectory.h> 5 #include <ram_msgs/AdditiveManufacturingTrajectoryInfo.h> 6 #include <ram_utils/GetLayerSize.h> 7 #include <ram_utils/GetNumberOfLayersLevels.h> 8 #include <ram_utils/GetTrajectoryInfos.h> 9 #include <ram_utils/GetTrajectorySize.h> 13 ram_msgs::AdditiveManufacturingTrajectory
layers;
16 ram_msgs::AdditiveManufacturingTrajectoryInfo
traj_info;
18 void trajReceived(
const ram_msgs::AdditiveManufacturingTrajectory::Ptr& msg)
26 traj_info.generation_info = msg->generation_info;
29 traj_info.similar_layers = msg->similar_layers;
30 traj_info.number_of_poses = msg->poses.size();
37 if (msg->poses.empty())
43 traj_info.number_of_layers_levels = msg->poses.back().layer_level + 1;
44 traj_info.number_of_layers_indices = msg->poses.back().layer_index + 1;
46 unsigned polygon_count(0);
47 for (
auto pose : msg->poses)
49 if (pose.polygon_start ==
true)
52 traj_info.number_of_polygons = polygon_count;
54 Eigen::Vector3d last_position(msg->poses.front().pose.position.x,
55 msg->poses.front().pose.position.y,
56 msg->poses.front().pose.position.z);
57 double last_speed(msg->poses.front().params.speed);
58 double last_feed_rate(msg->poses.front().params.feed_rate);
59 for (
auto pose : msg->poses)
62 Eigen::Vector3d position(pose.pose.position.x, pose.pose.position.y, pose.pose.position.z);
63 Eigen::Vector3d difference(position - last_position);
64 traj_info.trajectory_length += difference.norm();
67 double speed(pose.params.speed);
70 if (pose.params.approach_type == 0)
73 const double mean_speed((last_speed + speed) / 2.0);
74 const double segment_time(difference.norm() / mean_speed);
79 double mean_feed_rate((last_feed_rate + pose.params.feed_rate) / 2.0);
80 traj_info.wire_length += segment_time * mean_feed_rate;
82 last_position = position;
90 ram_utils::GetTrajectorySize::Response &res)
93 res.trajectory_size =
layers.poses.size();
98 ram_utils::GetNumberOfLayersLevels::Response &res)
106 unsigned max_layer_level = 0;
107 for (
auto pose :
layers.poses)
109 if (max_layer_level < pose.layer_level)
110 max_layer_level = pose.layer_level;
113 res.number_of_layers = max_layer_level + 1;
118 ram_utils::GetLayerSize::Response &res)
126 if (req.layer_level >
layers.poses.back().layer_level)
129 unsigned pose_count = 0;
130 for (
auto &pose :
layers.poses)
131 if (pose.layer_level == req.layer_level)
134 res.layer_size = pose_count;
140 ram_utils::GetTrajectoryInfos::Response &res)
150 ros::init(argc, argv,
"ram_utils_trajectory_info");
160 pub_traj_info = nh.
advertise<ram_msgs::AdditiveManufacturingTrajectoryInfo>(
"ram/information/trajectory", 1,
true);
int main(int argc, char **argv)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool getNumberOfLayersLevelsCallback(ram_utils::GetNumberOfLayersLevels::Request &, ram_utils::GetNumberOfLayersLevels::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ram_msgs::AdditiveManufacturingTrajectory layers
std::mutex traj_info_mutex
bool getLayerSizeCallback(ram_utils::GetLayerSize::Request &req, ram_utils::GetLayerSize::Response &res)
bool getTrajectorySizeCallback(ram_utils::GetTrajectorySize::Request &, ram_utils::GetTrajectorySize::Response &res)
bool getTrajectoryInfosCallback(ram_utils::GetTrajectoryInfos::Request &, ram_utils::GetTrajectoryInfos::Response &res)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ram_msgs::AdditiveManufacturingTrajectoryInfo traj_info
ros::Publisher pub_traj_info
void trajReceived(const ram_msgs::AdditiveManufacturingTrajectory::Ptr &msg)
std::mutex trajectory_mutex
ROSCPP_DECL void waitForShutdown()