Skip to content

Commit f4bad50

Browse files
authored
Merge pull request #36 from ori-drs/topic/add-extended-joint-state
Add joint state with acceleration fields
2 parents 705532a + 827c368 commit f4bad50

File tree

10 files changed

+140
-1
lines changed

10 files changed

+140
-1
lines changed

pronto_msgs/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ add_message_files(FILES VisualOdometryUpdate.msg
88
GPSData.msg
99
IndexedMeasurement.msg
1010
QuadrupedStance.msg
11-
LidarOdometryUpdate.msg
11+
JointStateWithAcceleration.msg
12+
LidarOdometryUpdate.msg
1213
ControllerFootContact.msg
1314
BipedForceTorqueSensors.msg
1415
QuadrupedForceTorqueSensors.msg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is a message that holds data to describe the state of a set of torque controlled joints.
2+
#
3+
# The state of each joint (revolute or prismatic) is defined by:
4+
# * the position of the joint (rad or m),
5+
# * the velocity of the joint (rad/s or m/s),
6+
# * the acceleration of the joint (rad/s^2 or m/s^2), and
7+
# * the effort that is applied in the joint (Nm or N).
8+
#
9+
# Each joint is uniquely identified by its name
10+
# The header specifies the time at which the joint states were recorded. All the joint states
11+
# in one message have to be recorded at the same time.
12+
#
13+
# This message consists of a multiple arrays, one for each part of the joint state.
14+
# The goal is to make each of the fields optional. When e.g. your joints have no
15+
# effort associated with them, you can leave the effort array empty.
16+
#
17+
# All arrays in this message should have the same size, or be empty.
18+
# This is the only way to uniquely associate the joint name with the correct
19+
# states.
20+
21+
22+
Header header
23+
24+
string[] name
25+
float64[] position
26+
float64[] velocity
27+
float64[] acceleration
28+
float64[] effort

pronto_quadruped_ros/include/pronto_quadruped_ros/bias_lock_handler_ros.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <visualization_msgs/MarkerArray.h>
3434
#include <eigen_conversions/eigen_msg.h>
3535
#include <geometry_msgs/PointStamped.h>
36+
#include <pronto_msgs/JointStateWithAcceleration.h>
3637

3738
#include <tf2_ros/transform_listener.h>
3839
#include <tf2_ros/transform_broadcaster.h>
@@ -256,5 +257,14 @@ class ImuBiasLockROS : public ImuBiasLockBaseROS<sensor_msgs::JointState>
256257
void processSecondaryMessage(const sensor_msgs::JointState& msg) override;
257258
};
258259

260+
class ImuBiasLockWithAccelerationROS : public ImuBiasLockBaseROS<pronto_msgs::JointStateWithAcceleration>
261+
{
262+
public:
263+
ImuBiasLockWithAccelerationROS(ros::NodeHandle& nh) : ImuBiasLockBaseROS<pronto_msgs::JointStateWithAcceleration>(nh) {}
264+
virtual ~ImuBiasLockWithAccelerationROS() = default;
265+
266+
void processSecondaryMessage(const pronto_msgs::JointStateWithAcceleration& msg) override;
267+
};
268+
259269
} // namespace quadruped
260270
} // namespace pronto

pronto_quadruped_ros/include/pronto_quadruped_ros/conversions.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <sensor_msgs/JointState.h>
4+
#include <pronto_msgs/JointStateWithAcceleration.h>
45
#include <pronto_quadruped_commons/declarations.h>
56

67
namespace pronto {
@@ -11,5 +12,12 @@ bool jointStateFromROS(const sensor_msgs::JointState& msg,
1112
JointState& qd,
1213
JointState& qdd,
1314
JointState& tau);
15+
16+
bool jointStateWithAccelerationFromROS(const pronto_msgs::JointStateWithAcceleration& msg,
17+
uint64_t& utime,
18+
JointState& q,
19+
JointState& qd,
20+
JointState& qdd,
21+
JointState& tau);
1422
} // namespace quadruped
1523
} // namespace pronto

