-
Notifications
You must be signed in to change notification settings - Fork 4
ROS Tips(tamago)
tamagotchi edited this page Mar 4, 2021
·
1 revision
cd ~/catkin_ws/src
catkin_create_pkg rospackage_test roscpp rospy std_msgs tf
cd ~/catkin_ws
catkin_make
add_executable(basic_simple_talker src/basic_simple_talker.cpp)
target_link_libraries(basic_simple_talker
${catkin_LIBRARIES}
)
//opencvのとき
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
rospy
std_msgs
tf
)
#!/usr/bin/env python
# coding: utf-8
roscd py_lecture/scripts/
chmod +x python_talker.py
###USB
sudo chmod 777 /dev/ttyACM0
add_definitions(-std=c++11)
cd catkin_ws/rosbag/
rosbag record -a 全てのトピックを記録
rosbag record /topic1 /topic2 特定のトピックを記録
rosbag record -O file.bag
※画像は重たい!
rosbag play magImageXmark.bag -l --topics /sensorValue /magImage/state_vel -l:リピート --topics:トピック指定
<launch>
//自由につけれるノード名、パッケージ、元ノード名
<node name="basic_simple_talker" pkg="basic_lecture" type="basic_simple_talker" >
//元トピック名、変更後トピック名
<remap from="chatter" to="content"/>
</node>
//launchでの変数名、値(bool,double,string)
<arg name="mode" default="true"/>
//if(){}的な
//roslaunch basic_lecture launch_arg1.launch mode:=false とすると起動しなくなる
//<group unless="$(arg mode)"> 反対動作
<group if="$(arg mode)">
<node name="basic_simple_talker" pkg="basic_lecture" type="basic_simple_talker" />
<node name="basic_simple_listener" pkg="basic_lecture" type="basic_simple_listener" output="screen" />
</group>
<arg name="mode" default="mode0"/>
//eval:複雑な条件分岐
<group if="$(eval mode=='mode0' or mode=='mode1')">
<node name="basic_simple_talker" pkg="basic_lecture" type="basic_simple_talker" />
<node name="basic_simple_listener" pkg="basic_lecture" type="basic_simple_listener" output="screen" />
</group>
<node name="basic_param_talker" pkg="basic_lecture" type="basic_param_talker" >
//ソースfileでの変数、値
//ros::NodeHandle pnh("~");
std::string msg_chatter = "hello world!";
pnh.getParam("content", msg_chatter);
<param name="content" value="alternative hello"/>
</node>
//$(find〜)でフォルダの場所特定
<arg name="rvizconfig" default="$(find vis_lecture)/rviz/joint_display.rviz" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />
//コメント
<!-- -->
//xml のお約束
<?xml version="1.0"?>
<robot name="dtw_robot" xmlns:xacro="http://ros.org/wiki/xacro">
<material name="gray"> //色指定
<color rgba="0.5 0.5 0.5 2.5"/> //赤、緑、青、透明度
</material>
<material name="red">
<color rgba="1.0 0.0 0.0 2.5"/>
</material>
//xacroの記述
//parent,prefix,xyz=変数
<xacro:macro name="wheel_macro" params="parent prefix xyz">
//linkとlinkの結合記述
//type : fixed,continuous,revolute,floating
<joint name="${prefix}_joint" type="continuous">
//初期位置、角度
<origin xyz="${xyz}" rpy="${radians(-90)} 0 0"/>
<parent link="${parent}"/>
<child link="${prefix}_link"/>
<axis xyz="0 0 1" />
</joint>
//link=表示されるところの詳しい記述
<link name="${prefix}_link">
//表示部の記述
<visual>
//形の記述
<geometry>
//<box size="0.3 0.3 0.2"/>
//<sphere radius="0.2"/>
//<mesh filename="package://vis_lecture/stl/stl_part.stl" />
<cylinder radius="0.05" length="0.02" />
</geometry>
<material name="red"/>
</visual>
</link>
</xacro:macro>
//ロボットの基準
<link name="base_link"/>
<joint name="body_joint" type="fixed">
<parent link="base_link"/>
<child link="body_link"/>
<origin xyz="-0.07 0 0.07" rpy="0 0 0"/>
</joint>
<link name="body_link">
<visual>
<origin xyz="0 0 0" rpy="0 0 0" />
<geometry>
<box size="0.24 0.18 0.06" />
</geometry>
<material name="gray" />
</visual>
</link>
<xacro:wheel_macro prefix="left_wheel" parent="base_link" xyz="0 0.1 0.05"/>
<xacro:wheel_macro prefix="right_wheel" parent="base_link" xyz="0 -0.1 0.05"/>
<joint name="ball_joint" type="fixed">
<parent link="base_link"/>
<child link="ball_link"/>
<origin xyz="-0.14 0 0.04" rpy="0 0 0"/>
</joint>
<link name="ball_link">
<visual>
<origin xyz="0 0 0" rpy="0 0 0" />
<geometry>
<sphere radius="0.04" />
</geometry>
<material name="gray" />
</visual>
</link>
</robot>
//xacroでの定数
<xacro:property name="side" value="0.5" />
<box size="${side} ${side} ${side}" />
//xacroでのif文
<material name="red">
<color rgba="1.0 0.0 0.0 2.0"/>
</material>
<xacro:if value="${color=='red'}">
<material name="red"/>
</xacro:if>
//xacroでのinclude
<xacro:include filename="$(find vis_lecture)/xacro/basic5_h.xacro" />
//xacroでのlaunchパラメーター
<xacro:arg name="length" default="1.0"/>
<param name="robot_description" command="$(find xacro)/xacro $(arg model) length:=$(arg length0) --inorder" />
//xacroのエラーチェック
roscd info_lecture/xacro/
rosrun xacro xacro cart.xacro --inorder >cart.urdf
check_urdf cart.urdf
roslaunch urdf_tutorial display.launch model:=cart.urdf
//xacro出すときのlaunchファイル
<launch>
<arg name="model" />
<arg name="gui" default="true" />
<arg name="rvizconfig" default="$(find urdf_tutorial)/rviz/urdf.rviz" />
<param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
<param name="use_gui" value="$(arg gui)"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />
</launch>
<?xml version="1.0"?>
<robot name="dtw_robot" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:macro name="wheel_macro" params="parent prefix xyz">
//軸を動かす設定
<transmission name="${prefix}_trans" type="SimpleTransmission">
<type>transmission_interface/SimpleTransmission</type>
<actuator name="${prefix}_motor">
<mechanicalReduction>1</mechanicalReduction>
</actuator>
<joint name="${prefix}_joint">
//指令タイプ(EffortJointInterface 力指令、PositionJointInterface 位置指令) <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
</transmission>
<link name="${prefix}_link">
//重さに関するパラメータ
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.1"/>
//慣性モーメント
<inertia ixx="0.0001" ixy="0.0" ixz="0.0" iyy="0.0001" iyz="0.0" izz="0.0001"/>
</inertial>
<visual>
<geometry>
<cylinder radius="0.05" length="0.02" />
</geometry>
<material name="red"/>
</visual>
//衝突判定
<collision>
<geometry>
<cylinder radius="0.05" length="0.02" />
</geometry>
</collision>
</link>
//GAZEBO用情報
<gazebo reference="${prefix}_link">
<material>Gazebo/Red</material>
</gazebo>
</xacro:macro>
<gazebo reference="ball_link">
<material>Gazebo/Gray</material>
//摩擦係数
<mu1 value="0.5" />
<mu2 value="0.5" />
</gazebo>
<joint name="left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="left_wheel_link"/>
<origin xyz="0 0.1 0.05" rpy="-1.5708 0 0"/>
<axis xyz="0 0 1" />
<limit velocity="12.0" effort="0.4" /> //制限
<dynamics damping="0.1"/> //粘性係数
</joint>
//rosコントロールのおまじない
<gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<robotNamespace>/dtw_robot</robotNamespace>
<robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
<legacyModeNS>true</legacyModeNS>
</plugin>
</gazebo>