前言
- 依然是基础
参考
Mastering ROS for Robotics Programming.2015
学习记录
概述
- 需要安装以下包
sudo apt-get install ros-jade-gazebo-ros-pkgs ros-jade-gazeboros ros-jade-gazebo-msgs ros-jade-gazebo-plugins
- gazebo_ros_msgs: ROS包,为Gazebo提供ros方面的接口
- gazebo-msgs: 为ros提供gazebo方面的接口
- gazebo-plugins: gazebo plugins for sensors and actuators
- gazebo-ros-control: 包含标准的控制器
制作xacro文件
添加颜色和纹理
<gazebo reference="bottom_link">
<material>Gazebo/White</material>
</gazebo>
<gazebo reference="base_link">
<material>Gazebo/White</material>
</gazebo>
<gazebo reference="shoulder_pan_link">
<material>Gazebo/Red</material>
</gazebo>
添加换能信息
- 定义这种信息是为了将关节和马达(激励)联系起来,下面是定义transmission的宏
<xacro:macro name="transmission_block" params="joint_name">
<transmission name="tran1">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>PositionJointInterface</
hardwareInterface>
</joint>
<actuator name="motor1">
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
- Here, the "> is the joint in which we link the actuators. The element is the type of transmission. Currently, transmission_interface/SimpleTransmission is only supported. The element is the type of hardware interface to load (position, velocity, or effort interfaces). The hardware interface is loaded by the gazebo_ros_control plugin; we can see more about this plugin in the next section.
添加gazebo_ros_control插件
- 在xacro文件下添加这些文件
<!-- ros_control plugin -->
<gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.
so">
<robotNamespace>/seven_dof_arm</robotNamespace>
</plugin>
</gazebo>
- The default hardware interfaces are JointStateInterface, EffortJointInterface, and VelocityJointInterface.
添加一个3D传感器
- 略
制作环境启动文件
roslaunch seven_dof_arm_gazebo seven_dof_arm_world.launch
在RViz中查看图像
rosrun rviz rviz -f /rgbd_camera_optical_frame
使用ROS Controllers来移动机械臂各个关节
概述
- 对于每一个关节,我们都必须定义一个ROS Controller,这个控制器必须兼容硬件平台,这个硬件平台在xacro的中已经定义好。
- 一个控制器往往拥有一个PID控制律,这个控制律根据给定的点位置来输出一定的反馈输出给电机,来实现闭环控制。
- ros controller不会直接与硬件联系,而是与硬件接口联系(很好理解),硬件接口的作用是解释ROS控制器发送过来的数据信息,解决一些冲突问题。
- 在典型的机械臂中,需要定义好位置控制器,速度控制器,力矩控制器等等。这些控制器都在ros_control包中。
- 接下来我们学习如何配置这些控制器。
理解ros_control包
- 这一个大包实现了机器人控制器robot controllers, controller managers控制器管理器, hardware interface硬件接口,不同的换能接口transmission interface和控制工具箱control toolboxes.
- 主要包括以下包:
- control_toolbox: 包含PID控制器和sine控制器
- controller_interface: 包含控制机接口的基类
- controller_manager: 这个包能够加载,卸载,启动和停止控制器
- controller_manager_msgs: 为控制器管理器提供消息和服务的实现
- hardware_interface: 硬件接口的基类
- transmission_interface: 换能接口类,(差速,四杆机构,关节状态,位置,速度)
不同种类的ros控制器和硬件接口
- 标准的ROS控制器有:
- joint_pisition_controller: 简单的关节位置控制器
- joint_state_controller: 控制器,发送joint state消息
- joint_effort_controller: 关节力矩控制器
- 一般使用的硬件接口是:
- Joint Command Interface: 发送关节信息给硬件
- Effort Joint Interface:
- Velocity Joint Interface:
- Position Joint Interface:
- Joint State Interface: 这个接口会从激励器的编码器处获得传感信息
ROS控制器与Gazebo连接
设置joint state controllers and joint position controllers
为两个控制器写配置文件,名字为xxx_control.yaml
- 这是一个总的配置文件,规定每一个控制器分别发送和接收何种消息
cyton_gamma_1500_arm:
# Publish all joint states -----------------------------------
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 50
# Position Controllers ---------------------------------------
joint1_position_controller:
type: position_controllers/JointPositionController
joint: shoulder_roll_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint2_position_controller:
type: position_controllers/JointPositionController
joint: shoulder_pitch_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint3_position_controller:
type: position_controllers/JointPositionController
joint: shoulder_yaw_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint4_position_controller:
type: position_controllers/JointPositionController
joint: elbow_pitch_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint5_position_controller:
type: position_controllers/JointPositionController
joint: elbow_yaw_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint6_position_controller:
type: position_controllers/JointPositionController
joint: wrist_pitch_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
joint7_position_controller:
type: position_controllers/JointPositionController
joint: wrist_roll_joint
pid: {p: 100.0, i: 0.01, d: 10.0}
写启动控制器的启动文件
- xxx_gazebo_control.launch
<launch>
<!-- Launch Gazebo -->
<include file="$(find gamma_1500_gazebo)/launch/cyton_gamma_1500_world.launch" />
<!-- Load joint controller configurations from YAML file to parameter server -->
<rosparam file="$(find gamma_1500_gazebo)/config/cyton_gamma_1500_gazebo_control.yaml" command="load"/>
<!-- load the controllers -->
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" ns="/cyton_gamma_1500_arm" args="joint_state_controller
joint1_position_controller
joint2_position_controller
joint3_position_controller
joint4_position_controller
joint5_position_controller
joint6_position_controller
joint7_position_controller"/>
<!-- convert joint states to TF transforms for rviz, etc -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
respawn="false" output="screen">
<remap from="/joint_states" to="/cyton_gamma_1500_arm/joint_states" />
</node>
</launch>
移动关节
- 启动控制器,然后发送消息即可
roslaunch seven_dof_arm_gazebo seven_dof_arm_gazebo_control.launch
rostopic list
rostopic pub /seven_dof_arm/joint4_position_controller/command std_msgs/Float64 1.0
rostopic echo /seven_dof_arm/joint_states
原文地址:https://www.cnblogs.com/lizhensheng/p/11117530.html
时间: 2024-10-15 20:23:43