Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sensors] Launch vectornav in bringup.launch.py #229

Merged
merged 13 commits into from
Nov 24, 2024
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
path = external/articubot_one
url = https://github.com/joshnewans/articubot_one.git
branch = humble
[submodule "external/vectornav"]
path = external/vectornav
url = https://github.com/dawonn/vectornav.git
branch = ros2
62 changes: 62 additions & 0 deletions documents/installation/vectornav_imu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Launch Instructions for VectorNav with Permission Issues

This document explains how to resolve permission issues for serial devices (like `/dev/ttyUSB0`) and launch the VectorNav package on Linux.

## Prerequisites

1. **Install Necessary Packages**: Ensure all required packages are installed in your workspace and that the workspace is correctly sourced.

2. **Device Permissions**: You’ll need permission to access the device files (e.g., `/dev/ttyUSB0`).

## Steps

### Step 1: Check Device Permissions

1. First, identify the device port:
```bash
ls /dev/ttyUSB*
```
2. Verify your user has permission to access the device. If you see an error or permission denied, proceed with the steps below.

### Step 2: Add User to the `dialout` Group

The `dialout` group typically has access to serial devices. Add your user to this group:

```bash
sudo usermod -aG dialout $USER
```

**Note**: Log out and log back in for the group change to take effect. Alternatively, you can restart the system to apply these changes immediately.

### Step 3: Verify Permissions

After re-logging or rebooting, check that you have read and write permissions on the device:

```bash
ls -l /dev/ttyUSB0
```

If permissions are set correctly, the output should show that `dialout` has `rw` (read/write) access for `/dev/ttyUSB0`.

### Step 4: Launch VectorNav

Source your ROS workspace, then launch the VectorNav nodes with the appropriate configurations:

```bash
source ~/Documents/urc/rover-colcon/install/setup.bash
ros2 launch vectornav vectornav.launch.py
```

**Note**: Replace the workspace path with the correct path if it’s different on your system.

### Troubleshooting

If you continue to experience issues with permissions, consider checking `dmesg` logs to ensure the device is recognized:

```bash
dmesg | grep ttyUSB
```

This command shows messages related to the USB connection and may help diagnose connectivity issues.

---
1 change: 1 addition & 0 deletions external/vectornav
Submodule vectornav added at 2859fe
22 changes: 21 additions & 1 deletion urc_bringup/launch/bringup.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def generate_launch_description():
)
pkg_imu_driver = FindPackageShare("imu_driver").find("imu_driver")

pkg_vectornav = get_package_share_directory("vectornav")



controller_config_file_dir = os.path.join(
pkg_urc_bringup, "config", "controller_config.yaml"
)
Expand Down Expand Up @@ -81,6 +85,13 @@ def generate_launch_description():
arguments=["-p", controller_config_file_dir, "status_light_controller"],
)


imu_parser_node = Node(
package="urc_platform",
executable="urc_platform_IMUParser"
)


# load_arm_controller = Node(
# package="controller_manager",
# executable="spawner",
Expand Down Expand Up @@ -125,6 +136,13 @@ def generate_launch_description():
)
)

# change here
launch_vectornav = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_vectornav, "launch", "vectornav.launch.py")
)
)

rosbridge_server_node = Node(
package="rosbridge_server",
name="rosbridge_server",
Expand Down Expand Up @@ -160,6 +178,8 @@ def generate_launch_description():
launch_gps,
launch_imu,
rosbridge_server_node,
odom_frame_node
odom_frame_node,
launch_vectornav,
imu_parser_node
]
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file supposed to be here? It is empty.

Empty file.
9 changes: 9 additions & 0 deletions urc_platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(diagnostic_updater REQUIRED)
find_package(usb_cam REQUIRED)
find_package(vectornav_msgs REQUIRED)

