Skip to content

Commit 85bbc53

Browse files
Simplified CMakeLists.txt, added velocity timeout back, added timer for update method.
1 parent 3014cb3 commit 85bbc53

File tree

5 files changed

+40
-52
lines changed

5 files changed

+40
-52
lines changed

interbotix_ros_slate/interbotix_slate_driver/CMakeLists.txt

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ find_package(tf2_geometry_msgs REQUIRED)
2323
find_package(tf2_ros REQUIRED)
2424
find_package(trossen_slate REQUIRED)
2525

26-
include_directories(include ${trossen_slate_INCLUDE_DIRS})
26+
include_directories(include)
2727

2828
set(ROS_DEPENDENCIES
2929
geometry_msgs
@@ -38,46 +38,16 @@ set(ROS_DEPENDENCIES
3838
trossen_slate
3939
)
4040

41-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
42-
set(ARCH "x86_64")
43-
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
44-
set(ARCH "aarch64")
45-
else()
46-
message(FATAL_ERROR "Unknown System Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
47-
endif()
48-
49-
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/${ARCH})
50-
51-
add_library(slate_base
52-
src/slate_base.cpp
53-
)
54-
55-
ament_target_dependencies(slate_base ${ROS_DEPENDENCIES})
56-
57-
target_link_libraries(slate_base
58-
${trossen_slate_LIBRARIES}
59-
)
60-
6141
add_executable(slate_base_node
6242
src/slate_base_node.cpp
43+
src/slate_base.cpp
6344
)
6445

65-
target_link_libraries(slate_base_node
66-
slate_base
67-
)
68-
69-
install(
70-
TARGETS slate_base
71-
ARCHIVE DESTINATION lib
72-
LIBRARY DESTINATION lib
73-
RUNTIME DESTINATION bin
74-
)
46+
ament_target_dependencies(slate_base_node ${ROS_DEPENDENCIES})
7547

7648
install(
77-
TARGETS
78-
slate_base_node
79-
RUNTIME DESTINATION
80-
lib/${PROJECT_NAME}
49+
TARGETS slate_base_node
50+
DESTINATION lib/${PROJECT_NAME}
8151
)
8252

8353
if(BUILD_TESTING)

interbotix_ros_slate/interbotix_slate_driver/include/interbotix_slate_driver/slate_base.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class SlateBase
7676
void update();
7777

7878
private:
79-
// Update counter used to only update some values less frequently
79+
// Update counter used to update the battery status less frequently
8080
int cnt_;
8181

8282
// Array containing x and y translation in meters and rotation in radians
@@ -94,7 +94,7 @@ class SlateBase
9494
// Base command bytes containing data about charging and motor torque enabling
9595
uint32_t sys_cmd_ = 0;
9696

97-
// Stored data of the SLATE base
97+
// Stored data of the base
9898
base_driver::ChassisData data_;
9999

100100
// Name of odom frame
@@ -127,9 +127,18 @@ class SlateBase
127127
// Set light state service server
128128
rclcpp::Service<SetLightState>::SharedPtr srv_set_light_state_;
129129

130+
// Timer used to update the base state
131+
rclcpp::TimerBase::SharedPtr timer_;
132+
130133
// If publish_tf_ is true, this is the broadcaster used to publish the odom->base_link TF
131134
tf2_ros::TransformBroadcaster tf_broadcaster_odom_;
132135

136+
// Timeout for base velocity
137+
rclcpp::Duration cmd_vel_timeout_;
138+
139+
// Time last velocity command was received
140+
rclcpp::Time cmd_vel_time_last_update_;
141+
133142
/**
134143
* @brief Process incoming Twist command message
135144
* @param msg Incoming Twist command message
@@ -192,6 +201,6 @@ class SlateBase
192201
float wrap_angle(float angle);
193202
};
194203

195-
} // namespace slate_base
204+
} // namespace slate_base
196205

197-
#endif // INTERBOTIX_SLATE_DRIVER__SLATE_BASE_HPP_
206+
#endif // INTERBOTIX_SLATE_DRIVER__SLATE_BASE_HPP_

interbotix_ros_slate/interbotix_slate_driver/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>interbotix_slate_driver</name>
5-
<version>1.0.0</version>
5+
<version>0.0.0</version>
66
<description>The interbotix_slate_driver package</description>
77

88
<maintainer email="trsupport@trossenrobotics.com">Trossen Robotics</maintainer>

interbotix_ros_slate/interbotix_slate_driver/src/slate_base.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ namespace slate_base
3535
{
3636

3737
SlateBase::SlateBase(const rclcpp::NodeOptions & options)
38-
: trossen_slate::TrossenSlate(), rclcpp::Node("slate_base", options), sys_cmd_{0},
39-
publish_tf_(false), current_time_(get_clock()->now()), tf_broadcaster_odom_(this)
38+
: trossen_slate::TrossenSlate(), rclcpp::Node("slate_base", options), cnt_(0), pose_{0},
39+
publish_tf_(false), is_first_odom_(0), current_time_(get_clock()->now()), tf_broadcaster_odom_(
40+
this), cmd_vel_time_last_update_(get_clock()->now()),
41+
cmd_vel_timeout_(rclcpp::Duration(std::chrono::milliseconds(CMD_TIME_OUT)))
4042
{
4143
using std::placeholders::_1, std::placeholders::_2, std::placeholders::_3;
4244

@@ -72,6 +74,8 @@ SlateBase::SlateBase(const rclcpp::NodeOptions & options)
7274
"set_light_state",
7375
std::bind(&SlateBase::set_light_state_callback, this, _1, _2, _3));
7476

77+
timer_ = create_wall_timer(std::chrono::milliseconds(50), std::bind(&SlateBase::update, this));
78+
7579
std::string result;
7680
if (!init_base(result)) {
7781
RCLCPP_FATAL(get_logger(), result.c_str());
@@ -84,9 +88,14 @@ SlateBase::SlateBase(const rclcpp::NodeOptions & options)
8488

8589
void SlateBase::update()
8690
{
87-
rclcpp::spin_some(get_node_base_interface());
8891
current_time_ = get_clock()->now();
8992

93+
// Time out velocity commands
94+
if (current_time_ - cmd_vel_time_last_update_ > cmd_vel_timeout_) {
95+
data_.cmd_vel_x = 0.0f;
96+
data_.cmd_vel_z = 0.0f;
97+
}
98+
9099
if (!base_driver::updateChassisInfo(&data_)) {
91100
return;
92101
}
@@ -97,9 +106,12 @@ void SlateBase::update()
97106
if (cnt_ % 10 == 0) {
98107
battery_state.header.stamp = current_time_;
99108
battery_state.voltage = data_.voltage;
109+
battery_state.temperature = std::numeric_limits<double>::quiet_NaN();
100110
battery_state.current = data_.current;
111+
battery_state.charge = std::numeric_limits<double>::quiet_NaN();
112+
battery_state.capacity = std::numeric_limits<double>::quiet_NaN();
113+
battery_state.design_capacity = std::numeric_limits<double>::quiet_NaN();
101114
battery_state.percentage = data_.charge;
102-
battery_state.power_supply_status = data_.system_state;
103115
pub_battery_state_->publish(battery_state);
104116
}
105117

@@ -157,6 +169,7 @@ void SlateBase::cmd_vel_callback(const Twist::SharedPtr msg)
157169
{
158170
data_.cmd_vel_x = msg->linear.x;
159171
data_.cmd_vel_z = msg->linear.z;
172+
cmd_vel_time_last_update_ = get_clock()->now();
160173
}
161174

162175
bool SlateBase::set_text_callback(
@@ -220,4 +233,4 @@ float SlateBase::wrap_angle(float angle)
220233
return angle;
221234
}
222235

223-
} // namespace slate_base
236+
} // namespace slate_base

interbotix_ros_slate/interbotix_slate_driver/src/slate_base_node.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ int main(int argc, char ** argv)
3434
{
3535
rclcpp::init(argc, argv);
3636
auto node = std::make_shared<slate_base::SlateBase>();
37-
38-
auto r = rclcpp::Rate(20);
39-
40-
while (rclcpp::ok()) {
41-
node->update();
42-
r.sleep();
43-
}
37+
rclcpp::spin(node);
38+
rclcpp::shutdown();
39+
return 0;
4440
}

0 commit comments

Comments
 (0)