raspimouse_ros2_examples repository

Repository Summary

Checkout URI https://github.com/rt-net/raspimouse_ros2_examples.git
VCS Type git
VCS Version humble-devel
Last Updated 2024-03-06
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Packages

Name Version
raspimouse_ros2_examples 2.2.0

README

English | 日本語

raspimouse_ros2_examples

industrial_ci

ROS 2 examples for Raspberry Pi Mouse.

ROS1 examples is here.

To run on Gazebo, click here.

Supported ROS 2 distributions

  • Foxy
  • Humble (This branch)

Requirements

Installation

$ cd ~/ros2_ws/src
# Clone package
$ git clone -b $ROS_DISTRO-devel https://github.com/rt-net/raspimouse_ros2_examples.git

# Install dependencies
$ rosdep install -r -y --from-paths . --ignore-src

# Build & Install
$ cd ~/ros2_ws
$ colcon build --symlink-install
$ source ~/ros2_ws/install/setup.bash

License

This repository is licensed under the Apache 2.0, see LICENSE for details.

How To Use Examples


joystick_control

This is an example to use joystick controller to control a Raspberry Pi Mouse.

Requirements

How to use

Launch nodes with the following command:

# Use F710
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py joydev:="/dev/input/js0" joyconfig:=f710 mouse:=true

# Use DUALSHOCK 3
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py joydev:="/dev/input/js0" joyconfig:=dualshock3 mouse:=true

# Control from remote computer
## on RaspberryPiMouse
$ ros2 run raspimouse raspimouse
## on remote computer
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py mouse:=false

This picture shows the default key configuration.

To use Logicool Wireless Gamepad F710, set the input mode to D (DirectInput Mode).

Configure

Key assignments can be edited with key numbers in ./config/joy_f710.yml or ./config/joy_dualshock3.yml.

button_shutdown_1       : 8
button_shutdown_2       : 9

button_motor_off        : 8
button_motor_on         : 9

button_cmd_enable       : 4

Videos

joystick_control

back to example list


object_tracking

This is an example to use RGB camera images and OpenCV library for object tracking.

Requirements

Installation

Install a camera mount and a web camera to Raspberry Pi Mouse, then connect the camera to the Raspberry Pi.

How to use

Turn off automatic adjustment parameters of a camera (auto focus, auto while balance, etc.) with the following command:

$ cd ~/ros2_ws/src/raspimouse_ros2_examples/config
$ ./configure_camera.bash

Then, launch nodes with the following command:

$ ros2 launch raspimouse_ros2_examples object_tracking.launch.py video_device:=/dev/video0

This sample publishes two topics: camera/color/image_raw for the camera image and result_image for the object detection image. These images can be viewed with RViz or rqt_image_view.

Viewing an image may cause the node to behave unstable and not publish cmd_vel or image topics.

Configure

Edit ./src/object_tracking_component.cpp to change a color of tracking target.

If the object detection accuracy is poor, adjust the camera exposure and parameters in the function

