Skip to content

Commit 6aea09b

Browse files
authored
Merge pull request #37 from clydemcqueen/indigo-devel
Add support for defining and playing songs
2 parents e03a47f + c6e7996 commit 6aea09b

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _* Not verified. Anyone who is able to verify that this driver works or not is e
4343
| Brush motors | Planned [#15](https://github.com/AutonomyLab/create_autonomy/issues/15) |
4444
| LEDs | Available |
4545
| Digit LEDs | Available |
46-
| Sound | Planned [#5](https://github.com/AutonomyLab/create_autonomy/issues/5) |
46+
| Sound | Available |
4747
| Wheeldrop | Available |
4848
| Bumpers | Available |
4949
| Cliff sensor | Planned [#22](https://github.com/AutonomyLab/create_autonomy/issues/22) |
@@ -196,6 +196,8 @@ Topic | Description | Type
196196
`set_ascii` | Sets the 4 digit LEDs. Accepts 1 to 4 bytes, each representing an ASCII character to be displayed from left to right | [std_msgs/UInt8MultiArray][uint8multiarray]
197197
`dock` | Activates the demo docking behaviour. Robot enters _Passive_ mode meaning the user loses control (See [OI Spec][oi_spec]) | [std_msgs/Empty][empty]
198198
`undock` | Switches robot to _Full_ mode giving control back to the user | [std_msgs/Empty][empty]
199+
`define_song` | Define a song with up to 16 notes. Each note is described by a MIDI note number and a float32 duration in seconds. The longest duration is 255/64 seconds. You can define up to 4 songs (See [OI Spec][oi_spec]) | [ca_msgs/DefineSong][definesong_msg]
200+
`play_song` | Play a predefined song | [ca_msgs/PlaySong][playsong_msg]
199201
200202
## Commanding your Create
201203
@@ -229,6 +231,8 @@ Contributing to the development and maintenance of _create\_autonomy_ is encoura
229231
230232
* [Michael Browne](http://brownem.engineer/)
231233
- Confirms driver works with Roomba 700 and 800 series.
234+
* [Clyde McQueen](https://github.com/clydemcqueen)
235+
- Added support for sound ([#37](https://github.com/AutonomyLab/create_autonomy/pull/37)).
232236
* [Ben Wolsieffer](https://github.com/lopsided98)
233237
- Added JointState publisher for wheels ([#26](https://github.com/AutonomyLab/create_autonomy/pull/26)).
234238
- Added Create 1 description ([#27](https://github.com/AutonomyLab/create_autonomy/pull/27)).
@@ -248,3 +252,6 @@ Contributing to the development and maintenance of _create\_autonomy_ is encoura
248252
[mode_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/Mode.msg
249253
[chargingstate_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/ChargingState.msg
250254
[jointstate_msg]: http://docs.ros.org/api/sensor_msgs/html/msg/JointState.html
255+
[definesong_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/DefineSong.msg
256+
[playsong_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/PlaySong.msg
257+

ca_driver/include/create_driver/create_driver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "ca_msgs/ChargingState.h"
2020
#include "ca_msgs/Mode.h"
2121
#include "ca_msgs/Bumper.h"
22+
#include "ca_msgs/DefineSong.h"
23+
#include "ca_msgs/PlaySong.h"
2224

2325
static const double MAX_DBL = std::numeric_limits<double>::max();
2426
static const double COVARIANCE[36] = {1e-5, 1e-5, 0.0, 0.0, 0.0, 1e-5,
@@ -66,6 +68,8 @@ class CreateDriver
6668
void setASCIICallback(const std_msgs::UInt8MultiArrayConstPtr& msg);
6769
void dockCallback(const std_msgs::EmptyConstPtr& msg);
6870
void undockCallback(const std_msgs::EmptyConstPtr& msg);
71+
void defineSongCallback(const ca_msgs::DefineSongConstPtr& msg);
72+
void playSongCallback(const ca_msgs::PlaySongConstPtr& msg);
6973

7074
bool update();
7175
void updateBatteryDiagnostics(diagnostic_updater::DiagnosticStatusWrapper& stat);
@@ -94,6 +98,8 @@ class CreateDriver
9498
ros::Subscriber set_ascii_sub_;
9599
ros::Subscriber dock_sub_;
96100
ros::Subscriber undock_sub_;
101+
ros::Subscriber define_song_sub_;
102+
ros::Subscriber play_song_sub_;
97103

98104
ros::Publisher odom_pub_;
99105
ros::Publisher clean_btn_pub_;

ca_driver/src/create_driver.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ CreateDriver::CreateDriver(ros::NodeHandle& nh)
8989
set_ascii_sub_ = nh.subscribe("set_ascii", 10, &CreateDriver::setASCIICallback, this);
9090
dock_sub_ = nh.subscribe("dock", 10, &CreateDriver::dockCallback, this);
9191
undock_sub_ = nh.subscribe("undock", 10, &CreateDriver::undockCallback, this);
92+
define_song_sub_ = nh.subscribe("define_song", 10, &CreateDriver::defineSongCallback, this);
93+
play_song_sub_ = nh.subscribe("play_song", 10, &CreateDriver::playSongCallback, this);
9294

9395
// Setup publishers
9496
odom_pub_ = nh.advertise<nav_msgs::Odometry>("odom", 30);
@@ -222,6 +224,22 @@ void CreateDriver::undockCallback(const std_msgs::EmptyConstPtr& msg)
222224
robot_->setMode(create::MODE_FULL);
223225
}
224226

227+
void CreateDriver::defineSongCallback(const ca_msgs::DefineSongConstPtr& msg)
228+
{
229+
if (!robot_->defineSong(msg->song, msg->length, &(msg->notes.front()), &(msg->durations.front())))
230+
{
231+
ROS_ERROR_STREAM("[CREATE] Failed to define song " << msg->song << " of length " << msg->length);
232+
}
233+
}
234+
235+
void CreateDriver::playSongCallback(const ca_msgs::PlaySongConstPtr& msg)
236+
{
237+
if (!robot_->playSong(msg->song))
238+
{
239+
ROS_ERROR_STREAM("[CREATE] Failed to play song " << msg->song);
240+
}
241+
}
242+
225243
bool CreateDriver::update()
226244
{
227245
publishOdom();

ca_msgs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ add_message_files(
1010
FILES
1111
Bumper.msg
1212
ChargingState.msg
13+
DefineSong.msg
1314
Mode.msg
15+
PlaySong.msg
1416
)
1517

1618
generate_messages(

ca_msgs/msg/DefineSong.msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
uint8 song # song number [0-3]
2+
uint8 length # song length [1-16]
3+
uint8[] notes # notes defined by the MIDI note numbering scheme. Notes outside the range of [31-127] are rest notes.
4+
float32[] durations # durations in seconds. Maximum duration is 255/64.

ca_msgs/msg/PlaySong.msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uint8 song # song number [0-3]

0 commit comments

Comments
 (0)