Skip to content

Commit

Permalink
V280_noetic (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serafadam authored Sep 7, 2023
1 parent 1454cb6 commit bf7b03a
Show file tree
Hide file tree
Showing 74 changed files with 2,419 additions and 1,072 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X1
Will only start `stereo_inertial_node` launch file (you can try different commands).
### Running docker image on ROS2
``` bash
docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix depthai_ros roslaunch depthai_examples stereo_inertial_node.launch.py
docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix depthai_ros ros2 launch depthai_examples stereo_inertial_node.launch.py
```


Expand Down
7 changes: 6 additions & 1 deletion depthai_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ find_package(catkin REQUIRED COMPONENTS
stereo_msgs
std_msgs
vision_msgs
tf2_ros
urdf
robot_state_publisher
)
find_package(Boost REQUIRED)
find_package(depthai CONFIG REQUIRED)
Expand All @@ -48,12 +51,14 @@ FILE(GLOB LIB_SRC
"src/ImgDetectionConverter.cpp"
"src/SpatialDetectionConverter.cpp"
"src/ImuConverter.cpp"
"src/TFPublisher.cpp"
"src/TrackedFeaturesConverter.cpp"
)

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS depthai_ros_msgs camera_info_manager roscpp sensor_msgs std_msgs vision_msgs image_transport cv_bridge stereo_msgs
CATKIN_DEPENDS depthai_ros_msgs camera_info_manager roscpp sensor_msgs std_msgs vision_msgs image_transport cv_bridge stereo_msgs tf2_ros urdf robot_state_publisher
)

list(APPEND DEPENDENCY_PUBLIC_LIBRARIES ${catkin_LIBRARIES})
Expand Down
21 changes: 14 additions & 7 deletions depthai_bridge/include/depthai_bridge/BridgePublisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ class BridgePublisher {
ConvertFunc converter,
int queueSize,
std::string cameraParamUri = "",
std::string cameraName = "");
std::string cameraName = "",
bool lazyPublisher = true);

BridgePublisher(std::shared_ptr<dai::DataOutputQueue> daiMessageQueue,
rosOrigin::NodeHandle nh,
std::string rosTopic,
ConvertFunc converter,
int queueSize,
ImageMsgs::CameraInfo cameraInfoData,
std::string cameraName);
std::string cameraName,
bool lazyPublisher = true);

