@@ -60,6 +60,10 @@ class VADERStateMachine
6060 vader_msgs::Pepper *coarseEstimate;
6161 vader_msgs::Pepper *fineEstimate;
6262
63+ bool allowCoarseEstimateUpdate = true , allowFineEstimateUpdate = true ;
64+
65+ ros::Time waitForFinePoseStartTime;
66+
6367 // Plan/Exec clients connecting to planner
6468 ros::ServiceClient planClient;
6569
@@ -307,6 +311,10 @@ class VADERStateMachine
307311
308312 void setCoarsePoseEstimate (const vader_msgs::PepperArray::ConstPtr &msg)
309313 {
314+ if (!allowCoarseEstimateUpdate)
315+ {
316+ return ;
317+ }
310318 coarseEstimates.clear ();
311319 // ROS_INFO_STREAM("Received " << msg->peppers.size() << " coarse pepper estimates.");
312320 for (const vader_msgs::Pepper pepper_msg : msg->peppers )
@@ -317,6 +325,7 @@ class VADERStateMachine
317325 coarseEstimates.push_back (transformed_pepper);
318326 }
319327 _prioritizeCoarseEstimatePepper (coarseEstimates);
328+
320329 // if(coarseEstimate){
321330 // _transformFromCameraFrameIntoRobotFrame(msg, fineEstimate);
322331 // _logWithState("Coarse estimate received");
@@ -339,6 +348,10 @@ class VADERStateMachine
339348
340349 void setFinePoseEstimate (const vader_msgs::PepperArray::ConstPtr &msg)
341350 {
351+ if (!allowFineEstimateUpdate)
352+ {
353+ return ;
354+ }
342355 fineEstimates.clear ();
343356 // ROS_INFO_STREAM("Received " << msg->peppers.size() << " fine pepper estimates.");
344357 for (const vader_msgs::Pepper pepper_msg : msg->peppers )
@@ -352,7 +365,7 @@ class VADERStateMachine
352365 _transformFromCameraFrameIntoRobotFrame (pepper_msg, &transformed_pepper);
353366 fineEstimates.push_back (transformed_pepper);
354367 }
355- ROS_INFO_STREAM (" Transformed fine estimates count: " << fineEstimates.size ());
368+ // ROS_INFO_STREAM("Transformed fine estimates count: " << fineEstimates.size());
356369
357370 if (!fineEstimates.empty ())
358371 {
@@ -375,6 +388,22 @@ class VADERStateMachine
375388 }
376389 }
377390
391+ void setFinePoseEstimateWithCoarsePoseEst (){
392+ fineEstimate = new vader_msgs::Pepper (*coarseEstimate);
393+ fineEstimate->header .frame_id = " world" ;
394+ fineEstimate->fruit_data .pose .orientation .x = 0 ;
395+ fineEstimate->fruit_data .pose .orientation .y = 0 ;
396+ fineEstimate->fruit_data .pose .orientation .z = 0 ;
397+ fineEstimate->fruit_data .pose .orientation .w = 1 ;
398+ fineEstimate->peduncle_data .pose .orientation .x = 0 ;
399+ fineEstimate->peduncle_data .pose .orientation .y = 0 ;
400+ fineEstimate->peduncle_data .pose .orientation .z = 0 ;
401+ fineEstimate->peduncle_data .pose .orientation .w = 1 ;
402+ fineEstimate->peduncle_data .pose .position .x = fineEstimate->fruit_data .pose .position .x ;
403+ fineEstimate->peduncle_data .pose .position .y = fineEstimate->fruit_data .pose .position .y ;
404+ fineEstimate->peduncle_data .pose .position .z = fineEstimate->fruit_data .pose .position .z + 0.05 ; // approximate peduncle position
405+ }
406+
378407 void execute ()
379408 {
380409 int num_peppers_harvested = 0 ;
@@ -392,6 +421,8 @@ class VADERStateMachine
392421 {
393422 case State::HomeGripper:{
394423 harvest_start_time = ros::Time::now ();
424+ allowCoarseEstimateUpdate = true ;
425+ allowFineEstimateUpdate = true ;
395426 _logWithState (" Homing gripper..." );
396427 _sendGripperCommand (100 );
397428 vader_msgs::PlanningRequest srv;
@@ -460,6 +491,8 @@ class VADERStateMachine
460491 else
461492 {
462493 _logWithState (" Waiting for coarse estimate" );
494+ ROS_WARN_STREAM (" NOTE: " << coarseEstimates.size () << " coarse estimates found but outside of workspace bounds." );
495+ // TODO add comment about out of range peppers
463496 // _logWithState("Using fake estimate");
464497 // geometry_msgs::Pose fake_pose;
465498 // fake_pose.position.x = 1.0;
@@ -474,6 +507,7 @@ class VADERStateMachine
474507 break ;
475508 }
476509 case State::ParallelMovePregrasp:{
510+ allowCoarseEstimateUpdate = false ;
477511 _logWithState (" Planning parallel move to pregrasp..." );
478512 vader_msgs::PlanningRequest srv;
479513 srv.request .mode = vader_msgs::PlanningRequest::Request::PARALLEL_MOVE_PREGRASP;
@@ -485,6 +519,7 @@ class VADERStateMachine
485519 {
486520 _logWithState (" Parallel move to pregrasp successful." );
487521 currentState = State::WaitForFineEstimate;
522+ waitForFinePoseStartTime = ros::Time::now ();
488523 }
489524 else
490525 {
@@ -505,11 +540,21 @@ class VADERStateMachine
505540 {
506541 _logWithState (" Fine estimate received, switching states" );
507542 // currentState = State::Done;
543+ allowFineEstimateUpdate = false ;
544+ waitForFinePoseStartTime = ros::Time (0 );
508545 currentState = State::GripperGrasp;
509546 }
510547 else
511548 {
512549 _logWithState (" Waiting for fine estimate" );
550+
551+ if (!waitForFinePoseStartTime.isZero ()){
552+ ros::Duration wait_duration = ros::Time::now () - waitForFinePoseStartTime;
553+ if (wait_duration.toSec () > 5.0 && allowFineEstimateUpdate){
554+ ROS_WARN (" Timeout waiting for fine pose estimate. Proceeding with coarse estimate." );
555+ setFinePoseEstimateWithCoarsePoseEst ();
556+ }
557+ }
513558 }
514559 break ;
515560 }
0 commit comments