Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c048c5d
Publish OpenCR pins A0-A5 raw values to /analog_pins
travis-mendoza Apr 16, 2025
d040226
assign copyright of analog pins files to ROBOTIS
travis-mendoza Apr 17, 2025
79479c3
Add error messages and retry logic to check_device_status
travis-mendoza May 12, 2025
32b9853
Fix error handling for IMU calibration failures
travis-mendoza May 12, 2025
206c253
Update check_device_status declaration in header file
travis-mendoza May 12, 2025
8b6cd9e
Increase time between IMU calibration retries
travis-mendoza May 12, 2025
78ad7d0
Add moar cowbell (delay)
travis-mendoza May 12, 2025
28a48c0
Remove error handling and logging from last few commits to declutter
travis-mendoza May 12, 2025
050835f
Address launch file substitution error
travis-mendoza May 12, 2025
e3e7fe7
Sleep 5 seconds after IMU calibration for consistent bringup success
travis-mendoza May 12, 2025
227e36f
Test OpenCR heartbeat before reading device status
travis-mendoza May 14, 2025
888a3a7
Retry motor connection check if device status shows motor not connected
travis-mendoza May 15, 2025
d30d71a
Move motors warning out of for loop
travis-mendoza May 15, 2025
7f530fb
Only show motor warning when motors do not initialize
travis-mendoza May 15, 2025
046bffa
Create and check fw device_ready flag before checking device_status
travis-mendoza May 20, 2025
8cb7065
Slap on a hot messy fix to address bringup segfault
travis-mendoza May 31, 2025
f0179c8
Revert "Slap on a hot messy fix to address bringup segfault"
travis-mendoza May 31, 2025
789b9ef
Separate analog pins update rate from other sensors
travis-mendoza Jun 4, 2025
344bd83
Add pointer and timer for analog pins to header file
travis-mendoza Jun 4, 2025
98ff228
Write ez-turtlebot3 README
travis-mendoza Jun 17, 2025
b87f432
Fix rebuild instructions
travis-mendoza Jun 18, 2025
c299617
Invoke MPPI controller and SMAC Hybrid planner in nav2 burger params
travis-mendoza Jun 19, 2025
41c9ce9
add .vscode to gitignore
travis-mendoza Jul 16, 2025
ac70b2d
Add AGENT.md to work with Sourcegraph Amp
travis-mendoza Jul 16, 2025
807ee21
Comment out duplicate init_read_memory call for analog pins
travis-mendoza Jul 16, 2025
084be22
Checkout turtlebot3.cpp from 'humble' branch for baseline
travis-mendoza Jul 16, 2025
1aec572
Expand memory range in init_read_memory
travis-mendoza Jul 16, 2025
402b765
Replace analog sensors with analog pins
travis-mendoza Jul 16, 2025
898bb8f
Remove sensor_state from tb3_node CMakeLists
travis-mendoza Jul 16, 2025
0f774ae
Specify which analog pins to read
travis-mendoza Aug 25, 2025
7e6ef5c
Change variable types to make Colcon happy
travis-mendoza Aug 26, 2025
7a1a861
Provide default analog_pins parameter at declaration
travis-mendoza Aug 26, 2025
336094c
Add launch parameter to list analog pins to read
travis-mendoza Aug 26, 2025
9147c50
Make use of custom AnalogPin ROS2 msg
travis-mendoza Aug 28, 2025
3209053
Publish temperature and humidity
travis-mendoza Aug 28, 2025
0e27b02
Add debug messages for temperature and humidity
travis-mendoza Aug 28, 2025
c0fd2e8
Remove ROS info log messages used to debug temp and RH
travis-mendoza Aug 29, 2025
881f6c7
Fix copyright
travis-mendoza Aug 29, 2025
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
1 change: 1 addition & 0 deletions turtlebot3_node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_library(${PROJECT_NAME}_lib
"src/sensors/imu.cpp"
"src/sensors/joint_state.cpp"
"src/sensors/sensor_state.cpp"
"src/sensors/analog_pins.cpp"
)

