ROS와 연동

박정훈·2024년 1월 18일
0

Simulation

목록 보기
2/2
post-thumbnail

Gazebo의 ROS 노드

Gazebo 관련 ROS Topic

  • 빈 월드에 Box를 삽입하고, 터미널에서 /gazebo/model_states 토픽 확인
$ roslaunch robot_description empty_world.launch
$ rqt_graph

$ rostopic echo /gazebo/model_states

  • /gazebo/set_model_state 퍼블리싱
$ rostopic pub /gazebo/set_model_state gazebo_msgs/ModelState "model_name: unit_box

Gazebo 관련 ROS Service

$ rosservice call /gazebo/...
  • /gezebo/pause_physics: 물리 업데이트를 일시 중지

  • /gazebo/unpause_physics: 물리 업데이트를 재개

  • /gazebo/reset_simulator: 시간을 포함한 전체 시뮬레이션을 재설정

  • /gazebo/reset_world: 모델의 포즈를 재설정

Gazebo Tag

NameType설명
materialvalue시각적 요소의 재질
gravitybool중력 사용 여부
dampingFactordouble링크 속도의 지수적 감쇠 - 주어진 값과 이전 링크 속도를 (1-dampingFactor)로 곱합니다.
maxVeldouble최대 접촉 보정 속도 절단 항목
minDepthdouble접촉 보정 임펄스가 적용되기 전에 허용되는 최소 깊이
mu1doubleOpen Dynamics Engine (ODE)에 의해 정의된 주요 접촉 방향에 대한 마찰 계수 μ
mu2
fdir1string충돌 로컬 참조 프레임에서 mu1의 방향을 지정하는 3-튜플
kpdoubleODE에 정의된 강체 접촉의 접촉 강도 k_p 및 감쇠 k_d
kd
selfCollidebool참이면 모델 내의 다른 링크와 충돌할 수 있음
maxContactsint두 엔터티 간에 허용되는 최대 접촉 수. 이 값은 물리에서 정의된 max_contacts 요소를 무시함
laserRetrodouble레이저 센서에 의해 반환된 강도 값

Pre-defined materials

https://wiki.ros.org/simulator_gazebo/Tutorials/ListOfMaterials

$ gedit /usr/share/gazebo-9/media/materials/scripts/gazebo.material

    <gazebo reference="link_chassis">
        <material>Gazebo/Blue</material>
    </gazebo>
    <gazebo reference="link_caster_wheel">
        <material>Gazebo/Grey</material>
    </gazebo>
    <gazebo reference="link_left_wheel">
        <material>Gazebo/Black</material>
    </gazebo>
    <gazebo reference="link_right_wheel">
        <material>Gazebo/Black</material>
</gazebo>

Friction

   <gazebo reference="joint_chassis_caster_wheel">
        <preserveFixedJoint>true</preserveFixedJoint>
    </gazebo>
  • SDF 변환에서 link_chassis 와 link_caster_wheel이 분리된 상태로 유지
  • Gazebo에서는 고정 조인트로 묶인 링크로 병합하여 chassis 마찰을 설정하지 않고 caster_wheel의 마찰을 줄일 수 있다.
    <gazebo reference="link_chassis">
        <material>Gazebo/Blue</material>
    </gazebo>
    <gazebo reference="link_caster_wheel">
        <material>Gazebo/Grey</material>
        <mu1>0</mu1>
        <mu2>0</mu2>
    </gazebo>
    <gazebo reference="link_left_wheel">
        <material>Gazebo/Black</material>
        <mu1>1</mu1>
        <mu2>1</mu2>
    </gazebo>
    <gazebo reference="link_right_wheel">
        <material>Gazebo/Black</material>
        <mu1>1</mu1>
        <mu2>1</mu2>
    </gazebo>
  • link_caster_wheel, link_left_wheel, link_right_wheel 마찰 설정

Ros Plugin - Robot Differential Driver

