All Classes Namespaces Files Functions Variables Typedefs
rviz_object.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <string>
3 #include <std_msgs/Float32.h>
4 #include <std_msgs/Bool.h>
5 #include <visualization_msgs/Marker.h>
6 //#include <rvix> en dan nog wat dingen
7 
8 
9 void rvizUpdater(const std_msgs::Float32::ConstPtr&);
10 void shutdown(const std_msgs::Bool::ConstPtr&);
11 ros::Publisher cylinder_pub;
13 //const int freq = 250; /*!< The frequency at which the subscriber reads the . */
14 bool added = false;
24 int main(int argc, char **argv){
25 
26  ros::init(argc, argv, "rviz_object");
27  ros::NodeHandle n;
28  ros::Subscriber subscriber = n.subscribe("phidget_value", 1000, rvizUpdater);
29  ros::Subscriber sd = n.subscribe("shutdown", 1, shutdown);
30  cylinder_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 1);
31  ros::spin();
32 
33 
34  return 0;
35 }
36 
47 void rvizUpdater(const std_msgs::Float32::ConstPtr& msg){
48  const double diameter = 0.06, height=0.1;;
49  float distance;
50  distance = msg->data;
51  ROS_INFO("rziv distance: %f", distance);
52 
53  visualization_msgs::Marker marker;
54  marker.header.frame_id = "base";
55  marker.header.stamp = ros::Time::now();
56  marker.ns="shape_cylinder";
57  marker.id=0;
58  marker.type = visualization_msgs::Marker::CYLINDER;
59  if(distance == 0){
60  if(added == true){
61  marker.action = visualization_msgs::Marker::DELETE;
62  added = false;
63  cylinder_pub.publish(marker);
64  }
65  }else{
66  if(added==false){
67  marker.action = visualization_msgs::Marker::ADD;
68  added = true;
69  }
70 
71  marker.pose.position.x = 0;
72  marker.pose.position.y = -distance/100;
73  marker.pose.position.z = height/2-0.02;
74 
75  marker.pose.orientation.x = 0.0;
76  marker.pose.orientation.y = 0.0;
77  marker.pose.orientation.z = 0.0;
78  marker.pose.orientation.w = 1.0;
79 
80  marker.scale.x = diameter;
81  marker.scale.y = diameter;
82  marker.scale.z = height;
83 
84  marker.color.r = 0.0f;
85  marker.color.g = 1.0f;
86  marker.color.b = 0.0f;
87  marker.color.a = 1.0;
88 
89  marker.lifetime = ros::Duration();
90 
91  cylinder_pub.publish(marker);
92  }
93 }
94 
101 void shutdown(const std_msgs::Bool::ConstPtr& b){
102  ros::shutdown();
103 }


Grijper
Author(s): Stijn van Schooten, Wybren ten Cate, Florens Kreuk, Jan Wymenga,Joris Coenen, Roy Groot
autogenerated on Thu Oct 3 2013 22:59:42