Skip to content

Star-Cheng/src

Repository files navigation

ROS

清华源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
-i https://pypi.tuna.tsinghua.edu.cn/simple

Gazebo

# 停止 gazebo
ps -ef | grep gazebo | grep -v grep | awk '{print $2}' | xargs -r kill -9

启动Cat_kin

# 新版本
mkdir catkin_ws
cd catkin_ws
git clone https://github.com/star-cheng/src.git
cd src
bash setup_noetic.sh
# 旧版本
mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
git clone https://github.com/6-robot/wpr_simulation.git
cd wpr_simulation/scripts
./install_for_noetic.sh
cd ~/catkin_ws
catkin_make
vim ~/.bashrc
source ~/catkin_ws/devel/setup.bash
cd ~/catkin_ws/src
git clone https://github.com/6-robot/wpb_home.git
cd wpb_home/wpb_home_bringup/scripts
./install_for_noetic.sh
source ~/catkin_ws/devel/setup.bash
cd ~/catkin_ws
catkin_make
code
# Add Folder to Workspace
# Add src

Project

mujoco

git clone https://github.com/google-deepmind/mujoco_menagerie.git
wget https://github.com/google-deepmind/mujoco/releases/download/3.3.0/mujoco-3.3.0-linux-x86_64.tar.gz
export PATH=$PATH:/root/gym/code/rl/mujoco/mujoco-3.3.0/bin
# 将 urdf 文件转换成 MJCF 格式的 xml 文件
pip install urdf2mjcf
pip install stl
pip install numpy-stl
sudo apt-get install -y blender
pip install bpy # or blender --python blender_trans.py
urdf2mjcf --output single_arm_left.xml single_arm_left.urdf

msckf_vio

# https://ltslam-doc.readthedocs.io/en/latest/msckf/msckf.html
cd ~/catkin_ws/src
git clone https://github.com/KumarRobotics/msckf_vio.git
cd ..
sudo apt-get install libsuitesparse-dev -y
sudo apt-get install ros-noetic-random-numbers -y
echo $CMAKE_PREFIX_PATH
source /opt/ros/noetic/setup.bash
source ~/catkin_ws/devel/setup.bash
catkin_make --pkg msckf_vio --cmake-args -DCMAKE_BUILD_TYPE=Release
# http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/vicon_room1/V1_01_easy/V1_01_easy.bag
# EuRoC
roslaunch msckf_vio msckf_vio_euroc.launch
# rosbag
rosbag play ~/code/catkin_ws/data/V1_01_easy.bag
# RVIZ load msckf_vio/rviz/rviz_euroc_config.rviz
rivz # or roslaunch msckf_vio demo.launch
  • cd :~/code/catkin_ws/src/wpr_simulation/scripts
  • ./install_for_noetic.sh
  • catkin_make
  • source /home/gym/code/catkin_ws/devel/setup.bash
  • roslaunch wpr_simulation wpb_simple.launch
  • sudo apt install ros-noetic-teb-local-planner
  • cd /home/gym/code/catkin_ws/src/wpb_home/wpb_home_bringup/scripts
  • ./install_for_noetic.sh

moveit

# https://blog.csdn.net/weixin_44415639/article/details/131906519
rosdep update
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install -y python3-wstool python3-catkin-tools clang-format-13
mkdir ~/ws_moveit
cd ~/ws_moveit 
sudo apt install python3-wstool
wstool init src
wstool merge -t src https://raw.githubusercontent.com/ros-planning/moveit/master/moveit.rosinstall
wstool update -t src
rosdep install -y --from-paths src --ignore-src --rosdistro ${ROS_DISTRO}
catkin config --extend /opt/ros/${ROS_DISTRO} --cmake-args -DCMAKE_BUILD_TYPE=Release 
catkin build
sudo apt-get install ros-noetic-moveit -y
roslaunch panda_moveit_config demo.launch
rosdep install --from-paths /opt/ros/noetic/share --ignore-src -y
sudo apt-get install ros-noetic-moveit-resources
source /opt/ros/noetic/setup.bash
roslaunch moveit_setup_assistant setup_assistant.launch
# 启动panda_arm
rosrun moveit_ros_move_group move_group
roslaunch panda_moveit_config demo.launch

tracikpy

