Skip to content

Commit 65c2631

Browse files
Add rviz tools to display peppers, switch to gripper channels
1 parent 17d0692 commit 65c2631

File tree

4 files changed

+84
-24
lines changed

4 files changed

+84
-24
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project(vader_hri)
1010
find_package(catkin REQUIRED COMPONENTS
1111
roscpp
1212
rospy
13+
moveit_visual_tools
1314
std_msgs
1415
vader_msgs
1516
tf2
@@ -113,6 +114,7 @@ catkin_package(
113114
# LIBRARIES vader_hri
114115
# CATKIN_DEPENDS roscpp rospy std_msgs vader_msgs
115116
# DEPENDS system_lib
117+
CATKIN_DEPENDS moveit_visual_tools
116118
)
117119

118120
###########

launch/vader_fvd_dualReal.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
<!-- end effectors -->
1717
<node pkg="vader_dynamixel" type="dynamixel_node.py" name="dynamixel" output="screen"/>
1818

19-
<include file="$(find vader_perception)/launch/gripper_cam_pose_estimation.launch"></include>
19+
<include file="$(find vader_perception)/launch/dual_cam_pose_estimation.launch"></include>
2020
</launch>

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<build_depend>tf2</build_depend>
5757
<build_depend>tf2_ros</build_depend>
5858
<build_depend>tf2_msgs</build_depend>
59+
<build_depend>moveit_visual_tools</build_depend>
60+
5961
<build_depend>tf2_sensor_msgs</build_depend>
6062
<build_depend>tf2_geometry_msgs</build_depend>
6163
<build_export_depend>roscpp</build_export_depend>
@@ -76,6 +78,7 @@
7678
<exec_depend>tf2_msgs</exec_depend>
7779
<exec_depend>tf2_sensor_msgs</exec_depend>
7880
<exec_depend>tf2_geometry_msgs</exec_depend>
81+
<exec_depend>moveit_visual_tools</exec_depend>
7982

8083
<!-- The export tag contains other, unspecified, tags -->
8184
<export>

src/FVD_Dual_HRI.cpp

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
#include <tf2_ros/buffer.h>
2323
#include <geometry_msgs/PoseStamped.h>
2424

25+
#include <moveit_visual_tools/moveit_visual_tools.h>
26+
27+
2528
static void coarseEstimateCallback(const vader_msgs::PepperArray::ConstPtr &msg);
2629
static void fineEstimateCallback(const vader_msgs::PepperArray::ConstPtr &msg);
2730

31+
namespace rvt = rviz_visual_tools;
32+
2833
class VADERStateMachine
2934
{
3035
private:
@@ -43,11 +48,11 @@ class VADERStateMachine
4348
CutterGrasp,
4449
CutterEndEffector,
4550
// -----------Finish and cleanup-----------
46-
ParallelMoveStorage,
47-
HomeGripper2,
48-
Done,
49-
Error,
50-
End
51+
ParallelMoveStorage,
52+
HomeGripper2,
53+
Done,
54+
Error,
55+
End
5156
};
5257

5358
State currentState;
@@ -63,6 +68,7 @@ class VADERStateMachine
6368
bool allowCoarseEstimateUpdate = true, allowFineEstimateUpdate = true;
6469

6570
ros::Time waitForFinePoseStartTime;
71+
moveit_visual_tools::MoveItVisualToolsPtr visual_tools = std::make_shared<moveit_visual_tools::MoveItVisualTools>("world"); //shared from planner server main instance
6672

6773
// Plan/Exec clients connecting to planner
6874
ros::ServiceClient planClient;
@@ -160,6 +166,39 @@ class VADERStateMachine
160166
}
161167
}
162168

