Skip to content

Commit

Permalink
Add a latency property to get the latency of the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
romainreignier committed Jan 4, 2018
1 parent 71bb14a commit fdc5efd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ros_lib/node_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ ros::NodeHandle::NodeHandle(uint32_t input_size, uint32_t output_size, QObject *
INPUT_SIZE(input_size),
OUTPUT_SIZE(output_size),
configured_(false),
isActive_(false)
isActive_(false),
latency_(NAN)
{
message_in.resize(INPUT_SIZE);
message_out.resize(OUTPUT_SIZE);
Expand Down Expand Up @@ -233,6 +234,8 @@ void ros::NodeHandle::requestSyncTime()

void ros::NodeHandle::syncTime(uint8_t *data)
{
uint32_t latency_ms = hardware_.time() - rt_time;

std_msgs::Time t;
uint32_t offset = hardware_.time() - rt_time;

Expand All @@ -242,6 +245,10 @@ void ros::NodeHandle::syncTime(uint8_t *data)

this->setNow(t.data);
last_sync_receive_time = hardware_.time();

// update latency property
latency_ = latency_ms/1000.;
emit latencyChanged(latency_);
}

ros::Time ros::NodeHandle::now()
Expand Down Expand Up @@ -427,11 +434,22 @@ bool ros::NodeHandle::getParam(const std::string &name, std::string *param, unsi
return false;
}

float NodeHandle::latency() const
{
return latency_;
}

void NodeHandle::setConfigured(bool isConnected)
{
if (configured_ == isConnected)
return;

configured_ = isConnected;
emit isConnectedChanged(configured_);

if(!isConnected)
{
latency_ = NAN;
emit latencyChanged(latency_);
}
}
5 changes: 5 additions & 0 deletions src/ros_lib/ros/node_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
namespace ros {

class NodeHandleBase_ : public QObject{
Q_OBJECT
public:
NodeHandleBase_(QObject *parent=0) : QObject(parent){}

Expand All @@ -72,6 +73,7 @@ class NodeHandle : public NodeHandleBase_
Q_OBJECT

Q_PROPERTY(bool isConnected READ connected NOTIFY isConnectedChanged)
Q_PROPERTY(float latency READ latency NOTIFY latencyChanged)

protected:
RosQtSocket hardware_;
Expand Down Expand Up @@ -115,6 +117,7 @@ class NodeHandle : public NodeHandleBase_

bool configured_;
bool isActive_; // true if we should try to connect
float latency_;

/* used for syncing the time */
uint32_t last_sync_time;
Expand Down Expand Up @@ -228,9 +231,11 @@ private slots:
bool getParam(const std::string &name, float* param, unsigned int length=1, int timeout = 1000);
bool getParam(const std::string &name, std::string *param, unsigned int length=1, int timeout = 1000);
bool isConnected() const;
float latency() const;

signals:
void isConnectedChanged(bool isConnected);
void latencyChanged(float latency);
};

}
Expand Down

0 comments on commit fdc5efd

Please sign in to comment.