Skip to content

Commit ea7980d

Browse files
committed
Standardized settings, add video borders and new video qos
1 parent a0494cc commit ea7980d

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

turtlebot4_vision_tutorials/turtlebot4_vision_tutorials/pose_detection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@
3030
from irobot_create_msgs.msg import LightringLeds
3131
from turtlebot4_vision_tutorials.MovenetDepthaiEdge import MovenetDepthai
3232

33+
34+
# Settings
3335
SCORE_THRESH = 0.4
3436
SMART_CROP = True
35-
FRAME_HEIGHT = 432
37+
FRAME_HEIGHT = 432 # 1080 / 2.5
38+
PUBLISH_PERIOD = 0.0833 # seconds; 12 fps
39+
3640

37-
# keys:
41+
# Semaphore Alphabet Keys:
3842
# (right, left) where each value is the angle with the horizontal
3943
# quantized into 8 regions
4044
# Human facing camera
@@ -172,8 +176,7 @@ def __init__(self):
172176
self.handle_stop_camera
173177
)
174178

175-
timer_period = 0.0833 # seconds
176-
self.timer = self.create_timer(timer_period, self.pose_detect)
179+
self.timer = self.create_timer(PUBLISH_PERIOD, self.pose_detect)
177180

178181
self.pose = MovenetDepthai(input_src='rgb',
179182
model='thunder',

turtlebot4_vision_tutorials_cpp/launch/pose_display.launch.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# @author Hilary Luo (hluo@clearpathrobotics.com)
1818

1919
from launch import LaunchDescription
20-
from launch.actions.declare_launch_argument import DeclareLaunchArgument
21-
from launch.substitutions import LaunchConfiguration
2220
from launch_ros.actions import Node
2321

2422
def generate_launch_description():

turtlebot4_vision_tutorials_cpp/src/pose_display.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@
2727
#include "sensor_msgs/msg/battery_state.hpp"
2828
#include "sensor_msgs/msg/image.hpp"
2929

30+
// Constants
3031
#define IMAGE_HEIGHT 432
3132
#define IMAGE_WIDTH 768
3233
#define TILE_X 2
3334
#define TILE_Y 3
34-
35-
#define SCORE_THRESH 0.4
3635
#define LINE_NUM 16
3736

3837
#define NODE_NAME "pose_display"
3938
#define WINDOW_NAME "Clearpath Turtlebot 4 Demo"
39+
40+
// Settings
41+
#define SCORE_THRESH 0.4
4042
#define DISPLAY_PERIOD 83 //ms; 12 fps
4143

4244
const int max_num_streams = TILE_X * TILE_Y;
@@ -57,6 +59,7 @@ void imageCallback(uint num, std::string ns, const sensor_msgs::msg::Image::Cons
5759
const int x = (num % TILE_X) * IMAGE_WIDTH;
5860
const int y = (num / TILE_X) * IMAGE_HEIGHT;
5961
frame.copyTo(full_frame(cv::Rect(x, y, IMAGE_WIDTH, IMAGE_HEIGHT)));
62+
6063
cv::putText(full_frame, ns, cv::Point(x + 50, y + 50),
6164
cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar(0, 0, 255), 2);
6265
if (batt_perc[num])
@@ -88,6 +91,9 @@ void imageCallback(uint num, std::string ns, const sensor_msgs::msg::Image::Cons
8891
}
8992
}
9093
}
94+
95+
cv::rectangle(full_frame, cv::Rect(x, y, IMAGE_WIDTH, IMAGE_HEIGHT),
96+
cv::Scalar(150, 150, 150), 2, cv::LINE_AA);
9197
}
9298
catch(const std::exception& e)
9399
{
@@ -154,12 +160,25 @@ int main(int argc, char ** argv)
154160
rclcpp::Subscription<geometry_msgs::msg::PoseArray>::SharedPtr body_sub[max_num_streams];
155161
rclcpp::Subscription<sensor_msgs::msg::BatteryState>::SharedPtr battery_sub[max_num_streams];
156162

163+
const rmw_qos_profile_t rmw_qos_profile_video =
164+
{
165+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
166+
1,
167+
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
168+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
169+
RMW_QOS_DEADLINE_DEFAULT,
170+
RMW_QOS_LIFESPAN_DEFAULT,
171+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
172+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
173+
false
174+
};
175+
157176
for (uint i=0; i < namespaces.size(); i++)
158177
{
159178
frame_sub[i] = image_transport::create_subscription(
160179
node.get(), "/"+ namespaces[i]+"/oakd/rgb/preview/encoded",
161180
[i, namespaces] (const sensor_msgs::msg::Image::ConstSharedPtr & msg) {imageCallback(i, namespaces[i], msg);},
162-
"ffmpeg", rmw_qos_profile_sensor_data);
181+
"ffmpeg", rmw_qos_profile_video);
163182

164183
body_sub[i] = node->create_subscription<geometry_msgs::msg::PoseArray>(
165184
"/"+ namespaces[i]+"/body_pose",

0 commit comments

Comments
 (0)