Skip to content

Commit 6e1af60

Browse files
author
alireza@general
committed
feat: auto-unsubscribtion to the vga stream
1 parent d05885a commit 6e1af60

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

include/dji_osdk_ros_obsoleted/dji_sdk/dji_sdk_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ class DJISDKNode
299299
#endif
300300

301301
private:
302+
303+
#ifdef ADVANCED_SENSING
304+
int latest_camera_ = {-1};
305+
#endif
306+
302307
//! OSDK core
303308
Vehicle* vehicle;
304309
LinuxSetup* linuxEnvironment;

src/dji_osdk_ros_obsoleted/modules/dji_sdk_node.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ DJISDKNode::~DJISDKNode()
7777
{
7878
cleanUpSubscribeFromFC();
7979
}
80+
81+
#ifdef ADVANCED_SENSING
82+
if(latest_camera_ > 0)
83+
{
84+
vehicle->advancedSensing->unsubscribeVGAImages(latest_camera_);
85+
ROS_INFO("Unsubscribed from the VGA Stream");
86+
}
87+
#endif
88+
8089
if (vehicle)
8190
{
8291
delete vehicle;

src/dji_osdk_ros_obsoleted/modules/dji_sdk_node_publisher.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ DJISDKNode::publish5HzData(Vehicle *vehicle, RecvContainer recvFrame,
241241

242242
//TODO: publish gps detail data if needed
243243
Telemetry::TypeMap<Telemetry::TOPIC_BATTERY_INFO>::type battery_info=
244-
vehicle->subscribe->getValue<Tele/points2metry::TOPIC_BATTERY_INFO>();
244+
vehicle->subscribe->getValue<Telemetry::TOPIC_BATTERY_INFO>();
245245
sensor_msgs::BatteryState msg_battery_state;
246246
msg_battery_state.header.stamp = msg_time;
247247
msg_battery_state.capacity = battery_info.capacity;
@@ -279,7 +279,7 @@ DJISDKNode::publish5HzData(Vehicle *vehicle, RecvContainer recvFrame,
279279
sensor_msgs::NavSatFix rtk_position;
280280
rtk_position.header.stamp = msg_time;
281281
rtk_position.latitude = rtk_telemetry_position.latitude;
282-
rtk_position.longitude = rtk_telem/points2etry_position.longitude;
282+
rtk_position.longitude = rtk_telemetry_position.longitude;
283283
rtk_position.altitude = rtk_telemetry_position.HFSL;
284284
p->rtk_position_publisher.publish(rtk_position);
285285

@@ -396,7 +396,6 @@ DJISDKNode::publish50HzData(Vehicle* vehicle, RecvContainer recvFrame,
396396
std_msgs::Float32 height;
397397
height.data = fused_height;
398398
p->height_publisher.publish(height);
399-
/points2
400399
Telemetry::TypeMap<Telemetry::TOPIC_STATUS_FLIGHT>::type fs =
401400
vehicle->subscribe->getValue<Telemetry::TOPIC_STATUS_FLIGHT>();
402401

@@ -433,7 +432,7 @@ DJISDKNode::publish50HzData(Vehicle* vehicle, RecvContainer recvFrame,
433432

434433
geometry_msgs::Vector3Stamped gimbal_angle_vec3;
435434

436-
gimbal_angle_vec3.header.stamp = ros::Time::now()/points2;
435+
gimbal_angle_vec3.header.stamp = ros::Time::now();
437436
gimbal_angle_vec3.vector.x = gimbal_angle.x;
438437
gimbal_angle_vec3.vector.y = gimbal_angle.y;
439438
gimbal_angle_vec3.vector.z = gimbal_angle.z;

src/dji_osdk_ros_obsoleted/modules/dji_sdk_node_services.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ DJISDKNode::stereoDepthSubscriptionCallback(dji_osdk_ros::StereoDepthSubscriptio
394394
return true;
395395
}
396396

397+
398+
397399
bool
398400
DJISDKNode::stereoVGASubscriptionCallback(dji_osdk_ros::StereoVGASubscription::Request& request,
399401
dji_osdk_ros::StereoVGASubscription::Response& response)
@@ -402,9 +404,10 @@ DJISDKNode::stereoVGASubscriptionCallback(dji_osdk_ros::StereoVGASubscription::R
402404

403405
if (request.unsubscribe_vga == 1)
404406
{
405-
vehicle->advancedSensing->unsubscribeVGAImages();
407+
vehicle->advancedSensing->unsubscribeVGAImages(request.front_vga);
406408
response.result = true;
407409
ROS_INFO("unsubscribe stereo vga images");
410+
latest_camera_ = -1;
408411
return true;
409412
}
410413

@@ -415,17 +418,37 @@ DJISDKNode::stereoVGASubscriptionCallback(dji_osdk_ros::StereoVGASubscription::R
415418
response.result = false;
416419
return true;
417420
}
418-
419-
if (request.front_vga == 1)
420-
{
421+
422+
423+
/* In this version of the function, request.front_vga represent the side of the camera according to the followings
424+
* 1 ---------------------> front
425+
* 2 ---------------------> left
426+
* 3 ---------------------> right
427+
* 4 ---------------------> rear
428+
* 5 ---------------------> down
429+
* 6 ---------------------> top
430+
*/
431+
if (request.front_vga > 0 && request.front_vga <= 6)
432+
{
433+
//un-subscribe from the previous stream first
434+
if(request.front_vga != latest_camera_ && latest_camera_ > 0)
435+
{
436+
vehicle->advancedSensing->unsubscribeVGAImages(latest_camera_);
437+
ROS_INFO("unsubscribe stereo vga images");
438+
latest_camera_ = -1;
439+
ros::Duration(1).sleep();
440+
}
441+
421442
this->stereo_vga_subscription_success = false;
422-
vehicle->advancedSensing->subscribeFrontStereoVGA(request.vga_freq, &publishVGAStereoImage, this);
443+
vehicle->advancedSensing->subscribeFrontStereoVGA(request.vga_freq, request.front_vga, &publishVGAStereoImage, this);
423444
ros::Duration(1).sleep();
424445
}
425446

426447
if (this->stereo_vga_subscription_success == true)
427448
{
428449
response.result = true;
450+
//if the service call returns success, only then update the buffer
451+
latest_camera_ = request.front_vga;
429452
}
430453
else
431454
{

0 commit comments

Comments
 (0)