void Tracker::tracking(const cv::Mat & input_frame, cv::Mat & result_frame)
{
  cv::inRange(hsv, cv::Scalar(9, 100, 100), cv::Scalar(29, 255, 255), extracted_bin);  // Orange
  // cv::inRange(hsv, cv::Scalar(60, 100, 100), cv::Scalar(80, 255, 255), extracted_bin);  // Green
  // cv::inRange(hsv, cv::Scalar(100, 100, 100), cv::Scalar(120, 255, 255), extracted_bin);  // Blue

Videos

object_tracking

back to example list


line_follower

This is an example for line following.

Requirements

Installation

Install a line following sensor unit to Raspberry Pi Mouse.

How to use

Launch nodes with the following command:

$ ros2 launch raspimouse_ros2_examples line_follower.launch.py

Next, place Raspberry Pi Mouse on a field and press SW2 to sample sensor values on the field.

Then, place Raspberry Pi Mouse to detect a line and press SW1 to sample sensor values on the line.

Last, place Raspberry Pi Mouse on the line and press SW0 to start line following.

Press SW0 again to stop the following.

Configure

Edit ./src/line_follower_component.cpp to change a velocity command.

void Follower::publish_cmdvel_for_line_following(void)
{
  const double VEL_LINEAR_X = 0.08;  // m/s
  const double VEL_ANGULAR_Z = 0.8;  // rad/s
  const double LOW_VEL_ANGULAR_Z = 0.5;  // rad/s

Videos

line_follower

back to example list


camera_line_follower

This is an example for line following by RGB camera.

Requirements

Installation

Install a camera mount and a web camera to Raspberry Pi Mouse, then connect the camera to the Raspberry Pi.

How to use

Then, launch nodes with the following command:

$ ros2 launch raspimouse_ros2_examples camera_line_follower.launch.py video_device:=/dev/video0

Place Raspberry Pi Mouse on the line and press SW2 to start line following.

Press SW0 to stop the following.

This sample publishes two topics: camera/color/image_raw for the camera image and result_image for the object detection image. These images can be viewed with RViz or rqt_image_view.

Viewing an image may cause the node to behave unstable and not publish cmd_vel or image topics.

Parameters

  • max_brightness
    • Type: int
    • Default: 90
    • Maximum threshold value for image binarisation.
  • min_brightness
    • Type: int
    • Default: 0
    • Minimum threshold value for image binarisation.
  • max_linear_vel
    • Type: double
    • Default: 0.05
    • Maximum linear velocity.
  • max_angular_vel
    • Type: double
    • Default: 0.8
    • Maximum angular velocity.
  • area_threthold
    • Type: double
    • Default: 0.20
    • Threshold value of the area of the line to start following.
ros2 param set /camera_follower max_brightness 80

back to example list


SLAM

SLAM and Navigation examples for Raspberry Pi Mouse is here.

back to example list


direction_controller

This is an example to use an IMU sensor for direction control.

Requirements

Installation

Install the IMU sensor module to the LiDAR mount.

Install the LiDAR mount to the Raspberry Pi Mouse.

How to use

Launch nodes on Raspberry Pi Mouse with the following command:

$ ros2 launch raspimouse_ros2_examples direction_controller.launch.py

Then, press SW0 ~ SW2 to change the control mode as following,

  • SW0: Calibrate the gyroscope bias and reset a heading angle of Raspberry Pi Mouse to 0 rad.
  • SW1: Start a direction control to keep the heading angle to 0 rad.
    • Press SW0 ~ SW2 or tilt the body to sideways to finish the control.
  • SW2: Start a direction control to change the heading angle to -π ~ π rad.
    • Press SW0 ~ SW2 or tilt the body to sideways to finish the control.

Troubleshooting

The IMU might not be connected correctly.
Reconnect the USB cable several times and re-execute the above command.

Configure

Set parameters to configure gains of a PID controller for the direction control.

$ ros2 param set /direction_controller p_gain 10.0
Set parameter successful

$ ros2 param set /direction_controller i_gain 0.5
Set parameter successful

$ ros2 param set /direction_controller d_gain 0.0
Set parameter successful

Parameters

  • p_gain
    • Proportional gain of a PID controller for the direction control
    • default: 10.0, min:0.0, max:30.0
    • type: double
  • i_gain
    • Integral gain of a PID controller for the direction control
    • default: 0.0, min:0.0, max:5.0
    • type: double
  • d_gain
    • Derivative gain of a PID controller for the direction control
    • default: 20.0, min:0.0, max:30.0
    • type: double
  • target_angle
    • Target angle for the SW1 control mode.
    • default: 0.0, min:-π, max:+π
    • type: double

Publish topics

  • heading_angle
    • Heading angle of the robot that calculated from the IMU module sensor values.
    • type: std_msgs/Float64

Videos

back to example list

CONTRIBUTING

Any contribution that you make to this repository will be under the Apache 2 License, as dictated by that license:

5. Submission of Contributions. Unless You explicitly state otherwise,
   any Contribution intentionally submitted for inclusion in the Work
   by You to the Licensor shall be under the terms and conditions of
   this License, without any additional terms or conditions.
   Notwithstanding the above, nothing herein shall supersede or modify
   the terms of any separate license agreement you may have executed
   with Licensor regarding such Contributions.

Repository Summary

Checkout URI https://github.com/rt-net/raspimouse_ros2_examples.git
VCS Type git
VCS Version foxy-devel
Last Updated 2022-07-29
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Packages

Name Version
raspimouse_ros2_examples 1.0.0

README

English | 日本語

raspimouse_ros2_examples

industrial_ci

ROS 2 examples for Raspberry Pi Mouse.

ROS1 examples is here.

Requirements

Installation

$ cd ~/ros2_ws/src
# Clone package
$ git clone -b $ROS_DISTRO-devel https://github.com/rt-net/raspimouse_ros2_examples

# Install dependencies
$ rosdep install -r -y --from-paths . --ignore-src

# Build & Install
$ cd ~/ros2_ws
$ colcon build --symlink-install
$ source ~/ros2_ws/install/setup.bash

License

This repository is licensed under the Apache 2.0, see LICENSE for details.

How To Use Examples


joystick_control

This is an example to use joystick controller to control a Raspberry Pi Mouse.

Requirements

How to use

Launch nodes with the following command:

# Use F710
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py joydev:="/dev/input/js0" joyconfig:=f710 mouse:=true

# Use DUALSHOCK 3
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py joydev:="/dev/input/js0" joyconfig:=dualshock3 mouse:=true

# Control from remote computer
## on RaspberryPiMouse
$ ros2 run raspimouse raspimouse
## on remote computer
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py mouse:=false

This picture shows the default key configuration.

To use Logicool Wireless Gamepad F710, set the input mode to D (DirectInput Mode).

Configure

Key assignments can be edited with key numbers in ./config/joy_f710.yml or ./config/joy_dualshock3.yml.

button_shutdown_1       : 8
button_shutdown_2       : 9

button_motor_off        : 8
button_motor_on         : 9

button_cmd_enable       : 4

Videos

joystick_control

back to example list


object_tracking

This is an example to use RGB camera images and OpenCV library for object tracking.

Requirements

Installation

Install a camera mount and a web camera to Raspberry Pi Mouse, then connect the camera to the Raspberry Pi.

How to use

Turn off automatic adjustment parameters of a camera (auto focus, auto while balance, etc.) with the following command:

$ cd ~/ros2_ws/src/raspimouse_ros2_examples/config
$ ./configure_camera.bash

Then, launch nodes with the following command:

$ ros2 launch raspimouse_ros2_examples object_tracking.launch.py

This sample publishes two topics: raw_image for the camera image and result_image for the object detection image. These images can be viewed with RViz or rqt_image_view.

Viewing an image may cause the node to behave unstable and not publish cmd_vel or image topics.

Configure

Edit ./src/object_tracking_component.cpp to change a color of tracking target.

If the object detection accuracy is poor, adjust the camera exposure and parameters in the function

void Tracker::tracking(const cv::Mat & input_frame, cv::Mat & result_frame)
{
  cv::inRange(hsv, cv::Scalar(9, 100, 100), cv::Scalar(29, 255, 255), extracted_bin);  // Orange
  // cv::inRange(hsv, cv::Scalar(60, 100, 100), cv::Scalar(80, 255, 255), extracted_bin);  // Green
  // cv::inRange(hsv, cv::Scalar(100, 100, 100), cv::Scalar(120, 255, 255), extracted_bin);  // Blue

Videos

object_tracking

back to example list


line_follower

This is an example for line following.

Requirements

Installation

Install a line following sensor unit to Raspberry Pi Mouse.

How to use

Launch nodes with the following command:

$ ros2 launch raspimouse_ros2_examples line_follower.launch.py

Next, place Raspberry Pi Mouse on a field and press SW2 to sample sensor values on the field.

Then, place Raspberry Pi Mouse to detect a line and press SW1 to sample sensor values on the line.

Last, place Raspberry Pi Mouse on the line and press SW0 to start line following.

Press SW0 again to stop the following.

Configure

Edit ./src/line_follower_component.cpp to change a velocity command.

void Follower::publish_cmdvel_for_line_following(void)
{
  const double VEL_LINEAR_X = 0.08;  // m/s
  const double VEL_ANGULAR_Z = 0.8;  // rad/s
  const double LOW_VEL_ANGULAR_Z = 0.5;  // rad/s

Videos

line_follower

back to example list


SLAM

This is an example to use LiDAR and slam_toolbox for SLAM (Simultaneous Localization And Mapping).

Requirements

Installation

Install a LiDAR to the Raspberry Pi Mouse.

  • LDS-01

How to use

Launch nodes on Raspberry Pi Mouse with the following command:

# LDS
$ ros2 launch raspimouse_ros2_examples mouse_with_lidar.launch.py lidar:=lds

Next, launch teleop_joy.launch.py to control Raspberry Pi Mouse with the following command:

# Use DUALSHOCK 3
$ ros2 launch raspimouse_ros2_examples teleop_joy.launch.py joydev:="/dev/input/js0" joyconfig:=dualshock3 mouse:=false

Then, launch the slam_toolbox package (on a remote computer recommend) with the following command:

$ ros2 launch raspimouse_ros2_examples slam.launch.py

After moving Raspberry Pi Mouse and making a map, run a node to save the map with the following command:

$ mkdir ~/maps
$ ros2 run nav2_map_server map_saver_cli -f ~/maps/mymap --ros-args -p save_map_timeout:=10000

Configure SLAM parameters

Edit ./config/mapper_params_offline.yaml to configure parameters of slam_toolbox package.

Configure Odometry calculation

Edit mouse.yml to set use_pulse_counters to true (default: false) then the raspimouse node calculate the odometry (/odom) from motor control pulse counts.

This improves the accuracy of self-localization.

raspimouse:
  ros__parameters:
    odometry_scale_left_wheel : 1.0
    odometry_scale_right_wheel: 1.0
    use_light_sensors         : true
    use_pulse_counters        : true

back to example list


direction_controller

This is an example to use an IMU sensor for direction control.

Requirements

Installation

Install the IMU sensor module to the LiDAR mount.

Install the LiDAR mount to the Raspberry Pi Mouse.

How to use

Launch nodes on Raspberry Pi Mouse with the following command:

$ ros2 launch raspimouse_ros2_examples direction_controller.launch.py

Then, press SW0 ~ SW2 to change the control mode as following,

  • SW0: Calibrate the gyroscope bias and reset a heading angle of Raspberry Pi Mouse to 0 rad.
  • SW1: Start a direction control to keep the heading angle to 0 rad.
    • Press SW0 ~ SW2 or tilt the body to sideways to finish the control.
  • SW2: Start a direction control to change the heading angle to -π ~ π rad.
    • Press SW0 ~ SW2 or tilt the body to sideways to finish the control.

Configure

Set parameters to configure gains of a PID controller for the direction control.

$ ros2 param set /direction_controller p_gain 10.0
Set parameter successful

$ ros2 param set /direction_controller i_gain 0.5
Set parameter successful

$ ros2 param set /direction_controller d_gain 0.0
Set parameter successful

Parameters

  • p_gain
    • Proportional gain of a PID controller for the direction control
    • default: 10.0, min:0.0, max:30.0
    • type: double
  • i_gain
    • Integral gain of a PID controller for the direction control
    • default: 0.0, min:0.0, max:5.0
    • type: double
  • d_gain
    • Derivative gain of a PID controller for the direction control
    • default: 20.0, min:0.0, max:30.0
    • type: double
  • target_angle
    • Target angle for the SW1 control mode.
    • default: 0.0, min:-π, max:+π
    • type: double

Publish topics

  • heading_angle
    • Heading angle of the robot that calculated from the IMU module sensor values.
    • type: std_msgs/Float64

Videos

back to example list

CONTRIBUTING

Any contribution that you make to this repository will be under the Apache 2 License, as dictated by that license:

5. Submission of Contributions. Unless You explicitly state otherwise,
   any Contribution intentionally submitted for inclusion in the Work
   by You to the Licensor shall be under the terms and conditions of
   this License, without any additional terms or conditions.
   Notwithstanding the above, nothing herein shall supersede or modify
   the terms of any separate license agreement you may have executed
   with Licensor regarding such Contributions.