169+
void visualizePepper(vader_msgs::Pepper pepper_estimate) {
170+
171+
//Visualize as a visual tools marker
172+
std_msgs::ColorRGBA pepper_color;
173+
// green
174+
pepper_color.r = 0.0f;
175+
pepper_color.g = 1.0f;
176+
pepper_color.b = 0.0f;
177+
pepper_color.a = 0.8f; // semi-transparent
178+
ROS_INFO_STREAM("Visualizing pepper at: x=" << pepper_estimate.fruit_data.pose.position.x
179+
<< ", y=" << pepper_estimate.fruit_data.pose.position.y
180+
<< ", z=" << pepper_estimate.fruit_data.pose.position.z
181+
<< ", quat=(" << pepper_estimate.fruit_data.pose.orientation.x << ", "
182+
<< pepper_estimate.fruit_data.pose.orientation.y << ", "
183+
<< pepper_estimate.fruit_data.pose.orientation.z << ", "
184+
<< pepper_estimate.fruit_data.pose.orientation.w << ")");
185+
visual_tools->publishCylinder(pepper_estimate.fruit_data.pose, pepper_color, pepper_estimate.fruit_data.shape.dimensions[0], pepper_estimate.fruit_data.shape.dimensions[1]*2);
186+
if(pepper_estimate.peduncle_data.pose.position.x == 0 &&
187+
pepper_estimate.peduncle_data.pose.position.y == 0 &&
188+
pepper_estimate.peduncle_data.pose.position.z == 0){
189+
visual_tools->trigger();
190+
return;
191+
}
192+
std_msgs::ColorRGBA peduncle_color;
193+
// brown
194+
peduncle_color.r = 0.6f;
195+
peduncle_color.g = 0.3f;
196+
peduncle_color.b = 0.0f;
197+
peduncle_color.a = 0.8f; // semi-transparent
198+
visual_tools->publishCylinder(pepper_estimate.peduncle_data.pose, peduncle_color, pepper_estimate.peduncle_data.shape.dimensions[0], pepper_estimate.peduncle_data.shape.dimensions[1]*2);
199+
visual_tools->trigger();
200+
}
201+
163202
void _sendGripperCommand(int open_pct)
164203
{
165204
vader_msgs::GripperCommand gripperCommand;
@@ -280,9 +319,9 @@ class VADERStateMachine
280319
VADERStateMachine() : currentState(State::HomeGripper)
281320
{
282321
coarseEstimate = nullptr;
283-
coarseEstimateSub = n.subscribe("/coarse_pepper_array", 10, coarseEstimateCallback);
322+
coarseEstimateSub = n.subscribe("/gripper_coarse_pepper_array", 10, coarseEstimateCallback);
284323
fineEstimate = nullptr;
285-
fineEstimateSub = n.subscribe("/fine_pepper_array", 10, fineEstimateCallback);
324+
fineEstimateSub = n.subscribe("/gripper_fine_pepper_array", 10, fineEstimateCallback);
286325

287326
planClient = n.serviceClient<vader_msgs::PlanningRequest>("vader_planning_service");
288327

@@ -316,13 +355,19 @@ class VADERStateMachine
316355
return;
317356
}
318357
coarseEstimates.clear();
358+
visual_tools->deleteAllMarkers();
319359
// ROS_INFO_STREAM("Received " << msg->peppers.size() << " coarse pepper estimates.");
320360
for (const vader_msgs::Pepper pepper_msg : msg->peppers)
321361
{
322362
vader_msgs::Pepper transformed_pepper;
323363
// ROS_INFO("Transforming pepper with frame_id: %s", msg->header.frame_id.c_str());
324364
_transformFromCameraFrameIntoRobotFrame(pepper_msg, &transformed_pepper);
365+
transformed_pepper.fruit_data.pose.orientation.x = 0;
366+
transformed_pepper.fruit_data.pose.orientation.y = 0;
367+
transformed_pepper.fruit_data.pose.orientation.z = 0;
368+
transformed_pepper.fruit_data.pose.orientation.w = 1;
325369
coarseEstimates.push_back(transformed_pepper);
370+
326371
}
327372
_prioritizeCoarseEstimatePepper(coarseEstimates);
328373

@@ -364,6 +409,7 @@ class VADERStateMachine
364409
vader_msgs::Pepper transformed_pepper;
365410
_transformFromCameraFrameIntoRobotFrame(pepper_msg, &transformed_pepper);
366411
fineEstimates.push_back(transformed_pepper);
412+
visualizePepper(transformed_pepper);
367413
}
368414
// ROS_INFO_STREAM("Transformed fine estimates count: " << fineEstimates.size());
369415

@@ -392,20 +438,21 @@ class VADERStateMachine
392438
}
393439
}
394440

