Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions odrive_node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_srvs REQUIRED)
find_package(std_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/ControlMessage.msg"
"msg/ControllerStatus.msg"
"msg/ODriveStatus.msg"
"srv/AxisState.srv"
DEPENDENCIES std_msgs
)
ament_export_dependencies(rosidl_default_runtime)

Expand Down
38 changes: 38 additions & 0 deletions odrive_node/launch/multiple_odrives_example_launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
launch:

- node:
pkg: "odrive_can"
exec: "odrive_can_node"
name: "can_node6"
namespace: "odrive_axis0"
param:
-
name: "node_id"
value: 6
-
name: "interface"
value: "can0"
- node:
pkg: "odrive_can"
exec: "odrive_can_node"
name: "can_node7"
namespace: "odrive_axis0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these names should be different for each instance

param:
-
name: "node_id"
value: 7
-
name: "interface"
value: "can0"
- node:
pkg: "odrive_can"
exec: "odrive_can_node"
name: "can_node8"
namespace: "odrive_axis0"
param:
-
name: "node_id"
value: 8
-
name: "interface"
value: "can0"
2 changes: 2 additions & 0 deletions odrive_node/msg/ODriveStatus.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
std_msgs/Header header

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we're not using any of the other fields in Header, is there any downside to just using time timestamp directly?

uint32 node_id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your PR description states that this node_id should serve to distinguish two or more ODrive sources. But the typical way to do this that I know of is via the topic path on which they are published:

ros2 topic echo /odrive_axis0/odrive_status
ros2 topic echo /odrive_axis1/odrive_status
...

Is there a scenario where this does not work?

float32 bus_voltage
float32 bus_current
float32 fet_temperature
Expand Down
1 change: 1 addition & 0 deletions odrive_node/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<depend>rclcpp</depend>
<depend>std_srvs</depend>
<depend>std_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
3 changes: 3 additions & 0 deletions odrive_node/src/odrive_can_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ bool ODriveCanNode::init(EpollEventLoop* event_loop) {
axis_idle_on_shutdown_ = rclcpp::Node::get_parameter("axis_idle_on_shutdown").as_bool();
std::string interface = rclcpp::Node::get_parameter("interface").as_string();

odrv_stat_.node_id = node_id_;

if (!can_intf_.init(interface, event_loop, std::bind(&ODriveCanNode::recv_callback, this, _1))) {
RCLCPP_ERROR(rclcpp::Node::get_logger(), "Failed to initialize socket can interface: %s", interface.c_str());
return false;
Expand Down Expand Up @@ -142,6 +144,7 @@ void ODriveCanNode::recv_callback(const can_frame& frame) {
case CmdId::kGetBusVoltageCurrent: {
if (!verify_length("kGetBusVoltageCurrent", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(odrv_stat_mutex_);
odrv_stat_.header.stamp = rclcpp::Clock().now();
odrv_stat_.bus_voltage = read_le<float>(frame.data + 0);
odrv_stat_.bus_current = read_le<float>(frame.data + 4);
odrv_pub_flag_ |= 0b100;
Expand Down