Skip to content

Commit 7ff3d57

Browse files
authored
Merge pull request #26 from lopsided98/indigo-devel
Publish JointState messages for the wheels
2 parents f260846 + 90b5619 commit 7ff3d57

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ $ roslaunch ca_driver create_1.launch [publish_tf:=true]
161161
`dock_button` | 'dock' button is pressed ('advance' button for Create 1) | [std_msgs/Empty][empty]
162162
`spot_button` | 'spot' button is pressed | [std_msgs/Empty][empty]
163163
`ir_omni` | The IR character currently being read by the omnidirectional receiver. Value 0 means no character is being received | [std_msgs/UInt16][uint16]
164+
`joint_states` | The states (position, velocity) of the drive wheel joints | [sensor_msgs/JointState][jointstate_msg]
164165
`mode` | The current mode of the robot (See [OI Spec][oi_spec] for details)| [ca_msgs/Mode][mode_msg]
165166
`odom` | Robot odometry according to wheel encoders | [nav_msgs/Odometry][odometry]
166167
`wheeldrop` | At least one of the drive wheels has dropped | [std_msgs/Empty][empty]
167168
`/tf` | The transform from the `odom` frame to `base_footprint`. Only if the parameter `publish_tf` is `true` | [tf2_msgs/TFMessage](http://docs.ros.org/jade/api/tf2_msgs/html/msg/TFMessage.html)
168169

170+
169171
### Subscribers
170172

171173
Topic | Description | Type
@@ -226,3 +228,4 @@ Contributing to the development and maintenance of _create\_autonomy_ is encoura
226228
[bumper_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/Bumper.msg
227229
[mode_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/Mode.msg
228230
[chargingstate_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/ChargingState.msg
231+
[jointstate_msg]: http://docs.ros.org/api/sensor_msgs/html/msg/JointState.html

ca_driver/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ find_package(catkin REQUIRED COMPONENTS
66
std_msgs
77
geometry_msgs
88
nav_msgs
9+
sensor_msgs
910
tf
1011
ca_msgs
1112
)
@@ -15,13 +16,13 @@ find_package(Boost REQUIRED system thread)
1516
catkin_package(
1617
INCLUDE_DIRS include
1718
LIBRARIES libcreate
18-
CATKIN_DEPENDS roscpp std_msgs geometry_msgs nav_msgs tf ca_msgs ca_description
19+
CATKIN_DEPENDS roscpp std_msgs geometry_msgs nav_msgs sensor_msgs tf ca_msgs ca_description
1920
)
2021

2122
include(ExternalProject)
2223
ExternalProject_Add(libcreate
2324
GIT_REPOSITORY https://github.com/AutonomyLab/libcreate.git
24-
GIT_TAG 1.2.1
25+
GIT_TAG master
2526
PREFIX ${CATKIN_DEVEL_PREFIX}
2627
CONFIGURE_COMMAND cmake .
2728
BUILD_COMMAND make

ca_driver/include/create_driver/create_driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <std_msgs/UInt16.h>
99
#include <std_msgs/Int16.h>
1010
#include <std_msgs/UInt8MultiArray.h>
11+
#include <sensor_msgs/JointState.h>
1112
#include <geometry_msgs/Twist.h>
1213
#include <geometry_msgs/TransformStamped.h>
1314
#include <nav_msgs/Odometry.h>
@@ -42,6 +43,7 @@ class CreateDriver
4243
std_msgs::Float32 float32_msg_;
4344
std_msgs::UInt16 uint16_msg_;
4445
std_msgs::Int16 int16_msg_;
46+
sensor_msgs::JointState joint_state_msg_;
4547

4648
// ROS params
4749
double loop_hz_;
@@ -62,6 +64,7 @@ class CreateDriver
6264

6365
bool update();
6466
void publishOdom();
67+
void publishJointState();
6568
void publishBatteryInfo();
6669
void publishButtonPresses() const;
6770
void publishOmniChar();
@@ -100,6 +103,7 @@ class CreateDriver
100103
ros::Publisher mode_pub_;
101104
ros::Publisher bumper_pub_;
102105
ros::Publisher wheeldrop_pub_;
106+
ros::Publisher wheel_joint_pub_;
103107

104108
public:
105109
CreateDriver(ros::NodeHandle& nh);

ca_driver/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
<build_depend>std_msgs</build_depend>
1919
<build_depend>geometry_msgs</build_depend>
2020
<build_depend>nav_msgs</build_depend>
21+
<build_depend>sensor_msgs</build_depend>
2122
<build_depend>tf</build_depend>
2223
<build_depend>ca_msgs</build_depend>
2324

2425
<run_depend>roscpp</run_depend>
2526
<run_depend>std_msgs</run_depend>
2627
<run_depend>geometry_msgs</run_depend>
2728
<run_depend>nav_msgs</run_depend>
29+
<run_depend>sensor_msgs</run_depend>
2830
<run_depend>tf</run_depend>
2931
<run_depend>ca_msgs</run_depend>
3032
<run_depend>ca_description</run_depend>

ca_driver/src/create_driver.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ CreateDriver::CreateDriver(ros::NodeHandle& nh) : nh_(nh), priv_nh_("~")
4949
tf_odom_.child_frame_id = str_base_footprint;
5050
odom_msg_.header.frame_id = "odom";
5151
odom_msg_.child_frame_id = str_base_footprint;
52+
joint_state_msg_.name.resize(2);
53+
joint_state_msg_.position.resize(2);
54+
joint_state_msg_.velocity.resize(2);
55+
joint_state_msg_.effort.resize(2);
56+
joint_state_msg_.name[0] = "left_wheel_joint";
57+
joint_state_msg_.name[1] = "right_wheel_joint";
5258

5359
// Populate intial covariances
5460
for (int i = 0; i < 36; i++)
@@ -85,6 +91,7 @@ CreateDriver::CreateDriver(ros::NodeHandle& nh) : nh_(nh), priv_nh_("~")
8591
mode_pub_ = nh.advertise<ca_msgs::Mode>("mode", 30);
8692
bumper_pub_ = nh.advertise<ca_msgs::Bumper>("bumper", 30);
8793
wheeldrop_pub_ = nh.advertise<std_msgs::Empty>("wheeldrop", 30);
94+
wheel_joint_pub_ = nh.advertise<sensor_msgs::JointState>("joint_states", 10);
8895
ROS_INFO("[CREATE] Ready.");
8996
}
9097

@@ -190,6 +197,7 @@ void CreateDriver::undockCallback(const std_msgs::EmptyConstPtr& msg)
190197
bool CreateDriver::update()
191198
{
192199
publishOdom();
200+
publishJointState();
193201
publishBatteryInfo();
194202
publishButtonPresses();
195203
publishOmniChar();
@@ -255,6 +263,18 @@ void CreateDriver::publishOdom()
255263
odom_pub_.publish(odom_msg_);
256264
}
257265

266+
void CreateDriver::publishJointState() {
267+
// Publish joint states
268+
static float CREATE_2_WHEEL_RADIUS = create::util::CREATE_2_WHEEL_DIAMETER / 2.0;
269+
270+
joint_state_msg_.header.stamp = ros::Time::now();
271+
joint_state_msg_.position[0] = robot_->getLeftWheelDistance() / CREATE_2_WHEEL_RADIUS;
272+
joint_state_msg_.position[1] = robot_->getRightWheelDistance() / CREATE_2_WHEEL_RADIUS;
273+
joint_state_msg_.velocity[0] = robot_->getRequestedLeftWheelVel() / CREATE_2_WHEEL_RADIUS;
274+
joint_state_msg_.velocity[1] = robot_->getRequestedRightWheelVel() / CREATE_2_WHEEL_RADIUS;
275+
wheel_joint_pub_.publish(joint_state_msg_);
276+
}
277+
258278
void CreateDriver::publishBatteryInfo()
259279
{
260280
float32_msg_.data = robot_->getVoltage();

0 commit comments

Comments
 (0)