/**
* Tag Dispacher function to to overload the Publisher to ImageTransport Publisher
Expand Down Expand Up @@ -90,6 +92,7 @@ class BridgePublisher {
std::unique_ptr<camera_info_manager::CameraInfoManager> _camInfoManager;
bool _isCallbackAdded = false;
bool _isImageMessage = false; // used to enable camera info manager
bool _lazyPublisher = true;
};

template <class RosMsg, class SimMsg>
Expand All @@ -102,14 +105,16 @@ BridgePublisher<RosMsg, SimMsg>::BridgePublisher(std::shared_ptr<dai::DataOutput
ConvertFunc converter,
int queueSize,
std::string cameraParamUri,
std::string cameraName)
std::string cameraName,
bool lazyPublisher)
: _daiMessageQueue(daiMessageQueue),
_converter(converter),
_nh(nh),
_it(_nh),
_rosTopic(rosTopic),
_cameraParamUri(cameraParamUri),
_cameraName(cameraName) {
_cameraName(cameraName),
_lazyPublisher(lazyPublisher) {
// ROS_DEBUG_STREAM_NAMED(LOG_TAG, "Publisher Type : " << typeid(CustomPublisher).name());
_rosPublisher = advertise(queueSize, std::is_same<RosMsg, ImageMsgs::Image>{});
}
Expand All @@ -121,14 +126,16 @@ BridgePublisher<RosMsg, SimMsg>::BridgePublisher(std::shared_ptr<dai::DataOutput
ConvertFunc converter,
int queueSize,
ImageMsgs::CameraInfo cameraInfoData,
std::string cameraName)
std::string cameraName,
bool lazyPublisher)
: _daiMessageQueue(daiMessageQueue),
_nh(nh),
_converter(converter),
_it(_nh),
_cameraInfoData(cameraInfoData),
_rosTopic(rosTopic),
_cameraName(cameraName) {
_cameraName(cameraName),
_lazyPublisher(lazyPublisher) {
// ROS_DEBUG_STREAM_NAMED(LOG_TAG, "Publisher Type : " << typeid(CustomPublisher).name());
_rosPublisher = advertise(queueSize, std::is_same<RosMsg, ImageMsgs::Image>{});
}
Expand Down Expand Up @@ -219,7 +226,7 @@ void BridgePublisher<RosMsg, SimMsg>::publishHelper(std::shared_ptr<SimMsg> inDa
}
mainSubCount = _rosPublisher->getNumSubscribers();

if(mainSubCount > 0 || infoSubCount > 0) {
if(!_lazyPublisher || (mainSubCount > 0 || infoSubCount > 0)) {
_converter(inDataPtr, opMsgs);

while(opMsgs.size()) {
Expand Down
15 changes: 11 additions & 4 deletions depthai_bridge/include/depthai_bridge/ImageConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ class ImageConverter {
_updateRosBaseTimeOnToRosMsg = update;
}

void toRosMsgFromBitStream(std::shared_ptr<dai::ImgFrame> inData,
std::deque<ImageMsgs::Image>& outImageMsgs,
dai::RawImgFrame::Type type,
const sensor_msgs::CameraInfo& info);
void convertFromBitstream(dai::RawImgFrame::Type srcType);

void addExposureOffset(dai::CameraExposureOffset& offset);
void convertDispToDepth();

ImageMsgs::Image toRosMsgRawPtr(std::shared_ptr<dai::ImgFrame> inData, const sensor_msgs::CameraInfo& info = sensor_msgs::CameraInfo());
void toRosMsg(std::shared_ptr<dai::ImgFrame> inData, std::deque<ImageMsgs::Image>& outImageMsgs);
ImagePtr toRosMsgPtr(std::shared_ptr<dai::ImgFrame> inData);

Expand Down Expand Up @@ -86,6 +88,11 @@ class ImageConverter {
int64_t _totalNsChange{0};
// Whether to update the ROS base time on each message conversion
bool _updateRosBaseTimeOnToRosMsg{false};
dai::RawImgFrame::Type _srcType;
bool _fromBitstream = false;
bool _convertDispToDepth = false;
bool _addExpOffset = false;
dai::CameraExposureOffset _expOffset;
};

} // namespace ros
Expand Down
86 changes: 86 additions & 0 deletions depthai_bridge/include/depthai_bridge/TFPublisher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once
#include "depthai-shared/common/CameraFeatures.hpp"
#include "depthai/device/CalibrationHandler.hpp"
#include "geometry_msgs/Quaternion.h"
#include "geometry_msgs/TransformStamped.h"
#include "nlohmann/json.hpp"
#include "robot_state_publisher/robot_state_publisher.h"
#include "ros/node_handle.h"
#include "tf2_ros/static_transform_broadcaster.h"

namespace dai {
namespace ros {
class TFPublisher {
public:
explicit TFPublisher(::ros::NodeHandle node,
const dai::CalibrationHandler& calHandler,
const std::vector<dai::CameraFeatures>& camFeatures,
const std::string& camName,
const std::string& camModel,
const std::string& baseFrame,
const std::string& parentFrame,
const std::string& camPosX,
const std::string& camPosY,
const std::string& camPosZ,
const std::string& camRoll,
const std::string& camPitch,
const std::string& camYaw,
const std::string& imuFromDescr,
const std::string& customURDFLocation,
const std::string& customXacroArgs);
/*
* @brief Obtain URDF description by running Xacro with provided arguments.
*/
std::string getURDF();
geometry_msgs::Quaternion quatFromRotM(nlohmann::json rotMatrix);
geometry_msgs::Vector3 transFromExtr(nlohmann::json translation);

