-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect to a Specific Device using IP address as input #153
base: ros-release
Are you sure you want to change the base?
Changes from 5 commits
f73904f
20a584e
e57960f
972091c
2cfcb1e
4e9eea5
d31e32f
9d3f9d3
c0b5e95
0676041
d9b41bd
9514c6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<!-- Multiple camera args --> | ||
<arg name="enable_camera1" default="true"/> | ||
<arg name="enable_camera2" default="false"/> | ||
<arg name="useWithIP_camera1" default="false"/> | ||
<arg name="useWithIP_camera2" default="false"/> | ||
<arg name="ip_address_camera1" default=""/> | ||
<arg name="ip_address_camera2" default=""/> | ||
<arg name="useWithMxId_camera1" default="false"/> | ||
<arg name="useWithMxId_camera2" default="false"/> | ||
<arg name="mxId_camera1" default=""/> | ||
<arg name="mxId_camera2" default=""/> | ||
<arg name="tf_prefix_camera1" default="oak_front"/> | ||
<arg name="tf_prefix_camera2" default="oak_back"/> | ||
|
||
<!-- First Camera --> | ||
<include if="$(eval arg('enable_camera1') == true)" file="$(find depthai_examples)/launch/stereo_inertial_node.launch"> | ||
<arg name="tf_prefix" value="$(arg tf_prefix_camera1)" /> | ||
<arg name="useWithIP" value="$(arg useWithIP_camera1)"/> | ||
<arg name="ipAddress" value="$(arg ip_address_camera1)"/> | ||
<arg name="useWithMxId" value="$(arg useWithMxId_camera1)"/> | ||
<arg name="mxId" value="$(arg mxId_camera1)"/> | ||
</include> | ||
|
||
<!-- Second Camera --> | ||
<include if="$(eval arg('enable_camera2') == true)" file="$(find depthai_examples)/launch/stereo_inertial_node.launch"> | ||
<arg name="tf_prefix" value="$(arg tf_prefix_camera2)" /> | ||
<arg name="useWithIP" value="$(arg useWithIP_camera2)"/> | ||
<arg name="ipAddress" value="$(arg ip_address_camera2)"/> | ||
<arg name="useWithMxId" value="$(arg useWithMxId_camera2)"/> | ||
<arg name="mxId" value="$(arg mxId_camera2)"/> | ||
</include> | ||
|
||
<!-- More cameras can be added in the same fashion --> | ||
|
||
</launch> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,17 +275,20 @@ int main(int argc, char** argv) { | |
ros::init(argc, argv, "stereo_inertial_node"); | ||
ros::NodeHandle pnh("~"); | ||
|
||
std::string tfPrefix, mode, mxId, resourceBaseFolder, nnPath; | ||
std::string tfPrefix, mode, mxId, resourceBaseFolder, nnPath, ipAddress; | ||
std::string monoResolution = "720p", rgbResolution = "1080p"; | ||
int badParams = 0, stereo_fps, confidence, LRchecktresh, imuModeParam, detectionClassesCount, expTime, sensIso; | ||
int rgbScaleNumerator, rgbScaleDinominator, previewWidth, previewHeight; | ||
bool lrcheck, extended, subpixel, enableDepth, rectify, depth_aligned, manualExposure; | ||
bool enableSpatialDetection, enableDotProjector, enableFloodLight; | ||
bool usb2Mode, poeMode, syncNN; | ||
bool usb2Mode, poeMode, syncNN, useWithIP, useWithMxId; | ||
double angularVelCovariance, linearAccelCovariance; | ||
double dotProjectormA, floodLightmA; | ||
std::string nnName(BLOB_NAME); // Set your blob name for the model here | ||
|
||
badParams += !pnh.getParam("useWithIP", useWithIP); | ||
badParams += !pnh.getParam("ipAddress", ipAddress); | ||
badParams += !pnh.getParam("useWithMxId", useWithMxId); | ||
badParams += !pnh.getParam("mxId", mxId); | ||
badParams += !pnh.getParam("usb2Mode", usb2Mode); | ||
badParams += !pnh.getParam("poeMode", poeMode); | ||
|
@@ -352,7 +355,6 @@ int main(int argc, char** argv) { | |
|
||
dai::Pipeline pipeline; | ||
int width, height; | ||
bool isDeviceFound = false; | ||
std::tie(pipeline, width, height) = createPipeline(enableDepth, | ||
enableSpatialDetection, | ||
lrcheck, | ||
|
@@ -374,32 +376,57 @@ int main(int argc, char** argv) { | |
nnPath); | ||
|
||
std::shared_ptr<dai::Device> device; | ||
std::vector<dai::DeviceInfo> availableDevices = dai::Device::getAllAvailableDevices(); | ||
|
||
std::cout << "Listing available devices..." << std::endl; | ||
for(auto deviceInfo : availableDevices) { | ||
std::cout << "Device Mx ID: " << deviceInfo.getMxId() << std::endl; | ||
if(deviceInfo.getMxId() == mxId) { | ||
if(deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER) { | ||
isDeviceFound = true; | ||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
} | ||
break; | ||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("ros::NodeHandle() from Node \"" + pnh.getNamespace() + "\" DepthAI Device with MxId \"" + mxId | ||
+ "\" is already booted on different process. \""); | ||
if(useWithIP) // Connecting to a camera with specific IP, requires static IP config beforehand | ||
{ | ||
auto deviceInfo = dai::DeviceInfo(ipAddress); | ||
if(deviceInfo.state == X_LINK_ANY_STATE || deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER || deviceInfo.state == X_LINK_FLASH_BOOTED) { | ||
std::cout << "Device found with IP Address: " << ipAddress << std::endl; | ||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes a lot of sense. |
||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("ros::NodeHandle() from Node \"" + pnh.getNamespace() + "\" DepthAI Device with ipAddress \"" + ipAddress | ||
+ "\" is already booted on different process. \""); | ||
} else { | ||
throw std::runtime_error("Could NOT connect to device with IP Address: " + ipAddress); | ||
} | ||
} | ||
else if(useWithMxId) // Connecting to a camera with unique MxID | ||
{ | ||
auto deviceInfo = dai::DeviceInfo(mxId); | ||
if(deviceInfo.state == X_LINK_ANY_STATE || deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER || deviceInfo.state == X_LINK_FLASH_BOOTED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for Flashed_Boot here. it means device is running on it's own using the NOR flash config already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will test this if it works fine, then I will remove flash booted, but as far as I remember, flashed booted comes up once you update the bootloader. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thoughts ? @themarpe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samialperen Also this code isn't valid. DeviceInfo is just a hokder of information that other functions fill out. Setting mxid to constructor doesn't fill out the state or any other fields. Use Device.getX device to search for devices and return deviceinfo objects |
||
std::cout << "Connecting to device with MxID : " << mxId << std::endl; | ||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
} | ||
} else if(mxId.empty()) { | ||
isDeviceFound = true; | ||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("ros::NodeHandle() from Node \"" + pnh.getNamespace() + "\" DepthAI Device with MxId \"" + mxId | ||
+ "\" is already booted on different process. \""); | ||
} else { | ||
throw std::runtime_error("Could NOT connect to device with MxID: " + mxId); | ||
} | ||
} | ||
else if (!useWithIP && !useWithMxId) // List all available devices and connect one of them automatically | ||
{ | ||
std::vector<dai::DeviceInfo> availableDevices = dai::Device::getAllAvailableDevices(); | ||
std::cout << "Listing available devices..." << std::endl; | ||
for(auto deviceInfo : availableDevices) { | ||
std::cout << "Device Mx ID: " << deviceInfo.getMxId() << std::endl; | ||
device = std::make_shared<dai::Device>(pipeline); | ||
} | ||
if (availableDevices.empty()) | ||
{ | ||
throw std::runtime_error("Could NOT find any available device!"); | ||
} | ||
} | ||
|
||
if(!isDeviceFound) { | ||
throw std::runtime_error("ros::NodeHandle() from Node \"" + pnh.getNamespace() + "\" DepthAI Device with MxId \"" + mxId + "\" not found. \""); | ||
else | ||
{ | ||
throw std::runtime_error("You need to specify to either connect automatically (no MxId or IP Address" | ||
") or connect with IP or connect with MxId"); | ||
} | ||
|
||
if(!poeMode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,17 +274,20 @@ int main(int argc, char** argv) { | |
rclcpp::init(argc, argv); | ||
auto node = rclcpp::Node::make_shared("stereo_inertial_node"); | ||
|
||
std::string tfPrefix, mode, mxId, resourceBaseFolder, nnPath; | ||
std::string tfPrefix, mode, mxId, resourceBaseFolder, nnPath, ipAddress; | ||
std::string monoResolution = "720p", rgbResolution = "1080p"; | ||
int badParams = 0, stereo_fps, confidence, LRchecktresh, imuModeParam, detectionClassesCount, expTime, sensIso; | ||
int rgbScaleNumerator, rgbScaleDinominator, previewWidth, previewHeight; | ||
bool lrcheck, extended, subpixel, enableDepth, rectify, depth_aligned, manualExposure; | ||
bool enableSpatialDetection, enableDotProjector, enableFloodLight; | ||
bool usb2Mode, poeMode, syncNN; | ||
bool usb2Mode, poeMode, syncNN, useWithIP, useWithMxId;; | ||
double angularVelCovariance, linearAccelCovariance; | ||
double dotProjectormA, floodLightmA; | ||
std::string nnName(BLOB_NAME); // Set your blob name for the model here | ||
|
||
node->declare_parameter("useWithIP", false); | ||
node->declare_parameter("ipAddress", ""); | ||
node->declare_parameter("useWithMxId", false); | ||
node->declare_parameter("mxId", ""); | ||
node->declare_parameter("usb2Mode", false); | ||
node->declare_parameter("poeMode", false); | ||
|
@@ -329,6 +332,9 @@ int main(int argc, char** argv) { | |
|
||
// updating parameters if defined in launch file. | ||
|
||
node->get_parameter("useWithIP", useWithIP); | ||
node->get_parameter("ipAddress", ipAddress); | ||
node->get_parameter("useWithMxId", useWithMxId); | ||
node->get_parameter("mxId", mxId); | ||
node->get_parameter("usb2Mode", usb2Mode); | ||
node->get_parameter("poeMode", poeMode); | ||
|
@@ -413,32 +419,59 @@ int main(int argc, char** argv) { | |
nnPath); | ||
|
||
std::shared_ptr<dai::Device> device; | ||
std::vector<dai::DeviceInfo> availableDevices = dai::Device::getAllAvailableDevices(); | ||
|
||
std::cout << "Listing available devices..." << std::endl; | ||
for(auto deviceInfo : availableDevices) { | ||
std::cout << "Device Mx ID: " << deviceInfo.getMxId() << std::endl; | ||
if(deviceInfo.getMxId() == mxId) { | ||
if(deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER) { | ||
isDeviceFound = true; | ||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
} | ||
break; | ||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("\" DepthAI Device with MxId \"" + mxId + "\" is already booted on different process. \""); | ||
if(useWithIP) // Connecting to a camera with specific IP, requires static IP config beforehand | ||
{ | ||
auto deviceInfo = dai::DeviceInfo(ipAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will happen if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good condition to check. will test and update it. |
||
if(deviceInfo.state == X_LINK_ANY_STATE || deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER || deviceInfo.state == X_LINK_FLASH_BOOTED) { | ||
std::cout << "Device found with IP Address: " << ipAddress << std::endl; | ||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
} | ||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("DepthAI Device with ipAddress \"" + ipAddress | ||
+ "\" is already booted on different process. \""); | ||
} else { | ||
throw std::runtime_error("Could NOT connect to device with IP Address: " + ipAddress); | ||
} | ||
} | ||
else if(useWithMxId) // Connecting to a camera with unique MxID | ||
{ | ||
auto deviceInfo = dai::DeviceInfo(mxId); | ||
if(deviceInfo.state == X_LINK_ANY_STATE || deviceInfo.state == X_LINK_UNBOOTED || deviceInfo.state == X_LINK_BOOTLOADER || deviceInfo.state == X_LINK_FLASH_BOOTED) { | ||
std::cout << "Connecting to device with MxID : " << mxId << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
if(poeMode) { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo); | ||
} else { | ||
device = std::make_shared<dai::Device>(pipeline, deviceInfo, usb2Mode); | ||
} | ||
} else if(mxId == "x") { | ||
isDeviceFound = true; | ||
} else if(deviceInfo.state == X_LINK_BOOTED) { | ||
throw std::runtime_error("DepthAI Device with MxId \"" + mxId | ||
+ "\" is already booted on different process. \""); | ||
} else { | ||
throw std::runtime_error("Could NOT connect to device with MxID: " + mxId); | ||
} | ||
} | ||
else if (!useWithIP && !useWithMxId) // List all available devices and connect one of them automatically | ||
{ | ||
std::vector<dai::DeviceInfo> availableDevices = dai::Device::getAllAvailableDevices(); | ||
std::cout << "Listing available devices..." << std::endl; | ||
for(auto deviceInfo : availableDevices) { | ||
std::cout << "Device Mx ID: " << deviceInfo.getMxId() << std::endl; | ||
device = std::make_shared<dai::Device>(pipeline); | ||
} | ||
if (availableDevices.empty()) | ||
{ | ||
throw std::runtime_error("Could NOT find any available device!"); | ||
} | ||
} | ||
if(!isDeviceFound) { | ||
throw std::runtime_error("\" DepthAI Device with MxId \"" + mxId + "\" not found. \""); | ||
else | ||
{ | ||
throw std::runtime_error("You need to specify to either connect automatically (no MxId or IP Address" | ||
") or connect with IP or connect with MxId"); | ||
} | ||
|
||
if(!poeMode) { | ||
std::cout << "Device USB status: " << usbStrings[static_cast<int32_t>(device->getUsbSpeed())] << std::endl; | ||
} | ||
|
@@ -676,4 +709,4 @@ int main(int argc, char** argv) { | |
} | ||
|
||
return 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PoE device can be launched only if it is in Bootloader Mode I think. IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saching13 I tested this with POE device too and sometimes it goes to X_LINK_ANY_STATE. Also, if you update the latest bootloader, it takes FLASH_BOOTED, so to be on the safe side, I included all the conditions, but if you think some of them is not necessary, then I will remove unnecessary ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the case ? @themarpe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XLink any state would be an issue querying the information from the device. We should fix that in core. Fo you have a repro @samialperen ?
Flash booted state happens when a pipeline is flashed onto device to run standalone on boot. That is a valid case to then stop that pipeline and start a new one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@themarpe @saching13 I have OAK-D version 1, OAK-D-PRO-W POE, OAK-D-PRO USB, OAK-D-PRO-W USB. If you can share more context about what is expected from each device (or device type USB vs poe), I can test this one and share the results here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If queried you should see unbooted, bootloader, and booted if already running.
Check protocol for type of connection (usb/tcpip)