Try   HackMD

台達機械手臂IMP3整合ROS2

tags: vsclab

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
回到 2023 VSCLab 温梓傑 交接資料

Outline

Git Config

user.email=n26104256@gs.ncku.edu.tw
user.name=112-VSCLAB.Wun

Installation

Practices of Official Docs

(2022/9/26) Using colcon to build packages

[colcon build Error]: this step

# Input
colcon build --symlink-install --merge-install

# Output
ROS2 error: can‘t find examples_rclcpp_minimal_subscriber/Release/wait_set_subscriber
(2022/9/27) Creating a workspace

[colcon build error]

C:\dev\ros2_ws>colcon build --merge-install --packages-select my_package
[1.125s] colcon.colcon_core.package_identification WARNING Failed to parse ROS package manifest in 'src\my_package': Error(s) in package 'src\my_package\package.xml':
Invalid email "Delta Robot@todo.todo" for person "Delta Robot"
Starting >>> my_package
--- stderr: my_package
Error parsing 'C:/dev/ros2_ws/src/my_package/package.xml':
Traceback (most recent call last):
  File "C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py", line 150, in <module>
    main()
  File "C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py", line 53, in main
    raise e
  File "C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py", line 49, in main
    package = parse_package_string(
  File "C:\Python38\lib\site-packages\catkin_pkg\package.py", line 788, in parse_package_string
    pkg.validate(warnings=warnings)
  File "C:\Python38\lib\site-packages\catkin_pkg\package.py", line 330, in validate
    raise InvalidPackage('\n'.join(errors), self.filename)
catkin_pkg.package.InvalidPackage: Error(s) in package 'C:/dev/ros2_ws/src/my_package/package.xml':
Invalid email "Delta Robot@todo.todo" for person "Delta Robot"
CMake Error at C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:95 (message):
  execute_process(C:/Python38/python.exe
  C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py
  C:/dev/ros2_ws/src/my_package/package.xml
  C:/dev/ros2_ws/build/my_package/ament_cmake_core/package.cmake) returned
  error code 1
Call Stack (most recent call first):
  C:/dev/ros2_humble/ros2-windows/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:49 (_ament_package_xml)
  C:/dev/ros2_humble/ros2-windows/share/ament_lint_auto/cmake/ament_lint_auto_find_test_dependencies.cmake:31 (ament_package_xml)
  CMakeLists.txt:32 (ament_lint_auto_find_test_dependencies)


---
Failed   <<< my_package [0.72s, exited with code 1]

Summary: 0 packages finished [1.16s]
  1 package failed: my_package
  1 package had stderr output: my_package
  • Solution:
    C:/dev/ros2_ws/src/my_package/package.xml改成有效 email
(2022/9/27) Writing a simple publisher and subscriber (C++)

[Visual Studio Code IncludePath Issue with ROS headers]

# .vscode/c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/dev/ros2_humble/ros2-windows/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}
(Skip) Writing a simple publisher and subscriber (Python)
(2022/9/28) Writing a simple service and client (C++)
(Skip) Writing a simple service and client (Python)

Integrate IMP3 code with ROS2 packages

Create workspace and package

# Create a workspace
mkdir delta_ros2_ws\src
cd delta_ros2_ws\src

# Create a ros2 package named "delta" and dependencies
ros2 pkg create --build-type ament_cmake delta --dependencies rclcpp std_msgs example_interfaces

Modify src/delta/package.xml

  1. Update the package descriptioin
  2. Update your valid email
  3. Update license
<description>Delta Robot with ROS2</description> <maintainer email="vsclab.youbot@gmail.com">Delta Robot</maintainer> <license>Apache License 2.0</license>

Copy IMP3 code

  1. Header Files (.h/.hpp): delta_ros2_ws/src/delta/include/delta
  2. Source Files (.cpp): delta_ros2_ws/src/delta/src

Troubleshoots

Colcon build in Win10

Settings of colcon and debug

[o] No error message output while building

  • Solution:
colcon build --event-handlers console_direct+

[o] MVC output garbled message

  • Solution: Switch Win10 Language preferences to "English, United States"

[o] Annoying notifications after build success/failure

$ set COLCON_EXTENSION_BLOCKLIST=colcon_core.event_handler.desktop_notification

CMake issues

[o] Include custom header files in ROS2 package

# Custom Lib include_directories(include) # Find the include directories add_library(savedata src/SaveData.cpp) # add library definition target_link_libraries(main savedata) # Link to the executable ("main")

[x] Include static/dynamic library

set(IMC_LIB_PATH "C:/Program Files (x86)/ITRI/IMP3/IDDL/Library/VC/IMC3Driver.lib") # At Program Files(x86) target_link_libraries(main ${IMC_LIB_PATH})

[o] Build custom library with ros dependencies

add_library(motioncard src/delta/MotionCard.cpp)  # Compile "MotionCard.cpp"
ament_target_dependencies(motioncard rclcpp std_msgs example_interfaces)
target_include_directories(motioncard
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>)

[o] Compiler Warning (level 1) C4819

  • Solution
    1. 打开 Control Panel
    2. 选择 Region (and Language)
    3. 选择 Administrative 页签
    4. 在 Language for non-Unicode programs 区域点击 "Change System Locale" 按钮
    5. 设置 Current system locale,比如 English (United States)。
    6. 点击 "OK" 保存。

Program Descriptions

開發過程

Joint State Message

Some Tricks

台達機械手臂緊急停機SOP

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
先備知識

命令 行為 備註
Servo ON 馬達 煞車
Servo OFF 馬達 煞車
  • 控制箱總電源上電時,會先進行 Servo OFF (煞車) 動作
緊急停機旋鈕壓下
關閉控制箱總電源
執行清命令程式
開啟控制箱總電源
旋開緊急開關
按下藍色RESET鈕
一人先扶著手臂,另一人再按下ServoON
手臂復位
ServoOFF

在兩台虛擬機之間用ROS2溝通

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
ros2 communication between two virtual machines

# Step 1: 確認兩台VM的IP位址
$ ip a        # Ubuntu 20.04 up
$ ipconfig    # Windows

# Step 2: 互相ping對方
$ ping 192.168.aaa.aaa -c 3 # Ubuntu ([-c] 代表ping的次數)
$ ping 192.168.bbb.bbb      # Windows

# Step 3: 設定相同號碼的$ROS_DOMAIN_ID
$ export ROS_DOMAIN_ID=5    # 設定Ubuntu環境變數
$ echo $ROS_DOMAIN_ID       # 查看Ubuntu環境變數
> 5
$ set ROS_DOMAIN_ID=5       # 設定Windows環境變數
$ echo %ROS_DOMAIN_ID%      # 查看Windows環境變數
> 5
參考教學