https://classic.gazebosim.org/tutorials?tut=ros_gzplugins

    <!-- Robot Differential Driver -->
    <gazebo>
        <plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">
            <alwaysOn>true</alwaysOn>
            <updateRate>20</updateRate>
            <leftJoint>joint_chassis_left_wheel</leftJoint>
            <rightJoint>joint_chassis_right_wheel</rightJoint>
            <wheelSeparation>1.66</wheelSeparation>
            <wheelDiameter>0.8</wheelDiameter>
            <torque>10</torque>
            <commandTopic>cmd_vel</commandTopic>
            <odometryTopic>odom</odometryTopic>
            <odometryFrame>odom</odometryFrame>
            <robotBaseFrame>link_chassis</robotBaseFrame>
        </plugin>
    </gazebo>

move_simple.py

#!/usr/bin/env python3

import rospy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry

def odom_callback(msg):
    rospy.loginfo('X: %s / Y: %s' % (round(msg.pose.pose.position.x, 2), round(msg.pose.pose.position.y,2)))

def main():
    odom_sub = rospy.Subscriber('odom', Odometry, odom_callback)
    twist_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)

    rospy.init_node('move_simple_node', anonymous=True)
    rate = rospy.Rate(10) # 10hz

    while not rospy.is_shutdown():
        vel_msg = Twist()
        vel_msg.linear.x = 0.3
        vel_msg.angular.z = 0.3

        twist_pub.publish(vel_msg)
        rate.sleep()

if __name__=='__main__':
    try:
        main()
    except rospy.ROSInterruptException:
        pass

Ros Plugin - Robot Laser Sensor

move_with_laser.py

#!/usr/bin/env python3

import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

def laser_callback(msg):
    rospy.loginfo('Minimum distance is: %s' % min(msg.ranges))

def main():
    laser_sub = rospy.Subscriber('laser/scan', LaserScan, callback=laser_callback)
    twist_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)

    rospy.init_node('move_with_laser_node', anonymous=True)
    rate = rospy.Rate(10) # 10hz

    while not rospy.is_shutdown():
        twist_msg = Twist()
        twist_msg.linear.x = 0.3
        twist_msg.angular.z = 0.3
        twist_pub.publish(twist_msg)
        rate.sleep()

if __name__=='__main__':
    try:
        main()
    except rospy.ROSInterruptException:
        pass

XACRO

http://www.ros.org/wiki/xacro

로봇 모델링과 설명을 쉽게 관리하기 위한 XML 기반의 마크업 언어입니다.
xacro는 주로 로봇 모델링에 사용되며, URDF와 통합하여 로봇을 효과적으로 설명하고 관리할 수 있도록 도와줍니다.

  • 매크로 지원: xacro는 매크로 기능을 제공하여 반복적이고 재사용 가능한 코드 블록을 정의할 수 있습니다. 이는 로봇 모델을 단순화하고 가독성을 높이는 데 도움이 됩니다.
  • 파라미터화: xacro 파일은 파라미터를 사용하여 로봇의 여러 부분을 조절할 수 있습니다. 이를 통해 다양한 설정에 대응하는 유연한 모델을 만들 수 있습니다.
  • Include 기능: 다른 xacro 파일이나 URDF 파일을 include하여 로봇 모델을 구성하는 데 사용할 수 있습니다. 이를 통해 모델을 모듈화하고 재사용성을 높일 수 있습니다.

robot.xacro

<robot name="robot" xmlns:xacro="http://www.ros.org/wiki/xacro">

    <xacro:include filename="$(find robot_description)/urdf/robot.gazebo" />

    <!-- Parameters -->
    <xacro:property name="chassis_mass" value="10" />
    <xacro:property name="pi" value="3.1415926535897931"/>

    <!-- Link - chassis -->
    <link name="link_chassis">
        <inertial>
            <mass value="${chassis_mass}" />
            			...

ROS Plugin - Joint Control

https://wiki.ros.org/ros_control
https://classic.gazebosim.org/tutorials?tut=ros_control

profile
.______.

0개의 댓글