99#include " vader_msgs/GripperCommand.h"
1010#include " vader_msgs/CutterCommand.h"
1111
12+ #include " vader_msgs/HarvestResult.h"
13+
1214#include " vader_msgs/PlanningRequest.h"
1315
1416#include < ros/ros.h>
@@ -58,6 +60,8 @@ class VADERStateMachine
5860 // End effector talking to dynamixel node
5961 ros::Publisher gripperCommandPub, cutterCommandPub;
6062
63+ ros::Publisher resultStatusPub; // publishes to /harvest_result
64+
6165 /*
6266 Input: cameraFrameMsg containing the pose of the fruit in the camera frame from the coarse/fine pepper estimate
6367 Output: result containing the pose of the fruit in the world frame using TF2.
@@ -96,10 +100,10 @@ class VADERStateMachine
96100 peduncle_pose,
97101 " world" ,
98102 ros::Duration (3.0 ));
99- ROS_INFO (" Transformed pose: x=%f, y=%f, z=%f" ,
100- transformed_pose.pose .position .x ,
101- transformed_pose.pose .position .y ,
102- transformed_pose.pose .position .z );
103+ // ROS_INFO("Transformed pose: x=%f, y=%f, z=%f",
104+ // transformed_pose.pose.position.x,
105+ // transformed_pose.pose.position.y,
106+ // transformed_pose.pose.position.z);
103107 result->fruit_data .pose .position .x = transformed_pose.pose .position .x ;
104108 result->fruit_data .pose .position .y = transformed_pose.pose .position .y ;
105109 result->fruit_data .pose .position .z = transformed_pose.pose .position .z ;
@@ -149,6 +153,17 @@ class VADERStateMachine
149153 ROS_INFO_STREAM (" [" << currentState << " ]: " << message);
150154 }
151155
156+ void _publishResultStatus (int result_code, const std::string &reason)
157+ {
158+ vader_msgs::HarvestResult resultMsg;
159+ resultMsg.result = result_code;
160+ resultMsg.reason = reason;
161+ resultStatusPub.publish (resultMsg);
162+ ros::Duration (1.0 ).sleep ();
163+ resultStatusPub.publish (resultMsg);
164+ ROS_WARN_STREAM (" Published harvest result: " << result_code << " , reason: " << reason);
165+ }
166+
152167public:
153168 VADERStateMachine () : currentState(State::HomeGripper)
154169 {
@@ -161,6 +176,8 @@ class VADERStateMachine
161176
162177 gripperCommandPub = n.advertise <vader_msgs::GripperCommand>(" /gripper_command" , 10 );
163178 cutterCommandPub = n.advertise <vader_msgs::CutterCommand>(" /cutter_command" , 10 );
179+
180+ resultStatusPub = n.advertise <vader_msgs::HarvestResult>(" /harvest_status" , 10 );
164181 }
165182
166183 void setCoarsePoseEstimate (const vader_msgs::Pepper::ConstPtr &msg)
@@ -209,6 +226,7 @@ class VADERStateMachine
209226 }
210227 else
211228 {
229+ _publishResultStatus (srv.response .success , " Failed to home gripper." );
212230 _logWithState (" Failed to call planning service for gripper homing." );
213231 currentState = State::Error;
214232 }
@@ -234,6 +252,7 @@ class VADERStateMachine
234252 }
235253 else
236254 {
255+ _publishResultStatus (srv.response .success , " Failed to home cutter." );
237256 _logWithState (" Failed to call planning service for cutter homing." );
238257 currentState = State::Error;
239258 }
@@ -272,6 +291,7 @@ class VADERStateMachine
272291 }
273292 else
274293 {
294+ _publishResultStatus (srv.response .success , " Failed to move to pregrasp." );
275295 _logWithState (" Failed to call planning service for parallel move to pregrasp." );
276296 currentState = State::Error;
277297 }
@@ -310,6 +330,7 @@ class VADERStateMachine
310330 }
311331 else
312332 {
333+ _publishResultStatus (srv.response .success , " Failed to gripper grasp." );
313334 _logWithState (" Failed to call planning service for gripper grasp." );
314335 currentState = State::Error;
315336 }
@@ -346,6 +367,7 @@ class VADERStateMachine
346367 }
347368 else
348369 {
370+ _publishResultStatus (srv.response .success , " Failed to cutter grasp." );
349371 _logWithState (" Failed to call planning service for cutter grasp." );
350372 currentState = State::Error;
351373 }
@@ -387,6 +409,7 @@ class VADERStateMachine
387409 }
388410 else
389411 {
412+ _publishResultStatus (srv.response .success , " Failed to move to storage." );
390413 _logWithState (" Failed to call planning service for parallel move to storage." );
391414 currentState = State::Error;
392415 }
@@ -395,6 +418,7 @@ class VADERStateMachine
395418 case State::Done:
396419 {
397420 // ROS_INFO("Done");
421+ _publishResultStatus (vader_msgs::HarvestResult::RESULT_SUCCESS, " Success." );
398422 _logWithState (" Done" );
399423 break ;
400424 }
0 commit comments