set(DEPENDENCIES
Expand Down
7 changes: 7 additions & 0 deletions turtlebot3_node/include/turtlebot3_node/control_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ typedef struct

ControlItem profile_acceleration_left = {174, RAM, 4, READ_WRITE};
ControlItem profile_acceleration_right = {178, RAM, 4, READ_WRITE};

ControlItem analog_a0 = {350, RAM, 2, READ};
ControlItem analog_a1 = {352, RAM, 2, READ};
ControlItem analog_a2 = {354, RAM, 2, READ};
ControlItem analog_a3 = {356, RAM, 2, READ};
ControlItem analog_a4 = {358, RAM, 2, READ};
ControlItem analog_a5 = {360, RAM, 2, READ};
} ControlTable;

const ControlTable extern_control_table;
Expand Down
50 changes: 50 additions & 0 deletions turtlebot3_node/include/turtlebot3_node/sensors/analog_pins.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2025 ROBOTIS CO., LTD.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TURTLEBOT3_NODE__SENSORS__ANALOG_PINS_HPP_
#define TURTLEBOT3_NODE__SENSORS__ANALOG_PINS_HPP_

#include <memory>
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/u_int16_multi_array.hpp"

#include "turtlebot3_node/sensors/sensors.hpp"

namespace robotis
{
namespace turtlebot3
{
namespace sensors
{
class AnalogPins : public Sensors
{
public:
explicit AnalogPins(
std::shared_ptr<rclcpp::Node> & nh,
const std::string & topic_name);

void publish(
const rclcpp::Time & now,
std::shared_ptr<DynamixelSDKWrapper> & dxl_sdk_wrapper) override;

private:
rclcpp::Publisher<std_msgs::msg::UInt16MultiArray>::SharedPtr analog_publisher_;
};
} // namespace sensors
} // namespace turtlebot3
} // namespace robotis

#endif // TURTLEBOT3_NODE__SENSORS__ANALOG_PINS_HPP_
1 change: 1 addition & 0 deletions turtlebot3_node/include/turtlebot3_node/turtlebot3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "turtlebot3_node/devices/sound.hpp"
#include "turtlebot3_node/dynamixel_sdk_wrapper.hpp"
#include "turtlebot3_node/odometry.hpp"
#include "turtlebot3_node/sensors/analog_pins.hpp"
#include "turtlebot3_node/sensors/battery_state.hpp"
#include "turtlebot3_node/sensors/imu.hpp"
#include "turtlebot3_node/sensors/joint_state.hpp"
Expand Down
85 changes: 85 additions & 0 deletions turtlebot3_node/src/sensors/analog_pins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2025 ROBOTIS CO., LTD.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "turtlebot3_node/sensors/analog_pins.hpp"

#include <memory>
#include <string>
#include <utility>

using robotis::turtlebot3::sensors::AnalogPins;

AnalogPins::AnalogPins(
std::shared_ptr<rclcpp::Node> & nh,
const std::string & topic_name)
: Sensors(nh, "") // Call parent constructor with node handle and empty frame_id
{
auto qos = rclcpp::QoS(rclcpp::KeepLast(10));

analog_publisher_ = nh->create_publisher<std_msgs::msg::UInt16MultiArray>(topic_name, qos);

RCLCPP_INFO(nh->get_logger(), "Succeeded to create analog pins publisher");
}

