4 #include <moveit/robot_state/conversions.h>
10 #include <tesseract_ros/ros_tesseract_utils.h>
18 tesseract::tesseract_ros::KDLEnvPtr env)
20 if (env->checkInitialized())
23 env->clearAttachableObjects();
24 env->clearAttachedBodies();
27 const auto &scene_msg =
scene->getMessage();
28 for (
const auto &collision_object : scene_msg.world.collision_objects)
31 tesseract_msgs::AttachableObject obj;
32 obj.name = collision_object.id;
33 obj.operation = tesseract_msgs::AttachableObject::ADD;
35 for (
const shape_msgs::SolidPrimitive &primitive : collision_object.primitives)
37 obj.visual.primitives.emplace_back(primitive);
38 obj.collision.primitives.emplace_back(primitive);
40 cot.data = tesseract::CollisionObjectType::UseShapeType;
41 obj.collision.primitive_collision_object_types.emplace_back(cot);
44 for (
const shape_msgs::Mesh &mesh : collision_object.meshes)
46 obj.visual.meshes.emplace_back(mesh);
47 obj.collision.meshes.emplace_back(mesh);
49 cot.data = tesseract::CollisionObjectType::ConvexHull;
50 obj.collision.mesh_collision_object_types.emplace_back(cot);
53 for (
const shape_msgs::Plane &plane : collision_object.planes)
55 obj.visual.planes.emplace_back(plane);
56 obj.collision.planes.emplace_back(plane);
59 for (
const geometry_msgs::Pose &pose : collision_object.primitive_poses)
61 obj.visual.primitive_poses.emplace_back(pose);
62 obj.collision.primitive_poses.emplace_back(pose);
65 for (
const geometry_msgs::Pose &pose : collision_object.mesh_poses)
67 obj.visual.mesh_poses.emplace_back(pose);
68 obj.collision.mesh_poses.emplace_back(pose);
71 for (
const geometry_msgs::Pose &pose : collision_object.plane_poses)
73 obj.visual.plane_poses.emplace_back(pose);
74 obj.collision.plane_poses.emplace_back(pose);
78 auto ao = std::make_shared<tesseract::AttachableObject>();
79 tesseract::tesseract_ros::attachableObjectMsgToAttachableObject(ao, obj);
80 env->addAttachableObject(ao);
83 tesseract::AttachedBodyInfo attached_body_info;
84 attached_body_info.object_name = collision_object.id;
85 attached_body_info.parent_link_name = env->getRootLinkName();
86 attached_body_info.transform = Eigen::Isometry3d::Identity();
87 env->attachBody(attached_body_info);
91 if (scene_msg.world.octomap.octomap.data.size() > 0)
94 tesseract_msgs::AttachableObject obj;
96 obj.operation = tesseract_msgs::AttachableObject::ADD;
97 obj.collision.octomaps.emplace_back(scene_msg.world.octomap.octomap);
98 obj.collision.octomap_poses.emplace_back(scene_msg.world.octomap.origin);
100 cot.
data = tesseract::CollisionObjectType::UseShapeType;
101 obj.collision.octomap_collision_object_types.emplace_back(cot);
103 auto ao = std::make_shared<tesseract::AttachableObject>();
104 tesseract::tesseract_ros::attachableObjectMsgToAttachableObject(ao, obj);
105 env->addAttachableObject(ao);
107 tesseract::AttachedBodyInfo attached_body_info;
108 attached_body_info.object_name = name;
109 attached_body_info.parent_link_name = scene_msg.world.octomap.header.frame_id;
110 attached_body_info.transform = Eigen::Isometry3d::Identity();
111 env->attachBody(attached_body_info);
117 RBX_ERROR(
"Tesseract environment not initialized");
123 tesseract::tesseract_ros::KDLEnvPtr env)
125 moveit_msgs::RobotState state_msg;
128 std_msgs::Int32 cotp;
129 cotp.data = tesseract::CollisionObjectType::UseShapeType;
130 std_msgs::Int32 cotm;
131 cotm.data = tesseract::CollisionObjectType::ConvexHull;
133 for (
const auto &co : state_msg.attached_collision_objects)
136 tesseract_msgs::AttachableObject obj;
137 obj.name = co.object.id;
138 obj.operation = tesseract_msgs::AttachableObject::ADD;
141 obj.visual.primitives = co.object.primitives;
142 obj.visual.primitive_poses = co.object.primitive_poses;
143 obj.visual.meshes = co.object.meshes;
144 obj.visual.mesh_poses = co.object.mesh_poses;
145 obj.visual.planes = co.object.planes;
146 obj.visual.plane_poses = co.object.plane_poses;
149 obj.collision.primitives = co.object.primitives;
150 obj.collision.primitive_poses = co.object.primitive_poses;
151 obj.collision.primitive_collision_object_types.resize(co.object.primitives.size());
152 std::fill(obj.collision.primitive_collision_object_types.begin(),
153 obj.collision.primitive_collision_object_types.end(), cotp);
154 obj.collision.meshes = co.object.meshes;
155 obj.collision.mesh_poses = co.object.mesh_poses;
156 obj.collision.mesh_collision_object_types.resize(co.object.meshes.size());
157 std::fill(obj.collision.mesh_collision_object_types.begin(),
158 obj.collision.mesh_collision_object_types.end(), cotm);
159 obj.collision.planes = co.object.planes;
160 obj.collision.plane_poses = co.object.plane_poses;
163 auto ao = std::make_shared<tesseract::AttachableObject>();
164 tesseract::tesseract_ros::attachableObjectMsgToAttachableObject(ao, obj);
165 env->addAttachableObject(ao);
168 tesseract::AttachedBodyInfo attached_body_info;
169 attached_body_info.object_name = co.object.id;
170 attached_body_info.parent_link_name = co.link_name;
171 attached_body_info.transform = Eigen::Isometry3d::Identity();
172 env->attachBody(attached_body_info);
182 manip_joint_values.
clear();
183 manip_joint_values.
resize(0);
186 double *raw_state_values = robot_state->getVariablePositions();
189 const auto &robot_state_joint_names = robot_state->getVariableNames();
190 for (
const auto &joint_name : manip_joint_names)
193 robot_state_joint_names.begin(),
194 std::find(robot_state_joint_names.begin(), robot_state_joint_names.end(), joint_name));
195 manip_joint_values.
push_back(raw_state_values[index]);
201 const tesseract::tesseract_ros::KDLEnvPtr &env,
202 robot_state::RobotStatePtr robot_state)
205 const auto &joint_values = env->getCurrentJointValues();
206 std::vector<double> tmp_current_values(joint_values.data(), joint_values.data() + joint_values.size());
207 robot_state->setVariablePositions(env->getJointNames(), tmp_current_values);
210 const auto &joint_manip_names = env->getManipulator(manip)->getJointNames();
211 std::vector<double> tmp_group_values(manip_state.data(), manip_state.data() + manip_state.size());
212 robot_state->setVariablePositions(joint_manip_names, tmp_group_values);
216 const robot_state::RobotStatePtr &ref_state,
218 const tesseract::tesseract_ros::KDLEnvPtr &env,
219 robot_trajectory::RobotTrajectoryPtr trajectory)
221 const robot_state::RobotState © = *ref_state;
224 for (
int i = 0; i < tesseract_traj.rows(); i++)
227 auto tmp_state = std::make_shared<robot_state::RobotState>(copy);
239 const tesseract::tesseract_ros::KDLEnvPtr &env,
240 tesseract::TrajArray &trajectory)
243 trajectory.resize(robot_traj->getWayPointCount(), robot_traj->getGroup()->getVariableCount());
245 for (
unsigned int i = 0; i < robot_traj->getWayPointCount(); ++i)
253 trajectory.row(i) = Eigen::VectorXd::Map(manip_joint_values.
data(), manip_joint_values.
size());
void addSuffixWayPoint(const robot_state::RobotState &state, double dt)
A const shared pointer wrapper for robowflex::Scene.
#define RBX_ERROR(fmt,...)
Output a error logging message.
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)
void manipStateToRobotState(const Eigen::Ref< const Eigen::VectorXd > &manip_state, const std::string &manip, const tesseract::tesseract_ros::KDLEnvPtr &env, robot_state::RobotStatePtr robot_state)
Transform a tesseract waypoint (manip state) to robot state. Joint values for non-manip joints are ta...
void manipTesseractTrajToRobotTraj(const tesseract::TrajArray &tesseract_traj, const robot_state::RobotStatePtr &ref_state, const std::string &manip, const tesseract::tesseract_ros::KDLEnvPtr &env, robot_trajectory::RobotTrajectoryPtr trajectory)
Transform a tesseract trajectory to a robot trajectory.
bool sceneToTesseractEnv(const robowflex::SceneConstPtr &scene, tesseract::tesseract_ros::KDLEnvPtr env)
Add scene collision objects to a (previously initialized) KDL environment.
bool addAttachedBodiesToTesseractEnv(const robot_state::RobotStatePtr &state, tesseract::tesseract_ros::KDLEnvPtr env)
Add bodies attached to the robot scratch state to the KDL environment.
void robotTrajToManipTesseractTraj(const robot_trajectory::RobotTrajectoryPtr &robot_traj, const std::string &manip, const tesseract::tesseract_ros::KDLEnvPtr &env, tesseract::TrajArray &trajectory)
Transform a robot_trajectory to a tesseract manipulator trajectory.
void robotStateToManipState(const robot_state::RobotStatePtr &robot_state, const std::vector< std::string > &manip_joint_names, std::vector< double > &manip_joint_values)
Transform a robot_state to a vector representing joint values for the manipulator (in the order given...
Main namespace. Contains all library classes and functions.
Functions for loading and animating scenes in Blender.
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")