How to install ROS2 Humble and program a Doosan cobot in Python

Based on contributions by Roos.

Programming a Doosan cobot directly is awkward. Controlling it through ROS2 instead lets you simulate your program without needing access to the physical robot, and use regular Python libraries without the workarounds required by Doosan’s own Python offering. This guide covers installing ROS2 and the Doosan ROS2 driver, connecting to a real or simulated M-series cobot, and writing your own Python control scripts. It does not cover ROS2’s wider feature set.

What you need

  • A PC (or VM) running Ubuntu 22.04 LTS, which pairs with ROS2 Humble. Windows is listed as an install option in the ROS2 docs, but it is not well supported and does not work with the Doosan driver — use Ubuntu.
  • A Doosan cobot (e.g. an M1013) connected by Ethernet, or use the driver’s built-in simulation mode if you don’t have hardware access.
  • The doosan-robot2 ROS2 workspace (humble branch).
  • Familiarity with basic terminal commands and general Linux troubleshooting.

Steps

1. Install ROS2 Humble

Follow the official ROS2 Humble installation guide for Ubuntu 22.04.

If you’re using a different Ubuntu version, switch the distro selector at the bottom-left of that page — but check first that both ROS2 and the Doosan packages support it.

Screenshot_1

Once ROS2 is installed, source it in every new terminal before running any ros2 command:

source /opt/ros/humble/setup.bash

To avoid typing this every time, add it to the end of your ~/.bashrc (edit it with gedit ~/.bashrc):

Screenshot_3

This sources ROS2 automatically in every new terminal. Sourcing tells the terminal which commands and environment variables are available in the current session — comparable to setting environment variables on Windows.

2. Install the Doosan ROS2 packages

Clone the humble branch of doosan-robot2 into a ROS2 workspace and follow the repository’s build instructions. When you reach the colcon build step, add --symlink-install:

colcon build --cmake-args -DDRCF_VER=3 --symlink-install

--symlink-install links your Python scripts into the install directory instead of copying them, so edits to your script take effect immediately without rebuilding. You can always rebuild later if needed.

If you’re not on Ubuntu 22.04, make sure to follow the matching install guide on the repository page:

Source the workspace’s own setup script to enable the Doosan ROS2 commands:

source install/setup.bash

Run this from inside the workspace folder, and repeat it in every new terminal you use — the Doosan commands won’t be available otherwise. Adding this line to ~/.bashrc is convenient if you only ever work with this one workspace, but is generally discouraged: sourcing it globally can cause confusing conflicts if you later work with a different ROS2 workspace.

If you run into install issues, search online first; if that fails, an AI assistant can often help debug Linux/ROS2 problems.

3. Connect to the robot or start a simulation

The doosan-robot2 repository provides three launch configurations: RViz2, Gazebo simulation, and MoveIt2. For basic control you’ll mostly need RViz2 to connect to the cobot and send move commands. Each launch command supports two modes:

  • virtual: simulates the cobot so you can test code without hardware.
  • real: connects to the physical cobot. You must pass the robot’s IP address, which you can find on the teach pendant.

For real mode, connect to the cobot over Ethernet, configure your network settings, and confirm connectivity before launching:

ping <cobot ip address>

4. Run a built-in test script

Confirm the connection works by running one of the driver’s example scripts:

ros2 run <package> <script>

For example:

ros2 run dsr_example slope_demo

:warning: If connected in real mode, this moves the physical robot in an unpredictable direction. Keep your hand on the emergency stop.

5. Create a custom package for your own scripts

Go to your ROS2 workspace folder (the doosan-robot2 workspace) and create a Python package:

ros2 pkg create <package_name> --build-type ament_python --dependencies rclpy

This creates a package with a subfolder of the same name containing an __init__.py file — do not delete this file. Add your custom script in that same subfolder as <your_script>.py. A recommended starting script is at the bottom of this guide.

Once your script exists, register it in setup.py. Open the setup.py created in your package folder, find the entry_points / console_scripts section, and add your script:

entry_points={
    'console_scripts': [
        'testscript = how_to_package.testscript:main',
    ],
},

6. Build and run your script

Rebuild the workspace so it picks up the new package and entry point:

colcon build --cmake-args -DDRCF_VER=3 --symlink-install

(--symlink-install again means future edits to your script take effect without rebuilding.) Then run it:

ros2 run <package> <script_name>

That’s it — ROS2 and the Doosan packages are installed, and you can program the cobot in Python much like you would a Universal Robots cobot through ROS2. ROS2 offers a lot more functionality beyond this if you want to explore further.

Example: recommended starting script

import rclpy
import DR_init


def main(args=None):
    rclpy.init(args=args)

    # Cobot settings
    ROBOT_ID = "dsr01"
    ROBOT_MODEL = "m1013"
    DR_init.__dsr__id = ROBOT_ID
    DR_init.__dsr__model = ROBOT_MODEL

    # Node name — not important to change
    node = rclpy.create_node('example_py', namespace=ROBOT_ID)
    DR_init.__dsr__node = node

    # This import must happen after DR_init is configured above; do not move it.
    # Add any other DSR_ROBOT2 functions you need to this import line.
    from DSR_ROBOT2 import (
        get_current_posx, posx, movel, movejx, movej, posj,
        set_digital_output, set_robot_mode, get_robot_mode,
        ROBOT_MODE_AUTONOMOUS, get_current_pose,
        get_digital_input, get_modbus_input,
    )

    # Enable remote-control commands. In this mode you CANNOT freemove the robot by hand.
    if get_robot_mode() != ROBOT_MODE_AUTONOMOUS:
        set_robot_mode(ROBOT_MODE_AUTONOMOUS)

    # Robot mode 0 is freemove: the robot ignores commands but can be moved by hand.
    # Uncomment to enable it, or add your own logic to toggle it when needed.
    # set_robot_mode(0)

    # Move the robot
    cobot_start_position = posx(300, 34, 1000, 0, 90, 0)  # x, y, z, rx, ry, rz
    movejx(cobot_start_position, vel=30, acc=30)

    # Replace this with your own control loop; add a stop condition so the
    # code below can run.
    while True:
        print(get_current_posx())

    print("Example complete")
    rclpy.shutdown()


if __name__ == '__main__':
    main()

Troubleshooting / Common mistakes

  • ros2 run / Doosan commands not found: you forgot to source setup.bash. This has to be repeated in every new terminal window, for both ROS2 (/opt/ros/humble/setup.bash) and the Doosan workspace (install/setup.bash) — unless you added them to ~/.bashrc.
  • Robot doesn’t respond to commands: make sure set_robot_mode(ROBOT_MODE_AUTONOMOUS) has been called — the robot won’t accept remote commands in freemove mode (mode 0).
  • Real-mode testing: always keep a hand on the emergency stop button before running any script against a physical robot, especially the built-in demo scripts.
  • Getting help: the doosan-robot2 issues page is for problems with the ROS2 installation/driver itself, not general “how do I program X” questions.
  • Useful references: the Python API command list for importable functions, and the official API manual for how to use them. You can also browse the DSR folders inside the doosan-robot2 workspace directly — every Python function you call is defined there.

Related


Rewritten and consolidated (Sept 2026) from the original student how-to’s: How to install and use ROS2 to connect and program an doosan cobot.