void AnalogPins::publish(
const rclcpp::Time & now,
std::shared_ptr<DynamixelSDKWrapper> & dxl_sdk_wrapper)
{
(void)now; // Mark as unused intentionally to suppress warning

try {
auto analog_msg = std::make_unique<std_msgs::msg::UInt16MultiArray>();

// Set up dimensions for the message
analog_msg->layout.dim.push_back(std_msgs::msg::MultiArrayDimension());
analog_msg->layout.dim[0].label = "analog_pins";
analog_msg->layout.dim[0].size = 6;
analog_msg->layout.dim[0].stride = 6;
analog_msg->layout.data_offset = 0;

// Initialize data array to hold 6 pin values
analog_msg->data.resize(6);

// Read values from all 6 analog pins (A0-A5)
analog_msg->data[0] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a0.addr,
extern_control_table.analog_a0.length);
analog_msg->data[1] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a1.addr,
extern_control_table.analog_a1.length);
analog_msg->data[2] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a2.addr,
extern_control_table.analog_a2.length);
analog_msg->data[3] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a3.addr,
extern_control_table.analog_a3.length);
analog_msg->data[4] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a4.addr,
extern_control_table.analog_a4.length);
analog_msg->data[5] = dxl_sdk_wrapper->get_data_from_device<uint16_t>(
extern_control_table.analog_a5.addr,
extern_control_table.analog_a5.length);

// Publish the message
analog_publisher_->publish(std::move(analog_msg));
} catch (const std::exception & e) {
RCLCPP_ERROR(
rclcpp::get_logger("analog_pins"),
"Exception in analog_pins publish: %s", e.what());
} catch (...) {
RCLCPP_ERROR(
rclcpp::get_logger("analog_pins"),
"Unknown exception in analog_pins publish");
}
}
17 changes: 16 additions & 1 deletion turtlebot3_node/src/turtlebot3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void TurtleBot3::init_dynamixel_sdk_wrapper(const std::string & usb_port)
this->declare_parameter<uint8_t>("opencr.id");
this->declare_parameter<int>("opencr.baud_rate");
this->declare_parameter<float>("opencr.protocol_version");
this->declare_parameter<std::string>("namespace");

this->get_parameter_or<uint8_t>("opencr.id", opencr.id, 200);
this->get_parameter_or<int>("opencr.baud_rate", opencr.baud_rate, 1000000);
Expand All @@ -66,11 +65,19 @@ void TurtleBot3::init_dynamixel_sdk_wrapper(const std::string & usb_port)

dxl_sdk_wrapper_ = std::make_shared<DynamixelSDKWrapper>(opencr);

// Initialize the main control table range (original range)
dxl_sdk_wrapper_->init_read_memory(
extern_control_table.millis.addr,
(extern_control_table.profile_acceleration_right.addr - extern_control_table.millis.addr) +
extern_control_table.profile_acceleration_right.length
);

// Add a separate initialization for the analog pins range
dxl_sdk_wrapper_->init_read_memory(
extern_control_table.analog_a0.addr,
(extern_control_table.analog_a5.addr - extern_control_table.analog_a0.addr) +
extern_control_table.analog_a5.length
);

Choose a reason for hiding this comment

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

medium

It might be beneficial to add a check to ensure that the analog_a5.addr is actually greater than analog_a0.addr to prevent potential issues if the control table is not defined as expected. This could be done with an RCLCPP_ERROR and a return if the condition is not met.

Suggested change
// Add a separate initialization for the analog pins range
dxl_sdk_wrapper_->init_read_memory(
extern_control_table.analog_a0.addr,
(extern_control_table.analog_a5.addr - extern_control_table.analog_a0.addr) +
extern_control_table.analog_a5.length
);
if (extern_control_table.analog_a5.addr <= extern_control_table.analog_a0.addr) {
RCLCPP_ERROR(this->get_logger(), "Invalid analog pin addresses in control table");
return;
}
dxl_sdk_wrapper_->init_read_memory(
extern_control_table.analog_a0.addr,
(extern_control_table.analog_a5.addr - extern_control_table.analog_a0.addr) +
extern_control_table.analog_a5.length
);

}

void TurtleBot3::check_device_status()
Expand Down Expand Up @@ -198,6 +205,14 @@ void TurtleBot3::add_sensors()
is_connected_ir,
is_connected_sonar));

sensors_.push_back(
new sensors::AnalogPins(
node_handle_,
"analog_pins"));


RCLCPP_INFO(this->get_logger(), "Successfully added all sensors");

dxl_sdk_wrapper_->read_data_set();
sensors_.push_back(
new sensors::JointState(
Expand Down