4#ifndef PLAYBACK_PANEL_HPP_
5#define PLAYBACK_PANEL_HPP_
21#include "rclcpp/rclcpp.hpp"
22#include "rviz_common/panel.hpp"
24#include "autonomy_datasets_msgs/srv/request_samples.hpp"
79 void load(
const rviz_common::Config& config)
override;
86 void save(rviz_common::Config config)
const override;
145 void applyRequestResult(
const QString& position,
const QString& status,
bool success);
154 bool eventFilter(QObject* watched, QEvent* event)
override;
184 static void showElided(QLabel* label,
const QString& text);
199 void sendRequest(uint8_t mode, uint64_t num_samples,
const std::vector<uint64_t>& sample_ids,
const QString& pending_status);
220 static QString
describePosition(
const autonomy_datasets_msgs::srv::RequestSamples::Response& response);
246 rclcpp::Client<autonomy_datasets_msgs::srv::RequestSamples>::SharedPtr
client_;
void onServiceNameChanged()
Re-creates the service client after the service name has been edited.
rclcpp::Node::SharedPtr node_
ROS node of RViz, which its executor spins.
void onStepClicked()
Requests the next samples, which advances the playback by the configured step size.
QPushButton * play_button_
Runs the playback to the end of the dataset.
QString status_text_
Full text reported by status_label_, of which only what fits is shown.
QString position_text_
Full text reported by position_label_, of which only what fits is shown.
QPushButton * step_button_
Advances the playback by the configured step size.
void showStatus(const QString &text)
Reports what the panel is waiting for or what a request resulted in.
QPushButton * skip_button_
Skips the playback ahead to the entered sample IDs.
static QString describePosition(const autonomy_datasets_msgs::srv::RequestSamples::Response &response)
Describes the sample a response reports as published last.
void save(rviz_common::Config config) const override
Stores the service name and step size in the RViz configuration.
void onSkipClicked()
Requests the entered sample IDs, which skips the playback ahead to them.
QLabel * position_label_
Sample the dataset node published last.
~PlaybackPanel() override
Destroys the panel, dropping the service client before the RViz node goes away.
void onInitialize() override
Picks up the ROS node of RViz and creates the client for the configured service.
void updateAvailability()
Tracks whether the service is available and reflects it in the panel.
QLineEdit * sample_ids_edit_
Sample IDs to skip ahead to.
PlaybackPanel & operator=(const PlaybackPanel &)=delete
Copy assignment is disabled because the panel owns Qt and ROS resources.
void onPauseClicked()
Requests no sample at all, which stops the playback at the current sample.
bool service_available_
Whether the service was available the last time it was polled.
bool eventFilter(QObject *watched, QEvent *event) override
Re-shortens the reported texts whenever one of the labels showing them is resized.
static void showElided(QLabel *label, const QString &text)
Shows as much of a text as fits into a label and offers all of it as its tooltip.
PlaybackPanel & operator=(PlaybackPanel &&)=delete
Move assignment is disabled because RViz owns the panel lifecycle.
void setupUi()
Creates the widgets of the panel and connects them to their handlers.
rclcpp::Client< autonomy_datasets_msgs::srv::RequestSamples >::SharedPtr client_
Client of the request_samples service of the dataset node.
PlaybackPanel(const PlaybackPanel &)=delete
Copy construction is disabled because the panel owns Qt and ROS resources.
void onPlayClicked()
Requests all remaining samples, which runs the playback to the end of the dataset.
std::vector< uint64_t > parseSampleIds(QString *error) const
Reads the sample IDs entered in the panel.
void requestFinished(const QString &position, const QString &status, bool success)
Reports the outcome of a sample request from the thread that received the response.
void load(const rviz_common::Config &config) override
Restores the service name and step size stored in the RViz configuration.
bool request_in_flight_
Whether a request has been sent whose response has not arrived yet.
QPushButton * pause_button_
Stops the playback at the current sample.
void applyRequestResult(const QString &position, const QString &status, bool success)
Shows the outcome of a sample request and re-enables the controls.
PlaybackPanel(QWidget *parent=nullptr)
Creates the panel and its widgets, without connecting to a service yet.
QLineEdit * service_name_edit_
Name of the request_samples service of the dataset node to control.
void updateControlState()
Enables the controls that may be used while no request is being processed.
PlaybackPanel(PlaybackPanel &&)=delete
Move construction is disabled because RViz owns the panel lifecycle.
QTimer * availability_timer_
Polls whether the service is available, as the panel cannot be notified about it.
void sendRequest(uint8_t mode, uint64_t num_samples, const std::vector< uint64_t > &sample_ids, const QString &pending_status)
Sends a sample request and reports its response through requestFinished().
void createClient()
Creates the service client for the service name currently entered in the panel.
void showPosition(const QString &text)
Reports which sample the dataset node published last.
QSpinBox * step_size_spin_
Number of samples a step advances the playback by.
QLabel * status_label_
Outcome of the last request, or why no request can be sent.