pronto_quadruped_ros/include/pronto_quadruped_ros/legodo_handler_ros.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <pronto_quadruped/LegOdometerBase.hpp>
3131
#include <pronto_quadruped/DataLogger.hpp>
3232

33+
#include <pronto_msgs/JointStateWithAcceleration.h>
3334
#include <pronto_msgs/QuadrupedStance.h>
3435
#include <pronto_msgs/QuadrupedForceTorqueSensors.h>
3536
#include <pronto_msgs/VelocityWithSigmaBounds.h>
@@ -133,6 +134,25 @@ class LegodoHandlerROS : public pronto::SensingModule<sensor_msgs::JointState>,
133134
RBIM &init_cov) override;
134135
};
135136

137+
class LegodoHandlerWithAccelerationROS : public pronto::SensingModule<pronto_msgs::JointStateWithAcceleration>,
138+
public LegodoHandlerBase
139+
{
140+
public:
141+
LegodoHandlerWithAccelerationROS(ros::NodeHandle& nh,
142+
StanceEstimatorBase &stance_est,
143+
LegOdometerBase &legodo) : LegodoHandlerBase(nh, stance_est, legodo) {}
144+
virtual ~LegodoHandlerWithAccelerationROS() = default;
145+
146+
Update * processMessage(const pronto_msgs::JointStateWithAcceleration *msg, StateEstimator *est) override;
147+
148+
bool processMessageInit(const pronto_msgs::JointStateWithAcceleration* /*msg*/,
149+
const std::map<std::string, bool>& /*sensor_initialized*/,
150+
const RBIS& /*default_state*/,
151+
const RBIM& /*default_cov*/,
152+
RBIS& /*init_state*/,
153+
RBIM& /*init_cov*/) override { return true; }
154+
};
155+
136156
class ForceSensorLegodoHandlerROS : public LegodoHandlerBase,
137157
public pronto::DualSensingModule<sensor_msgs::JointState,
138158
pronto_msgs::QuadrupedForceTorqueSensors>

pronto_quadruped_ros/src/bias_lock_handler_ros.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ void ImuBiasLockROS::processSecondaryMessage(const sensor_msgs::JointState &msg)
6565
jointStateFromROS(msg, bias_lock_js_msg_);
6666
bias_lock_module_->processSecondaryMessage(bias_lock_js_msg_);
6767
}
68+
69+
// pronto_msgs/JointStateWithAcceleration (includes acceleration)
70+
void ImuBiasLockWithAccelerationROS::processSecondaryMessage(const pronto_msgs::JointStateWithAcceleration &msg) {
71+
jointStateWithAccelerationFromROS(msg, bias_lock_js_msg_);
72+
bias_lock_module_->processSecondaryMessage(bias_lock_js_msg_);
73+
}

pronto_quadruped_ros/src/conversions.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,36 @@ bool jointStateFromROS(const sensor_msgs::JointState& msg,
3838
return true;
3939
}
4040

41+
bool jointStateWithAccelerationFromROS(const pronto_msgs::JointStateWithAcceleration& msg,
42+
uint64_t& utime,
43+
JointState& q,
44+
JointState& qd,
45+
JointState& qdd,
46+
JointState& tau)
47+
{
48+
// if the size of the joint state message does not match our own,
49+
// we silently return an invalid update
50+
if (static_cast<int>(static_cast<const pronto_msgs::JointStateWithAcceleration&>(msg).position.size()) != q.size() ||
51+
static_cast<int>(static_cast<const pronto_msgs::JointStateWithAcceleration&>(msg).velocity.size()) != q.size() ||
52+
static_cast<int>(static_cast<const pronto_msgs::JointStateWithAcceleration&>(msg).acceleration.size()) != q.size() ||
53+
static_cast<int>(static_cast<const pronto_msgs::JointStateWithAcceleration&>(msg).effort.size()) != q.size()){
54+
ROS_WARN_STREAM_THROTTLE(1, "Joint State is expected " << \
55+
q.size() << " joints but "\
56+
<< msg.position.size() << " / " << msg.velocity.size() << " / " << msg.acceleration.size() << " / " << msg.effort.size()
57+
<< " are provided.");
58+
return false;
59+
}
60+
// store message time in microseconds
61+
utime = 1e-3 * msg.header.stamp.toNSec();
62+
for(int i=0; i<12; i++){
63+
q(i) = msg.position[i];
64+
qd(i) = msg.velocity[i];
65+
qdd(i) = msg.acceleration[i];
66+
tau(i) = msg.effort[i];
67+
}
68+
69+
return true;
70+
}
71+
4172
} // namespace quadruped
4273
} // namespace pronto