# tracikpy
sudo apt-get install swig -y
sudo apt-get install libeigen3-dev liborocos-kdl-dev libkdl-parser-dev liburdfdom-dev libnlopt-dev -y
git clone https://github.com/Star-Cheng/tracikpy.git
pip install tracikpy/
rm -rf control/tracikpy/
mv tracikpy control/

moveit dual arm

# https://blog.csdn.net/qq_45762996/article/details/136472543
mkdir -p ~/dual_arm_ws/src
cd ~/dual_arm_ws/src
git clone https://github.com/bi3ri/dual_arm_demo.git
git submodule update --init --recursive
catkin build 
echo "source $(pwd)/devel/setup.bash" >> ~/.bashrc

Fast_LIO

# 参考连接
# https://zhuanlan.zhihu.com/p/461246350
# https://zhuanlan.zhihu.com/p/471876061
git clone https://github.com/hku-mars/FAST_LIO.git
git clone https://github.com/Livox-SDK/livox_ros_driver.git
cd FAST_LIO/include
git clone https://github.com/hku-mars/ikd-Tree.git
# 启动运行fast_lio的demo
roslaunch fast_lio mapping_velodyne.launch
rosbag play /root/gym/data/slam/Velodyne_bagfiles/demo01_velodyne.bag

Octmap

# https://robot.czxy.com/car/orbslam/octomap/
sudo apt update
sudo apt upgrade
sudo apt-get install ros-$ROS_DISTRO-octomap-ros -y
sudo apt-get install ros-$ROS_DISTRO-octomap-msgs -y
sudo apt-get install ros-$ROS_DISTRO-octomap-server -y
sudo apt-get install ros-$ROS_DISTRO-octomap-rviz-plugins -y
cd .. && git clone https://gitee.com/tangyang/pointcloud_publisher.git
catkin_make
# roslaunch pointcloud_publisher demo.launch

xv_skd

cd scripts && sh install_xvsdk.sh
cp -r /usr/share/ros-wrapper/xv_sdk ~/code/catkin_ws/src/
catkin_make -DXVSDK_INCLUDE_DIRS="/usr/include/xvsdk" -DXVSDK_LIBRARIES="/usr/lib/libxvsdk.so" 
# 三. 启动(后面每次启动demo只需运行下面指令即可,需要开三个终端分别启动)
# 1. node launch
roscore
# 2. roslaunch(in another terminal)
cd ~/code/catkin_ws/
roslaunch xv_sdk xv_sdk.launch
rosrun rviz rviz -d `rospack find xv_sdk`/rviz/demo.rviz

mid360

# 下载Livox-SDK2(home下,任意位置皆可)
git clone https://github.com/Livox-SDK/Livox-SDK2.git
cd Livox-SDK2
mkdir build
cd build
cmake .. && make -j8
sudo make install
# https://blog.csdn.net/zardforever123/article/details/134219903
cd ~/code/catkin_ws/src
git clone https://github.com/Star-Cheng/livox_ros_driver2.git
cd livox_ros_driver2
./build.sh ROS1
# 修改/livox_ros_driver2/config/MID_360_config.jsonl
cd ~/code/catkin_ws
source devel/setup.bash
roslaunch livox_ros_driver2 msg_MID360.launch
roslaunch livox_ros_driver2 rviz_MID360.launch
# fastlio中运行mid360: https://blog.csdn.net/qq_16775293/article/details/132408005
rosbag record -O faster_lio.bag /livox/lidar /livox/imu
roslaunch livox_ros_driver2 msg_MID360.launch
roslaunch fast_lio mapping_mid360.launch

Tools

创建自己的工作空间

mkdir -p ~/catkin_ws/src
# 方法一
# cd ~/catkin_ws/src
# catkin_init_workspace
# 方法二
cd ~/catkin_ws
catkin_make
# 刷新工作空间的bash脚本
source ~/catkin_ws/devel/setup.bash
# 可以将这段命令添加到~/.bashrc中, 以便每次启动终端时都自动执行该命令

docker 运行ros noetic

# https://www.zhihu.com/tardis/zm/art/552273212?source_id=1005
https://blog.csdn.net/zkk9527/article/details/121159353
sudo docker pull osrf/ros:noetic-desktop-full
xhost +
docker run --env="DISPLAY" --net=host --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --env="QT_X11_NO_MITSHM=1" -v /tmp/.X11-unix:/tmp/.X11-unix:ro -it --name noetic --ipc=host -it --gpus all -v /mnt/d/Docker:/root/gym osrf/ros:noetic-desktop-full
source /opt/ros/noetic/setup.bash
source ~/gym/code/catkin_ws/devel/setup.bash
# 可以将这段命令添加到~/.bashrc中, 以便每次启动终端时都自动执行该命令

