Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for defining and playing songs #37

Merged
merged 1 commit into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ _* Not verified. Anyone who is able to verify that this driver works or not is e
| Brush motors | Planned [#15](https://github.com/AutonomyLab/create_autonomy/issues/15) |
| LEDs | Available |
| Digit LEDs | Available |
| Sound | Planned [#5](https://github.com/AutonomyLab/create_autonomy/issues/5) |
| Sound | Available |
| Wheeldrop | Available |
| Bumpers | Available |
| Cliff sensor | Planned [#22](https://github.com/AutonomyLab/create_autonomy/issues/22) |
Expand Down Expand Up @@ -196,6 +196,8 @@ Topic | Description | Type
`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]
`dock` | Activates the demo docking behaviour. Robot enters _Passive_ mode meaning the user loses control (See [OI Spec][oi_spec]) | [std_msgs/Empty][empty]
`undock` | Switches robot to _Full_ mode giving control back to the user | [std_msgs/Empty][empty]
`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]
`play_song` | Play a predefined song | [ca_msgs/PlaySong][playsong_msg]

## Commanding your Create

Expand Down Expand Up @@ -229,6 +231,8 @@ Contributing to the development and maintenance of _create\_autonomy_ is encoura

* [Michael Browne](http://brownem.engineer/)
- Confirms driver works with Roomba 700 and 800 series.
* [Clyde McQueen](https://github.com/clydemcqueen)
- Added support for sound ([#37](https://github.com/AutonomyLab/create_autonomy/pull/37)).
* [Ben Wolsieffer](https://github.com/lopsided98)
- Added JointState publisher for wheels ([#26](https://github.com/AutonomyLab/create_autonomy/pull/26)).
- Added Create 1 description ([#27](https://github.com/AutonomyLab/create_autonomy/pull/27)).
Expand All @@ -248,3 +252,6 @@ Contributing to the development and maintenance of _create\_autonomy_ is encoura
[mode_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/Mode.msg
[chargingstate_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/ChargingState.msg
[jointstate_msg]: http://docs.ros.org/api/sensor_msgs/html/msg/JointState.html
[definesong_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/DefineSong.msg
[playsong_msg]: https://github.com/AutonomyLab/create_autonomy/blob/indigo-devel/ca_msgs/msg/PlaySong.msg

6 changes: 6 additions & 0 deletions ca_driver/include/create_driver/create_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "ca_msgs/ChargingState.h"
#include "ca_msgs/Mode.h"
#include "ca_msgs/Bumper.h"
#include "ca_msgs/DefineSong.h"
#include "ca_msgs/PlaySong.h"

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

bool update();
void updateBatteryDiagnostics(diagnostic_updater::DiagnosticStatusWrapper& stat);
Expand Down Expand Up @@ -94,6 +98,8 @@ class CreateDriver
ros::Subscriber set_ascii_sub_;
ros::Subscriber dock_sub_;
ros::Subscriber undock_sub_;
ros::Subscriber define_song_sub_;
ros::Subscriber play_song_sub_;

ros::Publisher odom_pub_;
ros::Publisher clean_btn_pub_;
Expand Down
18 changes: 18 additions & 0 deletions ca_driver/src/create_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ CreateDriver::CreateDriver(ros::NodeHandle& nh)
set_ascii_sub_ = nh.subscribe("set_ascii", 10, &CreateDriver::setASCIICallback, this);
dock_sub_ = nh.subscribe("dock", 10, &CreateDriver::dockCallback, this);
undock_sub_ = nh.subscribe("undock", 10, &CreateDriver::undockCallback, this);
define_song_sub_ = nh.subscribe("define_song", 10, &CreateDriver::defineSongCallback, this);
play_song_sub_ = nh.subscribe("play_song", 10, &CreateDriver::playSongCallback, this);

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

void CreateDriver::defineSongCallback(const ca_msgs::DefineSongConstPtr& msg)
{
if (!robot_->defineSong(msg->song, msg->length, &(msg->notes.front()), &(msg->durations.front())))
{
ROS_ERROR_STREAM("[CREATE] Failed to define song " << msg->song << " of length " << msg->length);
}
}

void CreateDriver::playSongCallback(const ca_msgs::PlaySongConstPtr& msg)
{
if (!robot_->playSong(msg->song))
{
ROS_ERROR_STREAM("[CREATE] Failed to play song " << msg->song);
}
}

bool CreateDriver::update()
{
publishOdom();
Expand Down
2 changes: 2 additions & 0 deletions ca_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ add_message_files(
FILES
Bumper.msg
ChargingState.msg
DefineSong.msg
Mode.msg
PlaySong.msg
)

generate_messages(
Expand Down
4 changes: 4 additions & 0 deletions ca_msgs/msg/DefineSong.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
uint8 song # song number [0-3]
uint8 length # song length [1-16]
uint8[] notes # notes defined by the MIDI note numbering scheme. Notes outside the range of [31-127] are rest notes.
float32[] durations # durations in seconds. Maximum duration is 255/64.
1 change: 1 addition & 0 deletions ca_msgs/msg/PlaySong.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uint8 song # song number [0-3]