pronto_quadruped_ros/src/legodo_handler_ros.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ bool LegodoHandlerROS::processMessageInit(const sensor_msgs::JointState* /*msg*/
317317
return true;
318318
}
319319

320+
LegodoHandlerWithAccelerationROS::Update* LegodoHandlerWithAccelerationROS::processMessage(const pronto_msgs::JointStateWithAcceleration *msg, StateEstimator *est)
321+
{
322+
nsec_ = msg->header.stamp.toNSec(); // save nsecs for later.
323+
utime_ = 1e-3 * nsec_; // A lot of internals still assume microseconds
324+
// TODO: transition from microseconds to nanoseconds everywhere
325+
if(!jointStateWithAccelerationFromROS(*msg, utime_, q_, qd_, qdd_, tau_)){
326+
ROS_WARN_STREAM("[LegodoHandlerWithAccelerationROS::processMessage] Could not process joint state from ROS!");
327+
return nullptr;
328+
}
329+
getPreviousState(est);
330+
331+
stance_estimator_.setJointStates(nsec_, q_, qd_, tau_, orientation_,
332+
// optional arguments starts from here
333+
// note passing previous value for velocity
334+
qdd_, xd_, xdd_, omega_, omegad_);
335+
336+
stance_estimator_.getStance(stance_, stance_prob_);
337+
338+
return computeVelocity();
339+
}
340+
320341
FootSensorLegodoHandlerROS::FootSensorLegodoHandlerROS(ros::NodeHandle& nh,
321342
StanceEstimatorBase& stance_est,
322343
LegOdometerBase& legodo)

pronto_ros/include/pronto_ros/pronto_ros_conversions.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <pronto_msgs/VisualOdometryUpdate.h>
1414
#include <pronto_msgs/LidarOdometryUpdate.h>
1515
#include <pronto_msgs/BipedForceTorqueSensors.h>
16+
#include <pronto_msgs/JointStateWithAcceleration.h>
1617

1718
namespace pronto {
1819

@@ -44,6 +45,8 @@ void rigidTransformFromROS(const geometry_msgs::TransformStamped& msg,
4445
void jointStateFromROS(const sensor_msgs::JointState& ros_msg,
4546
JointState& msg);
4647

48+
void jointStateWithAccelerationFromROS(const pronto_msgs::JointStateWithAcceleration& ros_msg, JointState& msg);
49+
4750
void visualOdometryFromROS(const pronto_msgs::VisualOdometryUpdate& ros_msg,
4851
VisualOdometryUpdate& msg);
4952

pronto_ros/src/pronto_ros_conversions.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ void jointStateFromROS(const sensor_msgs::JointState &ros_msg, JointState &msg){
144144
msg.joint_name = std::move(ros_msg.name);
145145
}
146146

147+
void jointStateWithAccelerationFromROS(const pronto_msgs::JointStateWithAcceleration &ros_msg, JointState &msg){
148+
// it is caller's responsibility to check that both joint states have same
149+
// size
150+
msg.utime = ros_msg.header.stamp.toNSec() / 1000;
151+
msg.joint_position = std::move(ros_msg.position);
152+
msg.joint_velocity = std::move(ros_msg.velocity);
153+
msg.joint_acceleration = std::move(ros_msg.acceleration);
154+
msg.joint_effort = std::move(ros_msg.effort);
155+
msg.joint_name = std::move(ros_msg.name);
156+
}
157+
147158
void visualOdometryFromROS(const pronto_msgs::VisualOdometryUpdate& ros_msg,
148159
VisualOdometryUpdate& msg){
149160
msg.curr_utime = ros_msg.curr_timestamp.toNSec() / 1000;

0 commit comments

Comments
 (0)