Cmake demo

add_executable(lidar_node src/lidar_node.cpp)
add_dependencies(lidar_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(lidar_node
  ${catkin_LIBRARIES}
)

waypoint tools

roslaunch waterplus_map_tools add_waypoint_simulation.launch
rosrun waterplus_map_tools wp_saver

录屏

sudo apt install kazam -y
kazam
sudo apt install simplescreenrecorder -y
simplescreenrecorder

速度控制

rosrun rqt_robot_steering rqt_robot_steering

在WSL中添加代理

# git config --global user.name Star-Cheng
# git config --global user.email 133592901@qq.com
# git config --global http.proxy http://127.0.0.1:7890
# git config --global https.proxy https://127.0.0.1:7890

Terminator

  • sudo apt install terminator
  • ctrl+shift+E, ctrl+shift+O

Study

Node(节点)

  1. 使用catkin_create_pkg创建一个软件包
  2. 在软件包的src文件夹下创建一个节点的cpp源码文件
  3. 在节点的源码文件中include包含ROS的头文件
  4. 构建一个main函数, 并在函数的开头执行ros::inti()
  5. 构建while循环, 循环条件为ros::ok
  6. 在CMakeLists.txt中设置节点源码的编译规则
  7. 编译运行

Topic(话题)

  1. 一个ROS节点网络中, 可以同时存在多个话题
  2. 一个话题可以有多个发布者, 也可以有多个订阅者
  3. 一个节点可以对多个话题进行订阅, 也可以发布多个话题
  4. 不同的传感器小气通常会拥有各自独立话题名称, 每个话题只有一个发布者
  5. 机器人速度指令话题通常会有多个发布者, 但是同一时间只能有一个发言人

Message(消息)

  1. 确定话题名称消息类型
  2. 在代码文件中include消息类型对应的头文件
  3. 在main函数中通过NodeHandler大管家发布一个话题并得到消息发送对象
  4. 生成要发送的消息包并进行发送数据的赋值
  5. 调用消息发送对象的publish()函数将消息包发送到话题当中
  6. 常用工具
    1. rostopic list
      • 列出当前系统中所有活跃着的话题
    2. rostopic echo 主题名称
      • 显示指定话题中发送的消息包内容
    3. rostopic hz 主题名称
      • 统计指定话题中消息包发送频率
    4. rqt_graph
      • 图像化显示当前系统活跃的节点以及节点间的话题通讯关系
    5. rosmsgs list
      • 列出所有ROS中内置的消息类型
    6. rosmsg show 消息类型
      • 显示指定消息类型的消息结构
    7. rosmsg info 消息类型
      • 显示指定消息类型的消息结构, 并显示消息类型的依赖关系

Subscriber(订阅者)

  1. 确定话题名称消息类型
  2. 在代码文件中include消息类型对应的头文件
  3. 在main函数中通过NodeHandler大管家订阅一个话题并得到消息订阅对象
  4. 定义一个回调函数,对接收到的消息包进行处理
  5. main函数中需要执行ros::spinOnce(), 让回调函数能够响应接收到的消息包
  6. 常用工具
    1. rqt_graph
      • 图像化显示当前系统活跃的节点以及节点间的话题通讯关系

launch文件启动节点

  1. 使用lauch文件, 可以通过roslaunch指令一次启动多个节点
  2. 在launch文件中, 为节点添加output="screen"属性, 可以让节点信息输出在终端中(ROS_WARN不受改属性控制)
  3. 在launch文件中, 为节点添加launch-prefix="gnome-terminal -e"属性, 可以让节点运行在一个独立的终端中
<launch>
    <node pkg= "ssr_pkg" type="yao_node" name="yao_node"/>
    <node pkg= "ssr_pkg" type="chao_node" name="chao_node" launch-prefix="gnome-terminal -e"/>
    <node pkg= "atr_pkg" type="ma_node" name="ma_node" output="screen"/>
</launch>

ROS消息包

standard message common message geometry message sensor message

生成自定义消息包

  1. 创建新软件包, 依赖项: message_generation, message_runtime
  2. 软件包添加msg目录, 新建自定义消息文件, 以.msg结尾
  3. 在CMakeLists.txt中, 将新建的.msg文件加入到add_messages_files()
  4. 在CMakeLists.txt中, 去掉**generate_messages()**注释符号, 将依赖的其他消息包名添加进去
  5. 在CMakeLists.txt中, 将message_runtime加入catkin_package()的CATKIN_DEPENDS
  6. 在package.xml中, 将message_runtime加入<build_depend>, <exec_depend>
  7. 编译软件包, 生成新的自定义消息类型
  8. 使用rosmsg show package_name/message_name, 查看自定义消息类型
  9. <buildtool_depend>: 表示编译工具, <build_depend>: 用于寻找构建改功能包需要的依赖, <build_export_depend>: 用于寻找构建该功能包库时所用依赖的库, <exec_depend>: 执行该程序包中代码所需要的程序包

新消息类型在C++节点的应用

  1. 在节点代码中, 先include自定义消息类型的头文件
  2. 在发布或订阅话题的时候, 将话题中的消息类型设置为新的消息类型
  3. 按照新的消息结构, 对消息包进行赋值发送或读取解析
  4. 在CMakeLists.txt文件的find_package()中, 添加新消息名称作为依赖项
  5. 在节点的编译规则中, 添加一条add_dependencies(), 将新消息软件包名称_generate_messages_cpp作为依赖项
  6. 在package.xml文件中, 将新消息软件包名称加入<build_depend>, <exec_depend>
  7. 运行catkin_make, 编译新消息软件包

新消息类型在Python节点的应用

  1. 在节点代码中, 先import自定义消息类型的模块
  2. 在发布或订阅话题的时候, 将话题中的消息类型设置为新的消息类型
  3. 按照新的消息结构, 对消息包进行赋值发送或读取解析
  4. 在CMakeLists.txt文件的find_package()中, 添加新消息包名称作为依赖项
  5. 在package.xml文件中, 将新消息包名称加入<build_depend>, <exec_depend>
  6. 重写编译, 确保软件包进入ROS的包列表中

ROS中的相机话题

  1. /image_raw: 相机的原始数据
  2. /image_color: 相机的彩色图像数据
  3. /image_color_rect: 畸变校正后的彩色图像数据
  4. /camera_info: 相机参数信息

ROS中的基本数据

  1. /odom: 里程计数据
  2. /tf: 坐标系变换数据

ROS中导出里程计数据

rosbag play V1_01_easy.bag --topics /vicon/firefly_sbx/firefly_sbx   # 播放bag文件
rostopic echo /vicon/firefly_sbx/firefly_sbx > transform_data.txt    # 导出为txt格式数据
rostopic echo /vicon/firefly_sbx/firefly_sbx -p > transform_data.csv # 导出为csv格式数据, -p表示输出表格形式(CSV)进行打印
import rosbag
from geometry_msgs.msg import TransformStamped
# 处理数据
bag = rosbag.Bag('/home/gym/code/catkin_ws/data/V1_01_easy.bag')
for topic, msg, t in bag.read_messages(topics=['/vicon/firefly_sbx/firefly_sbx']):
    print(f"Time: {t.to_sec()}, Position: {msg.transform.translation}, Orientation: {msg.transform.rotation}")
bag.close()
# 可视化或保存数
import rosbag
from geometry_msgs.msg import TransformStamped
import csv
bag = rosbag.Bag("/home/gym/code/catkin_ws/data/V1_01_easy.bag")
with open('odom_data.csv', 'w', newline='') as csvfile:
    fieldnames = ['time', 'position_x', 'position_y', 'position_z', 'orientation_x', 'orientation_y', 'orientation_z', 'orientation_w']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    for topic, msg, t in bag.read_messages(topics=['/vicon/firefly_sbx/firefly_sbx']):
        # if isinstance(msg, TransformStamped):
        writer.writerow({
            'time': t.to_sec(),
            'position_x': msg.transform.translation.x,
            'position_y': msg.transform.translation.y,
            'position_z': msg.transform.translation.z,
            'orientation_x': msg.transform.rotation.x,
            'orientation_y': msg.transform.rotation.y,
            'orientation_z': msg.transform.rotation.z,
            'orientation_w': msg.transform.rotation.w
        })
bag.close()

About

ros test project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published