38 #include <pybind11/stl.h>
40 #include <moveit_msgs/msg/robot_state.hpp>
45 namespace bind_robot_state
49 if (category ==
"all")
53 else if (category ==
"links_only")
55 self->updateLinkTransforms();
57 else if (category ==
"collisions_only")
59 self->updateCollisionBodyTransforms();
63 throw std::invalid_argument(
"Invalid category");
70 auto transformation =
self->getFrameTransform(frame_id, &frame_found);
71 return transformation.matrix();
76 auto transformation =
self->getGlobalLinkTransform(link_name);
77 return transformation.matrix();
82 return tf2::toMsg(self->getGlobalLinkTransform(link_name));
87 std::map<std::string, double> joint_positions;
88 const std::vector<std::string>& variable_name =
self->getVariableNames();
89 for (
auto&
name : variable_name)
91 joint_positions[
name.c_str()] =
self->getVariablePosition(
name);
93 return joint_positions;
98 for (
const auto& item : joint_positions)
100 self->setVariablePosition(item.first, item.second);
106 std::map<std::string, double> joint_velocity;
107 const std::vector<std::string>& variable_name =
self->getVariableNames();
108 for (
auto&
name : variable_name)
110 joint_velocity[
name.c_str()] =
self->getVariableVelocity(
name);
112 return joint_velocity;
117 for (
const auto& item : joint_velocities)
119 self->setVariableVelocity(item.first, item.second);
125 std::map<std::string, double> joint_acceleration;
126 const std::vector<std::string>& variable_name =
self->getVariableNames();
127 for (
auto&
name : variable_name)
129 joint_acceleration[
name.c_str()] =
self->getVariableAcceleration(
name);
131 return joint_acceleration;
136 for (
const auto& item : joint_accelerations)
138 self->setVariableAcceleration(item.first, item.second);
144 std::map<std::string, double> joint_effort;
145 const std::vector<std::string>& variable_name =
self->getVariableNames();
146 for (
auto&
name : variable_name)
148 joint_effort[
name.c_str()] =
self->getVariableEffort(
name);
155 for (
const auto& item : joint_efforts)
157 self->setVariableEffort(item.first, item.second);
163 Eigen::VectorXd values;
164 self->copyJointGroupPositions(joint_model_group_name, values);
170 Eigen::VectorXd values;
171 self->copyJointGroupVelocities(joint_model_group_name, values);
176 const std::string& joint_model_group_name)
178 Eigen::VectorXd values;
179 self->copyJointGroupAccelerations(joint_model_group_name, values);
187 return self->getJacobian(joint_model_group, reference_point_position);
191 const std::string& link_model_name,
const Eigen::Vector3d& reference_point_position,
192 bool use_quaternion_representation)
194 Eigen::MatrixXd jacobian;
197 self->getJacobian(joint_model_group, link_model, reference_point_position, jacobian, use_quaternion_representation);
202 const std::string& state_name)
206 return self->setToDefaultValues(joint_model_group, state_name);
211 py::module robot_state = m.def_submodule(
"robot_state");
214 "robotStateToRobotStateMsg",
216 moveit_msgs::msg::RobotState state_msg;
220 py::arg(
"state"), py::arg(
"copy_attached_bodies") =
true);
222 py::class_<moveit::core::RobotState, std::shared_ptr<moveit::core::RobotState>>(robot_state,
"RobotState",
224 Representation of a robot's state. At the lowest level, a state is a collection of variables. Each variable has a name and can have position, velocity, acceleration and effort associated to it. Effort and acceleration share the memory area for efficiency reasons (one should not set both acceleration and effort in the same state and expect things to work). Often variables correspond to joint names as well (joints with one degree of freedom have one variable), but joints with multiple degrees of freedom have more variables. Operations are allowed at variable level, joint level (see JointModel) and joint group level (see JointModelGroup). For efficiency reasons a state computes forward kinematics in a lazy fashion. This can sometimes lead to problems if the update() function was not called on the state.
227 .def(py::init<const std::shared_ptr<const moveit::core::RobotModel>&>(),
229 Initializes robot state from a robot model.
232 :py:class:`moveit_py.core.RobotModel`: The robot model associated to the instantiated robot state.
241 py::return_value_policy::reference,
243 :py:class:`moveit_py.core.RobotModel`: The robot model instance associated to this robot state.
248 bool: True if the robot state is dirty.
252 py::return_value_policy::move,
254 Get the transformation matrix from the model frame (root of model) to the frame identified by frame_id. If frame_id was not found, frame_found is set to false and an identity transform is returned. This method is restricted to frames defined within the robot state and doesn't include collision object present in the collision world. Please use the PlanningScene.getFrameTransform method for collision world objects.
257 frame_id (str): The id of the frame to get the transform for.
260 :py:class:`numpy.ndarray`: The transformation matrix from the model frame to the frame identified by frame_id.
265 Get the pose of a link that is defined in the robot model.
268 link_name (str): The name of the link to get the pose for.
271 geometry_msgs.msg.Pose: A ROS geometry message containing the pose of the link.
275 py::overload_cast<const moveit::core::RobotState*, const std::string&, const Eigen::Vector3d&>(
277 py::arg(
"joint_model_group_name"), py::arg(
"reference_point_position"), py::return_value_policy::move,
279 Compute the Jacobian with reference to the last link of a specified group.
282 joint_model_group_name (str): The name of the joint model group to compute the Jacobian for.
283 reference_point_position (:py:class:`numpy.ndarray`): The position of the reference point in the link frame.
286 :py:class:`numpy.ndarray`: The Jacobian of the specified group with respect to the reference point.
289 Exception: If the group is not a chain.
295 py::arg(
"joint_model_group_name"), py::arg(
"link_name"), py::arg(
"reference_point_position"),
296 py::arg(
"use_quaternion_representation") =
false, py::return_value_policy::move,
298 Compute the Jacobian with reference to a particular point on a given link, for a specified group.
301 joint_model_group_name (str): The name of the joint model group to compute the Jacobian for.
302 link_name (str): The name of the link model to compute the Jacobian for.
303 reference_point_position (:py:class:`numpy.ndarray`): The position of the reference point in the link frame.
304 use_quaternion_representation (bool): If true, the Jacobian will be represented using a quaternion representation, if false it defaults to euler angle representation.
307 :py:class:`numpy.ndarray`: The Jacobian of the specified group with respect to the reference point.
312 nullptr, py::return_value_policy::move,
314 str: represents the state tree of the robot state.
317 .def_property_readonly_static(
320 std::stringstream ss;
324 py::return_value_policy::move,
326 str: the state information of the robot state.
342 .def(
"set_joint_group_positions",
343 py::overload_cast<const std::string&, const Eigen::VectorXd&>(
345 py::arg(
"joint_model_group_name"), py::arg(
"position_values"),
347 Sets the positions of the joints in the specified joint model group.
350 joint_model_group_name (str):
351 position_values (:py:class:`numpy.ndarray`): The positions of the joints in the joint model group.
355 .def(
"set_joint_group_active_positions",
356 py::overload_cast<const std::string&, const Eigen::VectorXd&>(
358 py::arg(
"joint_model_group_name"), py::arg(
"position_values"),
360 Sets the active positions of joints in the specified joint model group.
363 joint_model_group_name (str): The name of the joint model group to set the active positions for.
364 position_values (:py:class:`numpy.ndarray`): The positions of the joints in the joint model group.
368 py::arg(
"joint_model_group_name"),
370 For a given group, get the position values of the variables that make up the group.
373 joint_model_group_name (str): The name of the joint model group to copy the positions for.
376 :py:class:`numpy.ndarray`: The positions of the joints in the joint model group.
379 .def("set_joint_group_velocities",
380 py::overload_cast<const std::string&, const Eigen::VectorXd&>(
382 py::arg(
"joint_model_group_name"), py::arg(
"velocity_values"),
384 Sets the velocities of the joints in the specified joint model group.
387 joint_model_group_name (str): The name of the joint model group to set the velocities for.
388 velocity_values (:py:class:`numpy.ndarray`): The velocities of the joints in the joint model group.
392 py::arg(
"joint_model_group_name"),
394 For a given group, get the velocity values of the variables that make up the group.
397 joint_model_group_name (str): The name of the joint model group to copy the velocities for.
399 :py:class:`numpy.ndarray`: The velocities of the joints in the joint model group.
402 .def("set_joint_group_accelerations",
403 py::overload_cast<const std::string&, const Eigen::VectorXd&>(
405 py::arg(
"joint_model_group_name"), py::arg(
"acceleration_values"),
407 Sets the accelerations of the joints in the specified joint model group.
410 joint_model_group_name (str): The name of the joint model group to set the accelerations for.
411 acceleration_values (:py:class:`numpy.ndarray`): The accelerations of the joints in the joint model group.
415 py::arg(
"joint_model_group_name"),
417 For a given group, get the acceleration values of the variables that make up the group.
420 joint_model_group_name (str): The name of the joint model group to copy the accelerations for.
423 :py:class:`numpy.ndarray`: The accelerations of the joints in the joint model group.
429 Returns the transform of the specified link in the global frame.
432 link_name (str): The name of the link to get the transform for.
435 :py:class:`numpy.ndarray`: The transform of the specified link in the global frame.
442 const std::string& tip,
443 double timeout) {
return self->setFromIK(self->getJointModelGroup(group), pose, tip, timeout); },
444 py::arg(
"joint_model_group_name"), py::arg(
"geometry_pose"), py::arg(
"tip_name"), py::arg(
"timeout") = 0.0,
446 Sets the state of the robot to the one that results from solving the inverse kinematics for the specified group.
449 joint_model_group_name (str): The name of the joint model group to set the state for.
450 geometry_pose (geometry_msgs.msg.Pose): The pose of the end-effector to solve the inverse kinematics for.
451 tip_name (str): The name of the link that is the tip of the end-effector.
452 timeout (float): The amount of time to wait for the IK solution to be found.
458 Set all joints to their default positions.
459 The default position is 0, or if that is not within bounds then half way between min and max bound.
462 .def("set_to_default_values",
463 py::overload_cast<const moveit::core::JointModelGroup*, const std::string&>(
465 py::arg(
"joint_model_group"), py::arg(
"name"),
467 Set the joints in group to the position name defined in the SRDF.
470 joint_model_group (:py:class:`moveit_py.core.JointModelGroup`): The joint model group to set the default values for.
471 name (str): The name of a predefined state which is defined in the robot model SRDF.
474 .def("set_to_default_values",
475 py::overload_cast<moveit::core::RobotState*, const std::string&, const std::string&>(
477 py::arg(
"joint_model_group_name"), py::arg(
"name"),
479 Set the joints in group to the position name defined in the SRDF.
482 joint_model_group_name (str): The name of the joint model group to set the default values for.
483 name (str): The name of a predefined state which is defined in the robot model SRDF.
488 Set all joints to random positions within the default bounds.
491 .def("set_to_random_positions",
493 py::arg(
"joint_model_group"),
495 Set all joints in the joint model group to random positions within the default bounds.
498 joint_model_group (:py:class:`moveit_py.core.JointModelGroup`): The joint model group to set the random values for.
503 Clear all attached bodies. We only allow for attaching of objects via the PlanningScene instance. This method allows any attached objects that are associated to this RobotState instance to be removed.
508 Update state transforms.
511 force (bool): when true forces the update of the transforms from scratch.
512 category (str): specifies the category to update. All indicates updating all transforms while "links_only" and "collisions_only" ensure that only links or collision transforms are updated. )");
A link from the robot. Contains the constant transform applied to the link and its geometry.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setJointGroupAccelerations(const std::string &joint_group_name, const double *gstate)
Given accelerations for the variables that make up a group, in the order found in the group (includin...
void setJointGroupVelocities(const std::string &joint_group_name, const double *gstate)
Given velocities for the variables that make up a group, in the order found in the group (including v...
void setJointGroupPositions(const std::string &joint_group_name, const double *gstate)
Given positions for the variables that make up a group, in the order found in the group (including va...
const RobotModelConstPtr & getRobotModel() const
Get the robot model this state is constructed for.
bool dirty() const
Returns true if anything in this state is dirty.
std::string getStateTreeString() const
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
void setJointGroupActivePositions(const JointModelGroup *group, const std::vector< double > &gstate)
Given positions for the variables of active joints that make up a group, in the order found in the gr...
void printStateInfo(std::ostream &out=std::cout) const
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
void clearAttachedBodies()
Clear all attached bodies. This calls delete on the AttachedBody instances, if needed.
Vec3fX< details::Vec3Data< double > > Vector3d
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
std::map< std::string, double > getJointAccelerations(const moveit::core::RobotState *self)
void setJointAccelerations(moveit::core::RobotState *self, std::map< std::string, double > &joint_accelerations)
std::map< std::string, double > getJointEfforts(const moveit::core::RobotState *self)
Eigen::VectorXd copyJointGroupVelocities(const moveit::core::RobotState *self, const std::string &joint_model_group_name)
Eigen::MatrixXd getJacobian(const moveit::core::RobotState *self, const std::string &joint_model_group_name, const Eigen::Vector3d &reference_point_position)
std::map< std::string, double > getJointVelocities(const moveit::core::RobotState *self)
std::map< std::string, double > getJointPositions(const moveit::core::RobotState *self)
void setJointEfforts(moveit::core::RobotState *self, std::map< std::string, double > &joint_efforts)
bool setToDefaultValues(moveit::core::RobotState *self, const std::string &joint_model_group_name, const std::string &state_name)
void initRobotState(py::module &m)
Eigen::MatrixXd getGlobalLinkTransform(const moveit::core::RobotState *self, std::string &link_name)
Eigen::VectorXd copyJointGroupAccelerations(const moveit::core::RobotState *self, const std::string &joint_model_group_name)
void update(moveit::core::RobotState *self, bool force, std::string &category)
void setJointVelocities(moveit::core::RobotState *self, std::map< std::string, double > &joint_velocities)
Eigen::VectorXd copyJointGroupPositions(const moveit::core::RobotState *self, const std::string &joint_model_group_name)
geometry_msgs::msg::Pose getPose(const moveit::core::RobotState *self, const std::string &link_name)
void setJointPositions(moveit::core::RobotState *self, std::map< std::string, double > &joint_positions)
Eigen::MatrixXd getFrameTransform(const moveit::core::RobotState *self, std::string &frame_id)