artoo-crazyflie 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e0d2c7d86a802bdc5bdb2549311392b230baa96
4
+ data.tar.gz: 38e0a2be8d4936500f40acb5457c9f4847b9807f
5
+ SHA512:
6
+ metadata.gz: c8af6dcddbf341d1b125eb5b25220ceb8b645a9c6beb348a923b47a486179423653fbbce895e48fa10e648ab569cd3ebe893555c67baf5986b584aa5927e5e8b
7
+ data.tar.gz: eb781ee11670ffff07047498cd99f12c91c82a4490493dc949ad4efe95493a748785e10fa106015f3680afbf6c89c57b00d7f6bd2d366120a20876a67f030876
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in artoo-crazyflie.gemspec
4
+ #gem 'artoo-joystick' #, :git => 'git://github.com/hybridgroup/artoo-joystick.git'
5
+ #gem 'ruby-sdl-ffi', :git => 'git://github.com/hybridgroup/ruby-sdl-ffi.git'
6
+ #gem 'crubyflie', :git => 'git://github.com/hybridgroup/crubyflie.git'
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ artoo-crazyflie (0.1.0)
5
+ artoo (>= 1.3.0)
6
+ hybridgroup-crubyflie
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ artoo (1.3.0)
12
+ celluloid (~> 0.15.0)
13
+ celluloid-io (~> 0.15.0)
14
+ multi_json (~> 1.6)
15
+ pry (~> 0.9)
16
+ rake
17
+ reel (~> 0.4.0)
18
+ thor (~> 0.18.1)
19
+ celluloid (0.15.1)
20
+ timers (~> 1.1.0)
21
+ celluloid-io (0.15.0)
22
+ celluloid (>= 0.15.0)
23
+ nio4r (>= 0.5.0)
24
+ coderay (1.0.9)
25
+ ffi (1.9.0)
26
+ http (0.5.0)
27
+ http_parser.rb
28
+ http_parser.rb (0.6.0.beta.2)
29
+ hybridgroup-crubyflie (0.1.4)
30
+ libusb
31
+ trollop
32
+ libusb (0.3.4)
33
+ ffi (>= 1.0)
34
+ metaclass (0.0.1)
35
+ method_source (0.8.2)
36
+ minitest (5.0.8)
37
+ minitest-happy (1.0.0)
38
+ mocha (0.14.0)
39
+ metaclass (~> 0.0.1)
40
+ multi_json (1.8.1)
41
+ nio4r (0.5.0)
42
+ pry (0.9.12.2)
43
+ coderay (~> 1.0.5)
44
+ method_source (~> 0.8)
45
+ slop (~> 3.4)
46
+ rake (10.1.0)
47
+ reel (0.4.0)
48
+ celluloid (>= 0.15.1)
49
+ celluloid-io (>= 0.15.0)
50
+ http (>= 0.5.0)
51
+ http_parser.rb (>= 0.6.0.beta.2)
52
+ websocket_parser (>= 0.1.4)
53
+ slop (3.4.6)
54
+ thor (0.18.1)
55
+ timers (1.1.0)
56
+ trollop (2.0)
57
+ websocket_parser (0.1.4)
58
+ http
59
+
60
+ PLATFORMS
61
+ java
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ artoo-crazyflie!
66
+ minitest (>= 5.0)
67
+ minitest-happy
68
+ mocha (>= 0.14.0)
data/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+
2
+ # TODO: put your license file here
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Artoo Adaptor For Crazyflie
2
+
3
+ This repository contains the Artoo (http://artoo.io/) adaptor for the Crazyflie micro-quadcopter (http://www.bitcraze.se/).
4
+
5
+ Artoo is a open source micro-framework for robotics using Ruby.
6
+
7
+ For more information abut Artoo, check out our repo at https://github.com/hybridgroup/artoo
8
+
9
+ The artoo-crazyflie adaptor is based on the crubyflie gem (https://github.com/hsanjuan/crubyflie).
10
+
11
+ [![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-crazyflie.png)](https://codeclimate.com/github/hybridgroup/artoo-crazyflie) [![Build Status](https://travis-ci.org/hybridgroup/artoo-crazyflie.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-crazyflie)
12
+
13
+ ## Installing
14
+
15
+ ```
16
+ gem install artoo-crazyflie
17
+ ```
18
+
19
+ ## Using
20
+
21
+ ```ruby
22
+ require 'artoo'
23
+
24
+ connection :crazyflie, :adaptor => :crazyflie
25
+ device :drone, :driver => :crazyflie, :connection => :crazyflie, :interval => 0.1
26
+
27
+ work do
28
+ drone.forward(0)
29
+ drone.set_thrust_on
30
+ after(1.seconds) {drone.stop}
31
+ end
32
+ ```
33
+
34
+ ## Connecting to Crazyflie
35
+
36
+ The Crazyflie uses a 2.4 GHz radio to communicate. There is a USB dongle called the Crazyradio that is required to control the Crazyflie quadcopter.
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "artoo-crazyflie/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "artoo-crazyflie"
7
+ s.version = Artoo::Crazyflie::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Adrian Zankich"]
10
+ s.email = ["artoo@hybridgroup.com"]
11
+ s.homepage = "https://github.com/hybridgroup/artoo-crazyflie"
12
+ s.summary = %q{Artoo adaptor and driver for Crazyflie}
13
+ s.description = %q{Artoo adaptor and driver for Crazyflie}
14
+
15
+ s.rubyforge_project = "artoo-crazyflie"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency 'artoo', '>= 1.3.0'
23
+ s.add_runtime_dependency 'hybridgroup-crubyflie'
24
+ s.add_development_dependency 'minitest', '>= 5.0'
25
+ s.add_development_dependency 'minitest-happy'
26
+ s.add_development_dependency 'mocha', '>= 0.14.0'
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'artoo'
2
+
3
+ connection :crazyflie, :adaptor => :crazyflie
4
+ device :drone, :driver => :crazyflie, :connection => :crazyflie, :interval => 0.1
5
+
6
+ work do
7
+ drone.forward(0)
8
+ drone.set_thrust_on
9
+ after(1.seconds) {drone.stop}
10
+ end
@@ -0,0 +1,62 @@
1
+ require 'artoo'
2
+
3
+ connection :crazyflie, :adaptor => :crazyflie
4
+ device :drone, :driver => :crazyflie, :connection => :crazyflie, :interval => 0.01
5
+
6
+ connection :joystick, :adaptor => :joystick
7
+ device :controller, :driver => :xbox360, :connection => :joystick, :interval => 0.01
8
+ #device :controller, :driver => :ps3, :connection => :joystick, :interval => 0.01
9
+ #device :controller, :driver => :joystick, :connection => :joystick, :interval => 0.01
10
+
11
+ work do
12
+ on controller, :joystick_0 => proc { |caller, data|
13
+ handle_joystick_0 data
14
+ }
15
+ on controller, :joystick_1 => proc { |caller, data|
16
+ handle_joystick_1 data
17
+ }
18
+ end
19
+
20
+ def handle_joystick_0 data
21
+ thrust_scale = 1.46
22
+ yaw_scale = 0.000191753
23
+ degrade = 700
24
+ @power = 0 if @power.nil?
25
+ thrust = (data[:y] < 0) ? (data[:y].abs * thrust_scale) : 0
26
+ if thrust >= @power
27
+ @power = thrust
28
+ elsif @power < degrade
29
+ @power = 0
30
+ else
31
+ @power = @power - degrade
32
+ end
33
+ drone.power(@power)
34
+
35
+ if data[:x] > 0
36
+ drone.turn_right(data[:x].abs * yaw_scale)
37
+ elsif data[:x] < 0
38
+ drone.turn_left(data[:x].abs * yaw_scale)
39
+ else
40
+ drone.turn_left(0)
41
+ end
42
+ end
43
+
44
+ def handle_joystick_1 data
45
+ deg_scale = 0.00091
46
+
47
+ if data[:y] < 0
48
+ drone.forward(data[:y].abs * deg_scale)
49
+ elsif data[:y] > 0
50
+ drone.backward(data[:y].abs * deg_scale)
51
+ else
52
+ drone.forward(0)
53
+ end
54
+
55
+ if data[:x] > 0
56
+ drone.right(data[:x].abs * deg_scale)
57
+ elsif data[:x] < 0
58
+ drone.left(data[:x].abs * deg_scale)
59
+ else
60
+ drone.left(0)
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ require 'artoo'
2
+
3
+ connection :crazyflie, :adaptor => :crazyflie
4
+ device :drone, :driver => :crazyflie, :connection => :crazyflie, :interval => 0.01
5
+
6
+ connection :leap, :adaptor => :leapmotion, :port => '127.0.0.1:6437'
7
+ device :leap, :connection => :leap, :driver => :leapmotion
8
+
9
+ work do
10
+ on leap, :hand => :wave
11
+ every(0.01) do
12
+ handle_thrust
13
+ end
14
+ end
15
+
16
+ def handle_thrust
17
+ @degrade = 700
18
+ @power = 0 if @power.nil?
19
+ @thrust = 0 if @thrust.nil?
20
+ if @thrust >= @power
21
+ @power = @thrust
22
+ @thrust = 0
23
+ elsif @power < @degrade
24
+ @power = 0
25
+ else
26
+ @power = @power - @degrade
27
+ end
28
+ drone.power(@power)
29
+ end
30
+
31
+ def wave sender, hand
32
+ return unless hand
33
+ @thrust = hand.palm_z.from_scale(100..800).to_scale(0..60000)
34
+ end
@@ -0,0 +1,3 @@
1
+ require 'lib/artoo/adaptors/crazyflie'
2
+ require 'lib/artoo/drivers/crazyflie'
3
+ require 'lib/artoo-crazyflie/version'
@@ -0,0 +1,5 @@
1
+ module Artoo
2
+ module Crazyflie
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ # Connect to a crazyflie quadcopter
6
+ # @see crazyflie documentation for more information
7
+ class Crazyflie < Adaptor
8
+ attr_reader :crazyflie, :commander
9
+
10
+ # Creates a connection with crazyflie
11
+ # @return [Boolean]
12
+ def connect
13
+ require 'crubyflie' unless defined?(::Crubyflie)
14
+ @crazyflie = ::Crubyflie::Crazyflie.new('/tmp/test')
15
+ source = additional_params[:source] || ""
16
+ if source.empty?
17
+ flies = @crazyflie.scan_interface
18
+ if flies.empty?
19
+ raise "No crazyflies!"
20
+ end
21
+ source = flies.first
22
+ end
23
+ @crazyflie.open_link(source)
24
+ @commander = ::Crubyflie::Commander.new(@crazyflie)
25
+ super
26
+ end
27
+
28
+ # Closes connection with device
29
+ # @return [Boolean]
30
+ def disconnect
31
+ @crazyflie.close_link
32
+
33
+ super
34
+ end
35
+
36
+ # device info interface
37
+ def firmware_name
38
+ "Crazyflie"
39
+ end
40
+
41
+ def version
42
+ Crubyflie::VERSION
43
+ end
44
+
45
+ # Uses method missing to call device actions
46
+ # @see device documentation
47
+ def method_missing(method_name, *arguments, &block)
48
+ @crazyflie.send(method_name, *arguments, &block)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,102 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # The crazyflie driver behaviors
6
+ class Crazyflie < Driver
7
+ COMMANDS = [:start, :stop, :hover, :land, :take_off, :emergency,
8
+ :up, :down, :left, :right, :forward, :backward,
9
+ :turn_left, :turn_right, :power].freeze
10
+
11
+
12
+ attr_reader :roll, :pitch, :yaw, :thrust, :xmode
13
+
14
+ def initialize(params={})
15
+ @roll = 0
16
+ @pitch = 0
17
+ @yaw = 0
18
+ @thrust = 0
19
+ @xmode = false # TODO what is this?
20
+ super
21
+ end
22
+
23
+ # Start driver and any required connections
24
+ def start_driver
25
+ begin
26
+ every(interval) do
27
+ send_command
28
+ end
29
+
30
+ super
31
+ rescue Exception => e
32
+ Logger.error "Error starting Crazyflie driver!"
33
+ Logger.error e.message
34
+ Logger.error e.backtrace.inspect
35
+ end
36
+ end
37
+
38
+ def start
39
+ @roll = 0
40
+ @pitch = 0
41
+ @yaw = 0
42
+ @thrust = 10001
43
+ end
44
+
45
+ def stop
46
+ set_thrust_off
47
+ end
48
+
49
+ def hover
50
+ # TODO: call firmware that can do this?
51
+ end
52
+
53
+ def land
54
+ end
55
+
56
+ def take_off
57
+ end
58
+
59
+ def power(deg)
60
+ @thrust = deg
61
+ end
62
+
63
+ def forward(deg)
64
+ @pitch = deg
65
+ end
66
+
67
+ def backward(deg)
68
+ @pitch = -deg
69
+ end
70
+
71
+ def left(deg)
72
+ @roll = -deg
73
+ end
74
+
75
+ def right(deg)
76
+ @roll = deg
77
+ end
78
+
79
+ def turn_left(deg)
80
+ @yaw = -deg
81
+ end
82
+
83
+ def turn_right(deg)
84
+ @yaw = deg
85
+ end
86
+
87
+ def set_thrust_on
88
+ @thrust = 40000
89
+ end
90
+
91
+ def set_thrust_off
92
+ @thrust = 0
93
+ end
94
+
95
+ private
96
+
97
+ def send_command
98
+ connection.commander.send_setpoint(roll, pitch, yaw, thrust, xmode)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/adaptors/crazyflie'
3
+
4
+ # TODO: test for your adaptor goes here...
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/drivers/crazyflie'
3
+
4
+ # TODO: test for your driver goes here...
@@ -0,0 +1,5 @@
1
+ require 'artoo/robot'
2
+
3
+ require 'minitest/autorun'
4
+
5
+ Celluloid.logger = nil
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artoo-crazyflie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Zankich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: artoo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hybridgroup-crubyflie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-happy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.0
83
+ description: Artoo adaptor and driver for Crazyflie
84
+ email:
85
+ - artoo@hybridgroup.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - artoo-crazyflie.gemspec
97
+ - examples/crazy_hop.rb
98
+ - examples/crazy_joystick.rb
99
+ - examples/crazy_leapmotion.rb
100
+ - lib/artoo-crazyflie.rb
101
+ - lib/artoo-crazyflie/version.rb
102
+ - lib/artoo/adaptors/crazyflie.rb
103
+ - lib/artoo/drivers/crazyflie.rb
104
+ - test/adaptors/crazyflie_adaptor_test.rb
105
+ - test/drivers/crazyflie_driver_test.rb
106
+ - test/test_helper.rb
107
+ homepage: https://github.com/hybridgroup/artoo-crazyflie
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project: artoo-crazyflie
126
+ rubygems_version: 2.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Artoo adaptor and driver for Crazyflie
130
+ test_files: []