private:
/*
* @brief Converts model name to one of the available model families
*/
void convertModelName();
/*
* @brief Prepare arguments for xacro command. If custom URDF location is not provided, check if model name is available in depthai_descriptions package.
*/
std::string prepareXacroArgs();
/*
* @brief Get URDF description and set it as a parameter for robot_state_publisher
*/
void publishDescription(::ros::NodeHandle node);
/*
* @brief Publish camera transforms ("standard" and optical) based on calibration data.
* Frame names are based on socket names and use following convention: [base_frame]_[socket_name]_camera_frame and
* [base_frame]_[socket_name]_camera_optical_frame
*/
void publishCamTransforms(nlohmann::json camData, ::ros::NodeHandle node);
/*
* @brief Publish IMU transform based on calibration data.
* Frame name is based on IMU name and uses following convention: [base_frame]_imu_frame.
* If IMU extrinsics are not set, warning is printed out and imu frame is published with zero translation and rotation.
*/
void publishImuTransform(nlohmann::json json, ::ros::NodeHandle node);
/*
* @brief Check if model STL file is available in depthai_descriptions package.
*/
bool modelNameAvailable();
std::string getCamSocketName(int socketNum);
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> _tfPub;
std::shared_ptr<robot_state_publisher::RobotStatePublisher> _rsp;
std::string _camName;
std::string _camModel;
std::string _baseFrame;
std::string _parentFrame;
std::string _camPosX;
std::string _camPosY;
std::string _camPosZ;
std::string _camRoll;
std::string _camPitch;
std::string _camYaw;
std::string _imuFromDescr;
std::string _customURDFLocation;
std::string _customXacroArgs;
std::vector<dai::CameraFeatures> _camFeatures;
};
} // namespace ros
} // namespace dai
56 changes: 56 additions & 0 deletions depthai_bridge/include/depthai_bridge/TrackedFeaturesConverter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

#include <depthai_ros_msgs/TrackedFeatures.h>

#include <deque>
#include <memory>
#include <string>

#include "depthai/pipeline/datatype/TrackedFeatures.hpp"
#include "ros/time.h"

namespace dai {

namespace ros {

class TrackedFeaturesConverter {
public:
// DetectionConverter() = default;
TrackedFeaturesConverter(std::string frameName, bool getBaseDeviceTimestamp = false);
~TrackedFeaturesConverter();

/**
* @brief Handles cases in which the ROS time shifts forward or backward
* Should be called at regular intervals or on-change of ROS time, depending
* on monitoring.
*
*/
void updateRosBaseTime();

/**
* @brief Commands the converter to automatically update the ROS base time on message conversion based on variable
*
* @param update: bool whether to automatically update the ROS base time on message conversion
*/
void setUpdateRosBaseTimeOnToRosMsg(bool update = true) {
_updateRosBaseTimeOnToRosMsg = update;
}

void toRosMsg(std::shared_ptr<dai::TrackedFeatures> inFeatures, std::deque<depthai_ros_msgs::TrackedFeatures>& featureMsgs);

private:
const std::string _frameName;
std::chrono::time_point<std::chrono::steady_clock> _steadyBaseTime;
::ros::Time _rosBaseTime;
bool _getBaseDeviceTimestamp;
// For handling ROS time shifts and debugging
int64_t _totalNsChange{0};
// Whether to update the ROS base time on each message conversion
bool _updateRosBaseTimeOnToRosMsg{false};
};

} // namespace ros

namespace rosBridge = ros;

} // namespace dai
3 changes: 3 additions & 0 deletions depthai_bridge/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<depend>std_msgs</depend>
<depend>stereo_msgs</depend>
<depend>vision_msgs</depend>
<depend>tf2_ros</depend>
<depend>urdf</depend>
<depend>robot_state_publisher</depend>

<export>
<build_type>catkin</build_type>
Expand Down
Loading

0 comments on commit bf7b03a

Please sign in to comment.