395-
void setFinePoseEstimateWithCoarsePoseEst(){
396-
fineEstimate = new vader_msgs::Pepper(*coarseEstimate);
397-
fineEstimate->header.frame_id = "world";
398-
fineEstimate->fruit_data.pose.orientation.x = 0;
399-
fineEstimate->fruit_data.pose.orientation.y = 0;
400-
fineEstimate->fruit_data.pose.orientation.z = 0;
401-
fineEstimate->fruit_data.pose.orientation.w = 1;
402-
fineEstimate->peduncle_data.pose.orientation.x = 0;
403-
fineEstimate->peduncle_data.pose.orientation.y = 0;
404-
fineEstimate->peduncle_data.pose.orientation.z = 0;
405-
fineEstimate->peduncle_data.pose.orientation.w = 1;
406-
fineEstimate->peduncle_data.pose.position.x = fineEstimate->fruit_data.pose.position.x;
407-
fineEstimate->peduncle_data.pose.position.y = fineEstimate->fruit_data.pose.position.y;
408-
fineEstimate->peduncle_data.pose.position.z = fineEstimate->fruit_data.pose.position.z + 0.05; // approximate peduncle position
441+
vader_msgs::Pepper setFinePoseEstimateWithCoarsePoseEst(const vader_msgs::Pepper &coarseEstimate){
442+
vader_msgs::Pepper fakeFineEstimate = (coarseEstimate);
443+
fakeFineEstimate.header.frame_id = "world";
444+
fakeFineEstimate.fruit_data.pose.orientation.x = 0;
445+
fakeFineEstimate.fruit_data.pose.orientation.y = 0;
446+
fakeFineEstimate.fruit_data.pose.orientation.z = 0;
447+
fakeFineEstimate.fruit_data.pose.orientation.w = 1;
448+
fakeFineEstimate.peduncle_data.pose.orientation.x = 0;
449+
fakeFineEstimate.peduncle_data.pose.orientation.y = 0;
450+
fakeFineEstimate.peduncle_data.pose.orientation.z = 0;
451+
fakeFineEstimate.peduncle_data.pose.orientation.w = 1;
452+
fakeFineEstimate.peduncle_data.pose.position.x = fakeFineEstimate.fruit_data.pose.position.x;
453+
fakeFineEstimate.peduncle_data.pose.position.y = fakeFineEstimate.fruit_data.pose.position.y;
454+
fakeFineEstimate.peduncle_data.pose.position.z = fakeFineEstimate.fruit_data.pose.position.z + 0.05; // approximate peduncle position
455+
return fakeFineEstimate;
409456
}
410457

411458
void execute()
@@ -489,6 +536,8 @@ class VADERStateMachine
489536
std::to_string(coarseEstimate->fruit_data.pose.orientation.y) + ", " +
490537
std::to_string(coarseEstimate->fruit_data.pose.orientation.z) + ", " +
491538
std::to_string(coarseEstimate->fruit_data.pose.orientation.w) + ")");
539+
visual_tools->deleteAllMarkers();
540+
visualizePepper(*coarseEstimate);
492541
// currentState = State::Done;
493542
currentState = State::ParallelMovePregrasp;
494543
}
@@ -547,6 +596,8 @@ class VADERStateMachine
547596
allowFineEstimateUpdate = false;
548597
waitForFinePoseStartTime = ros::Time(0);
549598
currentState = State::GripperGrasp;
599+
visual_tools->deleteAllMarkers();
600+
visualizePepper(*fineEstimate);
550601
}
551602
else
552603
{
@@ -556,7 +607,11 @@ class VADERStateMachine
556607
ros::Duration wait_duration = ros::Time::now() - waitForFinePoseStartTime;
557608
if(wait_duration.toSec() > 5.0 && allowFineEstimateUpdate){
558609
ROS_WARN("Timeout waiting for fine pose estimate. Proceeding with coarse estimate.");
559-
setFinePoseEstimateWithCoarsePoseEst();
610+
vader_msgs::Pepper fakeFineEstimate = setFinePoseEstimateWithCoarsePoseEst(*coarseEstimate);
611+
fineEstimate = new vader_msgs::Pepper(fakeFineEstimate);
612+
allowFineEstimateUpdate = false;
613+
614+
// *fineEstimate = setFinePoseEstimateWithCoarsePoseEst(*coarseEstimate);
560615
}
561616
}
562617
}
@@ -607,7 +662,7 @@ class VADERStateMachine
607662
if (srv.response.success)
608663
{
609664
_logWithState("Cutter grasp successful.");
610-
currentState = State::GripperEndEffector; // First do the cutting action
665+
currentState = State::End; // First do the cutting action
611666
}
612667
else
613668
{

0 commit comments

Comments
 (0)