-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cd5da54
Showing
42 changed files
with
1,030 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Flappy Bird Automation Game | ||
|
||
This repository contains the Flappy Bird game modified to be controlled with ROS. | ||
|
||
## Game description | ||
|
||
|
||
Flappy Bird is in trouble again! This time it went into space and landed in an asteroid belt. If FlappyBird collides with the rocks it is game over. Luckily Flappy remembered his laser scanner that provides distance measurements. It will give you its velocity and the laserscans in return for an acceleration input. FlappyBird only asks for 60 seconds of your guidance. Help FlappyBird go through as many asteroid lines as possible before the time runs out! | ||
|
||
![Flappy](flappy_cover.png) | ||
|
||
## Getting Started | ||
|
||
This game has been tested with Ubuntu 16.04 running ROS Kinetic and Python 2.7. | ||
|
||
There are two recommended options for running the game. Either download the VirtualBox image that comes with a complete Ubuntu 16.04 setup or add the packages provided from this repository to your own ROS workspace. | ||
|
||
### Option 1 - VirtualBox | ||
First download VirtualBox from here [[VirtualBox link]](https://www.virtualbox.org/wiki/Downloads) and install it on your system. Then download the Ubuntu image that we have preconfigured with the game from here [[Image link]](https://www.virtualbox.org/wiki/Downloads). Once downloaded add the image to VirtualBox and boot up Ubuntu. | ||
The username and password are both **FlyaTest** . | ||
|
||
### Option 2 - Adding as ROS package | ||
If you already have Ubuntu you can install ROS and setup a workspace as covered here [[ROS install guide]](http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment). | ||
To add the automation game to your workspace clone the automation game repository to the source folder. | ||
|
||
If you followed the tutorial it will look like this, | ||
``` | ||
cd ~/catkin_ws/src/ | ||
``` | ||
Clone the automation game, | ||
``` | ||
git clone https://github.com/JohsBL/flappy_automation_test.git | ||
``` | ||
Make sure you have Pygame installed | ||
``` | ||
sudo apt-get install python-pygame | ||
``` | ||
|
||
Then run the catkin_make command | ||
``` | ||
cd ~/catkin_ws/ | ||
catkin_make | ||
``` | ||
|
||
## Running the game | ||
|
||
To run the game we use the roslaunch command. There are two ROS launch files depending on if you want to run the game with C++ or python automation code (whatever you prefer). | ||
|
||
For python open a terminal and run, | ||
``` | ||
roslaunch flappy_automation_code flappy_automation_code_py.launch | ||
``` | ||
For C++ open a terminal and run, | ||
``` | ||
roslaunch flappy_automation_code flappy_automation_code_cpp.launch | ||
``` | ||
A GUI will become visible with the game start screen. For now the automation code does not do anything, so to start the game and move the bird press the arrow keys. Tapping the up key ↑ will start the game. You can then add velocity in a wanted direction by pressing the arrow keys ←↑↓→. Notice that it is not possible to go backwards and if hitting an obstacle the bird will crash. | ||
|
||
## Automate FlappyBird | ||
Now that we have gotten familiar with the game we want to control FlappyBird. To do this a python and C++ template has been provided. | ||
|
||
### Modifying the code | ||
|
||
The templates are located in the **flappy_automation_code** folder. | ||
|
||
For using python modify the file **flappy_automation_code_node.py** in the **scripts** folder. | ||
|
||
For using C++ modify the files **flappy_automation_code.cpp** in the **src** folder and **flappy_automation_code.hpp** in the **include** folder. | ||
|
||
Take your pick. | ||
|
||
To get the state of the bird velocity readings and laserscans are published and an acceleration command can be given for actuating the FlappyBird. In the code callbacks for these topics and examples of how to read the returned messages are provided. | ||
|
||
### Build and run | ||
Once the code has been modified run the catkin_make command again, | ||
``` | ||
cd ~/catkin_ws/ | ||
catkin_make | ||
``` | ||
|
||
Then launch the game as before. | ||
|
||
Python, | ||
``` | ||
roslaunch flappy_automation_code flappy_automation_code_py.launch | ||
``` | ||
C++, | ||
``` | ||
roslaunch flappy_automation_code flappy_automation_code_cpp.launch | ||
``` | ||
|
||
### Other info | ||
Scaling: 1 pixel = 0.01 meter | ||
Game and sensor update rates: 30 fps | ||
Max acceleration x: 0.1 m/s^2 | ||
Max acceleration y: 2.0 m/s^2 | ||
Axis convention: x →, y ↑ | ||
[LaserScan message definition](http://docs.ros.org/api/sensor_msgs/html/msg/LaserScan.html) | ||
|
||
| Value | Unit | Topic | | ||
| ------------- |:-------------:| :-----:| | ||
| Velocity | m/s | /flappy_vel | | ||
| Acceleration | m/s^2 | /flappy_acc | | ||
| LaserScan | Radians, meters | /flappy_laser_scan | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(flappy_automation_code) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
rospy | ||
std_msgs | ||
) | ||
|
||
catkin_package( | ||
INCLUDE_DIRS include | ||
CATKIN_DEPENDS roscpp rospy std_msgs | ||
) | ||
|
||
include_directories( | ||
include | ||
${catkin_INCLUDE_DIRS} | ||
) | ||
|
||
add_executable(${PROJECT_NAME}_node src/flappy_automation_code.cpp) | ||
|
||
target_link_libraries(${PROJECT_NAME}_node | ||
${catkin_LIBRARIES} | ||
) |
21 changes: 21 additions & 0 deletions
21
flappy_automation_code/include/flappy_automation_code/flappy_automation_code.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef FLAPPY_AUTOMATION_CODE_H_ | ||
#define FLAPPY_AUTOMATION_CODE_H_ | ||
|
||
#include <ros/ros.h> | ||
#include "sensor_msgs/LaserScan.h" | ||
#include "geometry_msgs/Vector3.h" | ||
|
||
//Ros nodehandle | ||
ros::NodeHandle* nh_= NULL; | ||
//Publisher for acceleration command | ||
ros::Publisher pub_acc_cmd; | ||
//Subscriber for velocity | ||
ros::Subscriber sub_vel; | ||
//Subscriber for laser scan | ||
ros::Subscriber sub_laser_scan; | ||
|
||
void initNode(); | ||
void velCallback(const geometry_msgs::Vector3::ConstPtr& msg); | ||
void laserScanCallback(const sensor_msgs::LaserScan::ConstPtr& msg); | ||
|
||
#endif |
6 changes: 6 additions & 0 deletions
6
flappy_automation_code/launch/flappy_automation_code_cpp.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<launch> | ||
<!-- launch script for cpp automation of flappy --> | ||
|
||
<node name="flappy_automation_code" pkg="flappy_automation_code" type="flappy_automation_code_node" output="screen" /> | ||
<node name="flappy_main_game" pkg="flappy_main_game" type="flappy.py" output="screen" /> | ||
</launch> |
6 changes: 6 additions & 0 deletions
6
flappy_automation_code/launch/flappy_automation_code_py.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<launch> | ||
<!-- launch script for py automation of flappy --> | ||
|
||
<node name="flappy_automation_code" pkg="flappy_automation_code" type="flappy_automation_code_node.py" output="screen" /> | ||
<node name="flappy_main_game" pkg="flappy_main_game" type="flappy.py" output="screen" /> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>flappy_automation_code</name> | ||
<version>0.0.0</version> | ||
<description>The flappy_automation_code package</description> | ||
|
||
<maintainer email="[email protected]">johannes</maintainer> | ||
|
||
<license>TODO</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>roscpp</build_depend> | ||
<build_depend>rospy</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<build_export_depend>roscpp</build_export_depend> | ||
<build_export_depend>rospy</build_export_depend> | ||
<build_export_depend>std_msgs</build_export_depend> | ||
<exec_depend>roscpp</exec_depend> | ||
<exec_depend>rospy</exec_depend> | ||
<exec_depend>std_msgs</exec_depend> | ||
|
||
<export> | ||
|
||
</export> | ||
</package> |
37 changes: 37 additions & 0 deletions
37
flappy_automation_code/scripts/flappy_automation_code_node.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import rospy | ||
import numpy as np | ||
from sensor_msgs.msg import LaserScan | ||
from geometry_msgs.msg import Vector3 | ||
|
||
# Publisher for sending acceleration commands to flappy bird | ||
pub_acc_cmd = rospy.Publisher('/flappy_acc', Vector3, queue_size=1) | ||
|
||
def initNode(): | ||
# Here we initialize our node running the automation code | ||
rospy.init_node('flappy_automation_code', anonymous=True) | ||
|
||
# Subscribe to topics for velocity and laser scan from Flappy Bird game | ||
rospy.Subscriber("/flappy_vel", Vector3, velCallback) | ||
rospy.Subscriber("/flappy_laser_scan", LaserScan, laserScanCallback) | ||
|
||
# Ros spin to prevent program from exiting | ||
rospy.spin() | ||
|
||
def velCallback(msg): | ||
# msg has the format of geometry_msgs::Vector3 | ||
# Example of publishing acceleration command on velocity velCallback | ||
x = 0 | ||
y = 0 | ||
pub_acc_cmd.publish(Vector3(x,y,0)) | ||
|
||
def laserScanCallback(msg): | ||
# msg has the format of sensor_msgs::LaserScan | ||
# print laser angle and range | ||
print "Laser range: {}, angle: {}".format(msg.ranges[0], msg.angle_max) | ||
|
||
if __name__ == '__main__': | ||
try: | ||
initNode() | ||
except rospy.ROSInterruptException: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "ros/ros.h" | ||
#include "flappy_automation_code/flappy_automation_code.hpp" | ||
#include "sensor_msgs/LaserScan.h" | ||
#include "geometry_msgs/Vector3.h" | ||
|
||
void initNode() | ||
{ | ||
//Initialization of nodehandle | ||
nh_ = new ros::NodeHandle(); | ||
//Init publishers and subscribers | ||
pub_acc_cmd = nh_->advertise<geometry_msgs::Vector3>("/flappy_acc",1); | ||
sub_vel = nh_->subscribe<geometry_msgs::Vector3>("/flappy_vel", 1, velCallback); | ||
sub_laser_scan = nh_->subscribe<sensor_msgs::LaserScan>("/flappy_laser_scan", 1, laserScanCallback); | ||
} | ||
|
||
void velCallback(const geometry_msgs::Vector3::ConstPtr& msg) | ||
{ | ||
// msg has the format of geometry_msgs::Vector3 | ||
// Example of publishing acceleration command on velocity velCallback | ||
geometry_msgs::Vector3 acc_cmd; | ||
|
||
acc_cmd.x = 0; | ||
acc_cmd.y = 0; | ||
pub_acc_cmd.publish(acc_cmd); | ||
} | ||
|
||
void laserScanCallback(const sensor_msgs::LaserScan::ConstPtr& msg) | ||
{ | ||
//msg has the format of sensor_msgs::LaserScan | ||
//print laser angle and range | ||
ROS_INFO("Laser range: %f, angle: %f", msg->ranges[0], msg->angle_max); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
ros::init(argc,argv,"flappy_automation_code"); | ||
initNode(); | ||
|
||
// Ros spin to prevent program from exiting | ||
ros::spin(); | ||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(flappy_main_game) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
rospy | ||
std_msgs | ||
) | ||
include_directories( | ||
${catkin_INCLUDE_DIRS} | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>flappy_main_game</name> | ||
<version>0.0.0</version> | ||
<description>The flappy_main_game package</description> | ||
|
||
<maintainer email="[email protected]">johannes</maintainer> | ||
|
||
<license>TODO</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>roscpp</build_depend> | ||
<build_depend>rospy</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<build_export_depend>roscpp</build_export_depend> | ||
<build_export_depend>rospy</build_export_depend> | ||
<build_export_depend>std_msgs</build_export_depend> | ||
<exec_depend>roscpp</exec_depend> | ||
<exec_depend>rospy</exec_depend> | ||
<exec_depend>std_msgs</exec_depend> | ||
|
||
<export> | ||
|
||
</export> | ||
</package> |
Oops, something went wrong.