include_directories(
include
Expand All @@ -19,6 +20,7 @@ include_directories(
# Library creation
add_library(${PROJECT_NAME} SHARED
src/joystick_driver.cpp
src/imu_parser.cpp
)

set(dependencies
Expand All @@ -28,6 +30,7 @@ set(dependencies
sensor_msgs
diagnostic_updater
usb_cam
vectornav_msgs
)

ament_target_dependencies(${PROJECT_NAME}
Expand All @@ -41,6 +44,12 @@ rclcpp_components_register_node(
EXECUTABLE ${PROJECT_NAME}_JoystickDriver
)

rclcpp_components_register_node(
${PROJECT_NAME}
PLUGIN "imu_parser::IMUParser"
EXECUTABLE ${PROJECT_NAME}_IMUParser
)

# Install launch files.
install(
DIRECTORY
Expand Down
33 changes: 33 additions & 0 deletions urc_platform/include/imu_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef IMU_PARSER_H
#define IMU_PARSER_H

#include <bits/stdc++.h>
#include <math.h>
#include <rclcpp/qos.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_components/register_node_macro.hpp>
#include <sensor_msgs/msg/imu.hpp>
#include <unistd.h>
#include <vectornav_msgs/msg/common_group.hpp>

namespace imu_parser
{

class IMUParser : public rclcpp::Node
{
public:
explicit IMUParser(const rclcpp::NodeOptions & options);

private:
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr
imu_publisher;

rclcpp::Subscription<vectornav_msgs::msg::CommonGroup>::SharedPtr vectornav_subscriber;

void VectornavCallback(const vectornav_msgs::msg::CommonGroup & msg);

};

} // namespace imu_parser

#endif
1 change: 1 addition & 0 deletions urc_platform/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<depend>usb_cam</depend>
<depend>image_transport</depend>
<depend>image_transport_plugins</depend>
<depend>vectornav_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
57 changes: 57 additions & 0 deletions urc_platform/src/imu_parser.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this IMU parser node anymore. There should be an option in the config file for the vectornav package that will automatically publish a ROS 2 sensor_msgs/Imu message.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "imu_parser.hpp"

namespace imu_parser
{

int header = 0;
IMUParser::IMUParser(const rclcpp::NodeOptions & options)
: rclcpp::Node("imu_parser", options)
{
vectornav_subscriber = create_subscription<vectornav_msgs::msg::CommonGroup>(
"/vectornav/raw/common", rclcpp::SystemDefaultsQoS(),
[this](const vectornav_msgs::msg::CommonGroup msg) {VectornavCallback(msg);});

imu_publisher = create_publisher<sensor_msgs::msg::Imu>(
"/imu/data", rclcpp::SystemDefaultsQoS());
}

void IMUParser::VectornavCallback(const vectornav_msgs::msg::CommonGroup & msg)
{
sensor_msgs::msg::Imu result;
result.header.frame_id = std::to_string(header++);

result.orientation.x = msg.quaternion.x;
result.orientation.y = msg.quaternion.y;
result.orientation.z = msg.quaternion.z;
result.orientation.w = msg.quaternion.w;
result.orientation_covariance = {
0.01, 0.0, 0.0,
0.0, 0.01, 0.0,
0.0, 0.0, 0.01
};

result.angular_velocity.x = msg.angularrate.x;
result.angular_velocity.y = msg.angularrate.y;
result.angular_velocity.z = msg.angularrate.z;
result.angular_velocity_covariance = {
0.01, 0.0, 0.0,
0.0, 0.01, 0.0,
0.0, 0.0, 0.01
};

result.linear_acceleration.x = msg.accel.x;
result.linear_acceleration.y = msg.accel.y;
result.linear_acceleration.z = msg.accel.z;
result.linear_acceleration_covariance = {
0.01, 0.0, 0.0,
0.0, 0.01, 0.0,
0.0, 0.0, 0.01
};


imu_publisher->publish(result);
}

} // namespace orchestrator

RCLCPP_COMPONENTS_REGISTER_NODE(imu_parser::IMUParser)
Loading