setJointValueTarget

Setting a joint state target (goal)

setJointValueTarget
There are 2 types of goal targets:

  • a JointValueTarget (aka JointStateTarget) specifies an absolute value for each joint (angle for rotational joints or position for prismatic joints).
  • a PoseTarget (Position, Orientation, or Pose) specifies the pose of one or more end effectors (and the planner can use any joint values that reaches the pose(s)).

Only one or the other is used for planning.
Calling any of the setJointValueTarget() functions sets the current goal target to the JointValueTarget.
Calling any of the setPoseTarget(), setOrientationTarget(), setRPYTarget(), setPositionTarget() functions sets the current goal target to the Pose target.

setJointValueTarget

bool moveit::planning_interface::MoveGroupInterface::setJointValueTarget(const std::vector< double > & 	group_variable_values	)	

Set the JointValueTarget and use it for future planning requests.

group_variable_values MUST exactly match the variable order as returned by getJointValueTarget(std::vector<double>&).

This always sets all of the group’s joint values.

After this call, the JointValueTarget is used instead of any previously set Position, Orientation, or Pose targets.

If these values are out of bounds then false is returned BUT THE VALUES ARE STILL SET AS THE GOAL.

bool moveit::planning_interface::MoveGroupInterface::setJointValueTarget(const std::vector< std::string > & 	variable_names,
const std::vector< double > & 	variable_values 
)	

Set the JointValueTarget and use it for future planning requests.

variable_names are variable joint names and variable_values are variable joint positions. Joints in the group are used to set the JointValueTarget. Joints in the model but not in the group are ignored. An exception is thrown if a joint name is not found in the model. Joint variables in the group that are missing from variable_names remain unchanged (to reset all target variables to their current values in the robot use setJointValueTarget(getCurrentJointValues())).

After this call, the JointValueTarget is used instead of any previously set Position, Orientation, or Pose targets.

If these values are out of bounds then false is returned BUT THE VALUES ARE STILL SET AS THE GOAL.

使用

    // Create the MoveIt MoveGroup Interface
    using moveit::planning_interface::MoveGroupInterface;
    auto move_group_interface = MoveGroupInterface(node, "ur_gripper"); //change

    // Set a Joint value
    move_group_interface.setJointValueTarget(std::vector<double>({-0.02, -0.02})); //打开
    move_group_interface.setJointValueTarget(std::vector<double>({0.0, 0.0})); //关闭

    // Create a plan to that target pose
    auto const [success, plan] = [&move_group_interface]{
        moveit::planning_interface::MoveGroupInterface::Plan msg;   
        auto const ok = static_cast<bool>(move_group_interface.plan(msg));
        return std::make_pair(ok, msg);
    }();

    // Execute the plan
    if(success) {
        move_group_interface.execute(plan);
    } else {
        RCLCPP_ERROR(logger, "Planing failed!");
    }
  • 9
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ROS中生成与MATLAB对应的六自由度机械臂二次规划,需要使用ROS中的相应工具和库,下面以ROS中的MoveIt!和Eigen库为例进行说明。 1. 安装MoveIt!和Eigen库 在Ubuntu终端中,输入以下命令安装MoveIt!和Eigen库: ``` sudo apt-get install ros-<distro>-moveit sudo apt-get install libeigen3-dev ``` 其中,`<distro>`表示你所使用的ROS发行版,如`melodic`或`noetic`。 2. 创建机械臂模型 在ROS中使用MoveIt!需要先创建机械臂的模型。可以使用MoveIt!提供的可视化工具或手动编辑URDF文件来创建机械臂模型。 3. 定义机械臂运动规划器 在ROS中,机械臂运动规划器通常使用OMPL或CHOMP等库来实现。可以使用MoveIt!提供的配置工具或手动编辑配置文件来定义机械臂运动规划器。 4. 编写二次规划代码 在ROS中使用Eigen库编写二次规划代码。以下是一个简单的六自由度机械臂二次规划示例: ```c++ #include <ros/ros.h> #include <moveit/move_group_interface/move_group_interface.h> #include <Eigen/Core> #include <Eigen/Cholesky> int main(int argc, char** argv) { // 初始化ROS节点 ros::init(argc, argv, "qp_example"); ros::NodeHandle nh; // 创建MoveGroupInterface对象 moveit::planning_interface::MoveGroupInterface move_group("arm"); // 定义目标位置 geometry_msgs::PoseStamped target_pose; target_pose.header.frame_id = "base_link"; target_pose.pose.position.x = 0.5; target_pose.pose.position.y = 0.0; target_pose.pose.position.z = 0.5; target_pose.pose.orientation.x = 0.0; target_pose.pose.orientation.y = 0.0; target_pose.pose.orientation.z = 0.0; target_pose.pose.orientation.w = 1.0; // 将目标位置设置为机械臂的目标姿态 move_group.setPoseTarget(target_pose); // 进行运动规划 moveit::planning_interface::MoveGroupInterface::Plan plan; bool success = (move_group.plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS); if (success) { // 获取机械臂当前的关节角度 std::vector<double> current_joint_values; move_group.getCurrentState()->copyJointGroupPositions(move_group.getCurrentState()->getRobotModel()->getJointModelGroup(move_group.getName()), current_joint_values); // 获取机械臂的关节数 int num_joints = current_joint_values.size(); // 定义二次规划问题的系数矩阵和常数向量 Eigen::MatrixXd H(num_joints, num_joints); Eigen::VectorXd f(num_joints); // 设置二次规划问题的系数矩阵和常数向量 H << 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1; f << -current_joint_values[0], -current_joint_values[1], -current_joint_values[2], -current_joint_values[3], -current_joint_values[4], -current_joint_values[5]; // 求解二次规划问题 Eigen::VectorXd joint_values = H.ldlt().solve(f); // 将求解结果作为机械臂的目标关节角度 move_group.setJointValueTarget(joint_values); // 进行运动规划 success = (move_group.plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS); if (success) { // 执行运动 move_group.execute(plan); } } return 0; } ``` 在上述代码中,首先定义了机械臂的目标位置,然后进行运动规划,获取机械臂当前的关节角度,并定义二次规划问题的系数矩阵和常数向量。接着,使用Eigen库中的求解LDLT分解的函数求解二次规划问题,将求解结果作为机械臂的目标关节角度,进行运动规划和执行运动。 需要注意的是,上述代码仅为示例,实际情况中需要根据具体机械臂的结构和运动规划器的配置进行相应的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值