SMACC2
Loading...
Searching...
No Matches
cp_camera.hpp
Go to the documentation of this file.
1// Copyright 2026 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
18#include <cl_rgb/geometry.hpp>
19#include <cl_rgb/types.hpp>
20
21#include <rclcpp/rclcpp.hpp>
22#include <sensor_msgs/msg/camera_info.hpp>
23#include <sensor_msgs/msg/image.hpp>
24#include <smacc2/smacc.hpp>
25
26#include <mutex>
27#include <optional>
28#include <string>
29
30namespace cl_rgb
31{
32
34{
35 std::string name; // of the component, e.g. "cam_head"
36 std::string imageTopic; // sensor_msgs/Image, any 8 bit colour encoding
37 std::string infoTopic; // sensor_msgs/CameraInfo
38 std::string worldFrame = "world"; // frame in which rays and points are given
39};
40
41// One camera: its latest image, and how its pixels relate to the world. The pose comes from
42// the transform tree at the time of the image, so a camera on a moving arm is handled the
43// same as a fixed one. Create one named component per camera.
45{
46public:
47 explicit CpCamera(const CameraParams & params);
48 ~CpCamera() override;
49
50 void onInitialize() override;
51
52 const CameraParams & params() const { return params_; }
53
54 // the latest image; null until the first one arrives
55 FramePtr latestFrame() const;
56
57 // the camera as it was when the frame was taken; nothing while the calibration or the
58 // transform at that time is missing
59 std::optional<PinholeCamera> model(const Frame & frame) const;
60
61 // called on the executor thread with every image
63
64private:
65 void onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg);
66 void onInfo(const sensor_msgs::msg::CameraInfo::ConstSharedPtr msg);
67
70 rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr imageSubscriber_;
71 rclcpp::Subscription<sensor_msgs::msg::CameraInfo>::SharedPtr infoSubscriber_;
72
73 mutable std::mutex mutex_;
75 uint64_t sequence_ = 0;
76 bool calibrated_ = false;
77 double fx_ = 1.0, fy_ = 1.0, cx_ = 0.0, cy_ = 0.0;
78};
79
80} // namespace cl_rgb
void onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
Definition cp_camera.cpp:42
FramePtr latestFrame() const
Definition cp_camera.cpp:87
CameraParams params_
Definition cp_camera.hpp:68
CpCamera(const CameraParams &params)
Definition cp_camera.cpp:23
rclcpp::Subscription< sensor_msgs::msg::CameraInfo >::SharedPtr infoSubscriber_
Definition cp_camera.hpp:71
void onInitialize() override
Definition cp_camera.cpp:27
uint64_t sequence_
Definition cp_camera.hpp:75
std::mutex mutex_
Definition cp_camera.hpp:73
const CameraParams & params() const
Definition cp_camera.hpp:52
~CpCamera() override
Definition cp_camera.cpp:25
smacc2::SmaccSignal< void(const FramePtr &)> onFrame_
Definition cp_camera.hpp:62
rclcpp::Subscription< sensor_msgs::msg::Image >::SharedPtr imageSubscriber_
Definition cp_camera.hpp:70
void onInfo(const sensor_msgs::msg::CameraInfo::ConstSharedPtr msg)
Definition cp_camera.cpp:71
CpTransforms * transforms_
Definition cp_camera.hpp:69
std::optional< PinholeCamera > model(const Frame &frame) const
Definition cp_camera.cpp:93
std::shared_ptr< const Frame > FramePtr
Definition types.hpp:39
std::string infoTopic
Definition cp_camera.hpp:37
std::string imageTopic
Definition cp_camera.hpp:36
std::string worldFrame
Definition cp_camera.hpp:38