Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ ros2 run genicam_driver camera_finder
The finder prints a device identifier for each camera. Use that value as `guid` below. For
GigE Vision cameras the device IP address is also accepted.

Set `transport` to `GigEVision` or `USB3Vision` to probe a single transport. The default
`all` discovers cameras on all enabled transports. For scripts, set `output_format` to
`yaml` to write a YAML sequence to standard output, with the device ID, address, vendor,
model, serial number, and protocol for each camera. An empty discovery writes `[]`.

```bash
ros2 run genicam_driver camera_finder --ros-args -p transport:=GigEVision -p output_format:=yaml
```

### 2. Start the driver

```bash
Expand Down
2 changes: 1 addition & 1 deletion genicam_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ rclcpp_components_register_nodes(${LIBRARY_NAME} "genicam_driver::CameraDriverUv
set(CAMERA_FINDER_EXEC_NAME camera_finder)
add_executable(${CAMERA_FINDER_EXEC_NAME} src/camera_finder_main.cpp)
target_compile_definitions(${CAMERA_FINDER_EXEC_NAME} PRIVATE ${COMMON_COMPILE_DEFINITIONS})
target_link_libraries(${CAMERA_FINDER_EXEC_NAME} ${LIBRARY_NAME})
target_link_libraries(${CAMERA_FINDER_EXEC_NAME} ${LIBRARY_NAME} ${YAML_CPP_LIBRARIES})

# camera_xml_exporter node

Expand Down
130 changes: 120 additions & 10 deletions genicam_driver/src/camera_finder_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,132 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

// ROS
#include <arv.h>
#include <yaml-cpp/yaml.h>

#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>

#include <rclcpp/rclcpp.hpp>

// genicam_driver
#include "genicam_driver/camera_driver_gv.h"
#include "genicam_driver/genicam_node_base.h"

int main(int argc, char** argv)
namespace
{

bool selectTransport(const std::string& transport)
{
rclcpp::init(argc, argv);
bool available = false;
const auto interface_count = arv_get_n_interfaces();
for (unsigned int i = 0; i < interface_count; ++i)
{
const char* interface_id = arv_get_interface_id(i);
if (transport == interface_id)
{
arv_enable_interface(interface_id);
available = true;
}
else
{
arv_disable_interface(interface_id);
}
}
return available;
}

auto p_node = std::make_shared<genicam_driver::GenicamNodeBase>("camera_finder");
const char* valueOrEmpty(const char* value)
{
return value != nullptr ? value : "";
}

bool writeInventory()
{
arv_update_device_list();
const auto device_count = arv_get_n_devices();

if (p_node)
p_node->listAvailableCameraDevices();
YAML::Emitter output;
output.SetStringFormat(YAML::DoubleQuoted);
output << YAML::BeginSeq;
for (unsigned int i = 0; i < device_count; ++i)
{
output << YAML::BeginMap
<< YAML::Key << "id" << YAML::Value << valueOrEmpty(arv_get_device_id(i))
<< YAML::Key << "address" << YAML::Value << valueOrEmpty(arv_get_device_address(i))
<< YAML::Key << "vendor" << YAML::Value << valueOrEmpty(arv_get_device_vendor(i))
<< YAML::Key << "model" << YAML::Value << valueOrEmpty(arv_get_device_model(i))
<< YAML::Key << "serial_number" << YAML::Value
<< valueOrEmpty(arv_get_device_serial_nbr(i))
<< YAML::Key << "protocol" << YAML::Value << valueOrEmpty(arv_get_device_protocol(i))
<< YAML::EndMap;
}
output << YAML::EndSeq;
if (!output.good())
return false;

rclcpp::shutdown();
std::cout << output.c_str() << '\n' << std::flush;
return static_cast<bool>(std::cout);
}

int runFinder()
{
genicam_driver::GenicamNodeBase node("camera_finder");
auto logger = node.get_logger();
const auto output_format = node.declare_parameter<std::string>("output_format", "text");
const auto transport = node.declare_parameter<std::string>("transport", "all");
if (output_format != "text" && output_format != "yaml")
{
RCLCPP_ERROR(logger, "Unknown output_format '%s'. Expected text or yaml.",
output_format.c_str());
return EXIT_FAILURE;
}
if (transport != "all" && transport != "GigEVision" && transport != "USB3Vision")
{
RCLCPP_ERROR(logger, "Unknown transport '%s'. Expected all, GigEVision, or USB3Vision.",
transport.c_str());
return EXIT_FAILURE;
}
if (transport != "all" && !selectTransport(transport))
{
RCLCPP_ERROR(logger, "Aravis does not support the requested transport '%s'.",
transport.c_str());
return EXIT_FAILURE;
}
if (output_format == "text")
{
RCLCPP_DEBUG(logger, "Discovering cameras with transport '%s'.", transport.c_str());
node.listAvailableCameraDevices();
return EXIT_SUCCESS;
}

// Keep the node's shutdown log out of the YAML document.
logger.set_level(rclcpp::Logger::Level::Warn);
if (!writeInventory())
{
std::cerr << "Failed to write the YAML camera inventory.\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

} // namespace

int main(int argc, char** argv)
{
int status = EXIT_FAILURE;
try
{
rclcpp::init(argc, argv);
status = runFinder();
}
catch (const std::exception& error)
{
RCLCPP_ERROR(rclcpp::get_logger("camera_finder"), "Camera discovery failed: %s",
error.what());
}

return p_node ? EXIT_SUCCESS : EXIT_FAILURE;
if (rclcpp::ok())
rclcpp::shutdown();
return status;
}
Loading