rapiro_wrapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +138 -0
  9. data/Rakefile +5 -0
  10. data/bin/rapiro_wrapper +147 -0
  11. data/lib/rapiro_wrapper.rb +23 -0
  12. data/lib/rapiro_wrapper/body.rb +43 -0
  13. data/lib/rapiro_wrapper/command.rb +19 -0
  14. data/lib/rapiro_wrapper/commander.rb +28 -0
  15. data/lib/rapiro_wrapper/led.rb +4 -0
  16. data/lib/rapiro_wrapper/led/eyes.rb +23 -0
  17. data/lib/rapiro_wrapper/servo_motor.rb +27 -0
  18. data/lib/rapiro_wrapper/servo_motor/head.rb +21 -0
  19. data/lib/rapiro_wrapper/servo_motor/left_foot_pitch.rb +21 -0
  20. data/lib/rapiro_wrapper/servo_motor/left_foot_yaw.rb +21 -0
  21. data/lib/rapiro_wrapper/servo_motor/left_hand_grip.rb +21 -0
  22. data/lib/rapiro_wrapper/servo_motor/left_sholder_pitch.rb +18 -0
  23. data/lib/rapiro_wrapper/servo_motor/left_sholder_roll.rb +18 -0
  24. data/lib/rapiro_wrapper/servo_motor/right_foot_pitch.rb +21 -0
  25. data/lib/rapiro_wrapper/servo_motor/right_foot_yaw.rb +21 -0
  26. data/lib/rapiro_wrapper/servo_motor/right_hand_grip.rb +21 -0
  27. data/lib/rapiro_wrapper/servo_motor/right_sholder_pitch.rb +18 -0
  28. data/lib/rapiro_wrapper/servo_motor/right_sholder_roll.rb +14 -0
  29. data/lib/rapiro_wrapper/servo_motor/waist.rb +21 -0
  30. data/lib/rapiro_wrapper/version.rb +4 -0
  31. data/rapiro_wrapper.gemspec +27 -0
  32. data/spec/integration/base_spec.rb +577 -0
  33. data/spec/rapiro_wrapper/body_spec.rb +77 -0
  34. data/spec/rapiro_wrapper/command_spec.rb +54 -0
  35. data/spec/rapiro_wrapper/commander_spec.rb +111 -0
  36. data/spec/rapiro_wrapper/led/eyes_spec.rb +38 -0
  37. data/spec/rapiro_wrapper/servo_moter/head_spec.rb +248 -0
  38. data/spec/rapiro_wrapper/servo_moter/left_foot_pitch_spec.rb +261 -0
  39. data/spec/rapiro_wrapper/servo_moter/left_foot_yaw_spec.rb +256 -0
  40. data/spec/rapiro_wrapper/servo_moter/left_hand_grip_spec.rb +256 -0
  41. data/spec/rapiro_wrapper/servo_moter/left_sholder_pitch_spec.rb +134 -0
  42. data/spec/rapiro_wrapper/servo_moter/left_sholder_roll_spec.rb +150 -0
  43. data/spec/rapiro_wrapper/servo_moter/right_foot_pitch_spec.rb +261 -0
  44. data/spec/rapiro_wrapper/servo_moter/right_foot_yaw_spec.rb +256 -0
  45. data/spec/rapiro_wrapper/servo_moter/right_hand_grip_spec.rb +256 -0
  46. data/spec/rapiro_wrapper/servo_moter/right_sholder_pitch_spec.rb +134 -0
  47. data/spec/rapiro_wrapper/servo_moter/right_sholder_roll_spec.rb +150 -0
  48. data/spec/rapiro_wrapper/servo_moter/waist_spec.rb +248 -0
  49. data/spec/rapiro_wrapper/servo_moter_spec.rb +64 -0
  50. data/spec/rapiro_wrapper/version_spec.rb +11 -0
  51. data/spec/spec_helper.rb +4 -0
  52. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7cd2ae42f91176f5dcf81417aefa11cc44c0c47
4
+ data.tar.gz: 946f4dc26e07d36d23caa2b0da9cef37bd17bce3
5
+ SHA512:
6
+ metadata.gz: 6e1cf27a03172b75bae19eb7d11ac9ef2f99f40a068897c28c131588e53c656862f785a7bb91bbfad100bb49b56e9f4f48efb0e850b8351dff5722a931984424
7
+ data.tar.gz: 5ee7277a0aafabdebb762cca7a1b1f987fc002f36aafd80c932c8cf20af6b761d90dccc2fc5fb7c3e48acc4b8a4d51cd0121f78a0126effd09acccf8da7f55b0
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.swp
16
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rapiro_wrapper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rapiro_wrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Takahiro HAMAGUCHI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # Rapiro Wrapper
2
+
3
+ A gem providing access to Rapiro with SerialPort.
4
+
5
+ ## Installation
6
+
7
+
8
+ ```ruby
9
+ gem 'rapiro_wrapper', github: 'tk-hamaguchi/rapiro_wrapper'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ ```
19
+ # git clone -b master --depth 1 https://github.com/tk-hamaguchi/rapiro_wrapper.git
20
+ # cd rapiro_wrapper/
21
+ # gem build rapiro_wrapper.gemspec
22
+ # gem install rapiro_wrapper-*.gem
23
+ ```
24
+
25
+ ## Usage1
26
+
27
+ 1. Require gem.
28
+ ``` ruby
29
+ require 'rapiro_wrapper'
30
+ ```
31
+
32
+ 2. Initialize commander. (default: '/dev/ttyAMA0')
33
+ ``` ruby
34
+ rapiro = RapiroWrapper::Body.new
35
+ ```
36
+ 2.1. In another case, initialize with serial port path.
37
+ ``` ruby
38
+ rapiro = RapiroWrapper::Body.new('/dev/tty.usbserial-DA00HMG6')
39
+ ```
40
+ 3. Set pose.
41
+ ``` ruby
42
+ rapiro.head = { left: 40 } ## param is left: 0..90 or right: 0..90
43
+ rapiro.waist = { right: 40 } ## param is left: 0..90 or right: 0..90
44
+ rapiro.right_sholder_roll = { up: 120 } ## param is up: 0..180 (default:0)
45
+ rapiro.right_sholder_pitch = { up: 20 } ## param is hold: 0..50 or open: 0..50
46
+ rapiro.right_hand_grip = { open: 10 } ## param is hold: 0..50 or open: 0..50
47
+ rapiro.left_sholder_roll = { up: 20 } ## param is up: 0..180 (default:0)
48
+ rapiro.left_sholder_pitch = { up: 70 } ## param is up: 0..90 (default:0)
49
+ rapiro.left_hand_grip = { hold: 0 } ## param is hold: 0..50 or open: 0..50
50
+ rapiro.right_foot_yaw = { close: 10 } ## param is close: 0..60 or open: 0..60
51
+ rapiro.right_foot_pitch = { open: 30 } ## param is close: 0..40 or open: 0..40
52
+ rapiro.left_foot_yaw = { open: 0 } ## param is close: 0..60 or open: 0..60
53
+ rapiro.left_foot_pitch = { close: 0 } ## param is close: 0..40 or open: 0..40
54
+ rapiro.eyes = '#808000' ## param is web color code for example #000000 or hash({red: 255, green: 255, blue: 0})
55
+ ```
56
+ 4. Execute. (default: 10)
57
+ ``` ruby
58
+ rapiro.execute!
59
+ ```
60
+ 4.1. In another case, execute with duration.
61
+ ``` ruby
62
+ rapiro.execute!(90) ## param is 0..127
63
+ ```
64
+
65
+
66
+ ## Usage2
67
+ 1. Require gem.
68
+ ``` ruby
69
+ require 'rapiro_wrapper'
70
+ ```
71
+
72
+ 2. Initialize commander with serial port path. (default: '/dev/ttyAMA0')
73
+ ``` ruby
74
+ commander = RapiroWrapper::Commander.new('/dev/tty.usbserial-DA00HMG6')
75
+ ```
76
+
77
+ 3. Execute commands
78
+ ``` ruby
79
+ ## generate command sequences
80
+ sequences = [
81
+ ## param is left: 0..90 or right: 0..90
82
+ RapiroWrapper::Head.new( left: 30 ),
83
+
84
+ ## param is left: 0..90 or right: 0..90
85
+ RapiroWrapper::Waist.new( right: 30 ),
86
+
87
+ ## param is up: 0..180 (default:0)
88
+ RapiroWrapper::RightSholderRoll.new( up: 160 ),
89
+
90
+ ## param is up: 0..90 (default:0)
91
+ RapiroWrapper::RightSholderPitch.new( up: 20 ),
92
+
93
+ ## param is hold: 0..50 or open: 0..50
94
+ RapiroWrapper::RightHandGrip.new( hold: 0 ),
95
+
96
+ ## param is up: 0..180 (default:0)
97
+ RapiroWrapper::LeftSholderRoll.new( up: 30 ),
98
+
99
+ ## param is up: 0..90 (default:0)
100
+ RapiroWrapper::LeftSholderPitch.new( up: 20 ),
101
+
102
+ ## param is hold: 0..50 or open: 0..50
103
+ RapiroWrapper::LeftHandGrip.new( open: 0 ),
104
+
105
+ ## param is close: 0..60 or open: 0..60
106
+ RapiroWrapper::RightFootYaw.new( open: 30 ),
107
+
108
+ ## param is close: 0..40 or open: 0..40
109
+ RapiroWrapper::RightFootPitch.new( open: 5 ),
110
+
111
+ ## param is close: 0..60 or open: 0..60
112
+ RapiroWrapper::LeftFootYaw.new( close: 20 ),
113
+
114
+ ## param is close: 0..40 or open: 0..40
115
+ RapiroWrapper::LeftFootPitch.new( close: 0 ),
116
+
117
+ ## param is web color code for example #000000 or hash
118
+ RapiroWrapper::Eyes.new('#00ff00')
119
+ ]
120
+ ## set duration by milliseconds. (default:10)
121
+ duration = 10
122
+ ## Execute
123
+ commander.execute!(sequences, duration)
124
+ ```
125
+
126
+
127
+ 4. Return to defaults
128
+ ``` ruby
129
+ commander.execute!([])
130
+ ```
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it ( https://github.com/tk-hamaguchi/rapiro_wrapper/fork )
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rapiro_wrapper'
4
+
5
+ commander = RapiroWrapper::Commander.new('/dev/tty.usbserial-DA00HMG6')
6
+
7
+ sleep 20
8
+
9
+ commander.execute!([])
10
+
11
+ sleep 5
12
+
13
+ sequences = [
14
+ ## param is left: 0..90 or right: 0..90
15
+ RapiroWrapper::Head.new(left: 30),
16
+
17
+ ## param is left: 0..90 or right: 0..90
18
+ RapiroWrapper::Waist.new(right: 30),
19
+
20
+ ## param is up: 0..180 (default:0)
21
+ RapiroWrapper::RightSholderRoll.new(up: 160),
22
+
23
+ ## param is up: 0..90 (default:0)
24
+ RapiroWrapper::RightSholderPitch.new(up: 20),
25
+
26
+ ## param is hold: 0..50 or open: 0..50
27
+ RapiroWrapper::RightHandGrip.new(hold: 0),
28
+
29
+ ## param is up: 0..180 (default:0)
30
+ RapiroWrapper::LeftSholderRoll.new(up: 30),
31
+
32
+ ## param is up: 0..90 (default:0)
33
+ RapiroWrapper::LeftSholderPitch.new(up: 20),
34
+
35
+ ## param is hold: 0..50 or open: 0..50
36
+ RapiroWrapper::LeftHandGrip.new(open: 0),
37
+
38
+ ## param is close: 0..60 or open: 0..60
39
+ RapiroWrapper::RightFootYaw.new(open: 30),
40
+
41
+ ## param is close: 0..40 or open: 0..40
42
+ RapiroWrapper::RightFootPitch.new(open: 5),
43
+
44
+ ## param is close: 0..60 or open: 0..60
45
+ RapiroWrapper::LeftFootYaw.new(close: 20),
46
+
47
+ ## param is close: 0..40 or open: 0..40
48
+ RapiroWrapper::LeftFootPitch.new(close: 0),
49
+
50
+ ## param is web color code for example #000000 or hash
51
+ RapiroWrapper::Eyes.new('#00ff00')
52
+ ]
53
+
54
+ commander.execute!(sequences)
55
+
56
+ sleep 5
57
+
58
+ commander.execute!([])
59
+
60
+ sleep 5
61
+
62
+ duration = 5
63
+
64
+ 5.times.each do
65
+ commander.execute!([
66
+ RapiroWrapper::Head.new(left: 10),
67
+ RapiroWrapper::RightSholderRoll.new(up: 160),
68
+ RapiroWrapper::LeftSholderRoll.new(up: 160),
69
+ RapiroWrapper::RightSholderPitch.new(up: 5),
70
+ RapiroWrapper::LeftSholderPitch.new(up: 5),
71
+ RapiroWrapper::RightFootPitch.new(open: 0),
72
+ RapiroWrapper::LeftFootPitch.new(close: 0),
73
+ RapiroWrapper::Eyes.new('#ff0000')
74
+ ], duration)
75
+
76
+ sleep duration * 0.1
77
+
78
+ commander.execute!([
79
+ RapiroWrapper::Head.new(right: 10),
80
+ RapiroWrapper::RightSholderRoll.new(up: 170),
81
+ RapiroWrapper::LeftSholderRoll.new(up: 170),
82
+ RapiroWrapper::RightSholderPitch.new(up: 40),
83
+ RapiroWrapper::LeftSholderPitch.new(up: 40),
84
+ RapiroWrapper::RightFootPitch.new(close: 0),
85
+ RapiroWrapper::LeftFootPitch.new(open: 0),
86
+ RapiroWrapper::Eyes.new('#330000')
87
+ ], duration)
88
+
89
+ sleep duration * 0.1
90
+ end
91
+
92
+ commander.execute!([], 10)
93
+
94
+ sleep 5
95
+
96
+ commander.execute!([
97
+ RapiroWrapper::Head.new(left: 40),
98
+ RapiroWrapper::Waist.new(right: 40),
99
+ RapiroWrapper::LeftHandGrip.new(hold: 0),
100
+ RapiroWrapper::RightHandGrip.new(hold: 0),
101
+ RapiroWrapper::RightSholderRoll.new(up: 90),
102
+ RapiroWrapper::LeftSholderRoll.new(up: 20),
103
+ RapiroWrapper::LeftFootYaw.new(open: 30),
104
+ RapiroWrapper::RightFootYaw.new(open: 20),
105
+ RapiroWrapper::Eyes.new('#003300')
106
+ ], 5)
107
+
108
+ sleep 1
109
+
110
+ commander.execute!([
111
+ RapiroWrapper::Head.new(right: 30),
112
+ RapiroWrapper::Waist.new(left: 30),
113
+ RapiroWrapper::LeftHandGrip.new(hold: 0),
114
+ RapiroWrapper::RightHandGrip.new(hold: 0),
115
+ RapiroWrapper::RightSholderPitch.new(up: 30),
116
+ RapiroWrapper::RightSholderRoll.new(up: 90),
117
+ RapiroWrapper::LeftSholderRoll.new(up: 0),
118
+ RapiroWrapper::LeftFootYaw.new(open: 30),
119
+ RapiroWrapper::RightFootYaw.new(open: 20),
120
+ RapiroWrapper::Eyes.new('#00ff00')
121
+ ], 2)
122
+
123
+ sleep 5
124
+
125
+ commander.execute!([], 10)
126
+
127
+ duration = 7
128
+
129
+ 2.times.each do
130
+ commander.execute!([
131
+ RapiroWrapper::Head.new(left: 30)
132
+ ], duration)
133
+
134
+ sleep duration * 0.1
135
+
136
+ commander.execute!([
137
+ RapiroWrapper::Head.new(right: 30)
138
+ ], duration)
139
+
140
+ sleep duration * 0.1
141
+ end
142
+
143
+ commander.execute!([], 10)
144
+
145
+ sleep 1
146
+
147
+ commander.execute!(sequences, duration)
@@ -0,0 +1,23 @@
1
+ require 'rapiro_wrapper/version'
2
+ require 'rapiro_wrapper/command'
3
+ require 'rapiro_wrapper/commander'
4
+ require 'rapiro_wrapper/servo_motor'
5
+ require 'rapiro_wrapper/servo_motor/head'
6
+ require 'rapiro_wrapper/servo_motor/waist'
7
+ require 'rapiro_wrapper/servo_motor/right_sholder_roll'
8
+ require 'rapiro_wrapper/servo_motor/right_sholder_pitch'
9
+ require 'rapiro_wrapper/servo_motor/right_hand_grip'
10
+ require 'rapiro_wrapper/servo_motor/left_sholder_roll'
11
+ require 'rapiro_wrapper/servo_motor/left_sholder_pitch'
12
+ require 'rapiro_wrapper/servo_motor/left_hand_grip'
13
+ require 'rapiro_wrapper/servo_motor/right_foot_yaw'
14
+ require 'rapiro_wrapper/servo_motor/left_foot_yaw'
15
+ require 'rapiro_wrapper/servo_motor/right_foot_pitch'
16
+ require 'rapiro_wrapper/servo_motor/left_foot_pitch'
17
+ require 'rapiro_wrapper/led'
18
+ require 'rapiro_wrapper/led/eyes'
19
+ require 'rapiro_wrapper/body'
20
+
21
+ # RapiroWrapper
22
+ module RapiroWrapper
23
+ end
@@ -0,0 +1,43 @@
1
+ module RapiroWrapper
2
+ # Controll class for RAPIRO
3
+ class Body
4
+ def initialize(device = '/dev/ttyAMA0')
5
+ @commander = RapiroWrapper::Commander.new(device)
6
+ servo_class = RapiroWrapper::ServoMotor.find_servos
7
+
8
+ @servos = servo_class.inject({}) do |hash, klass|
9
+ class_name = klass.to_s
10
+ snake_case = class_name.gsub(/::/, '/')
11
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
12
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
13
+ .tr('-', '_').downcase
14
+ hash[snake_case.split('/').last] = klass
15
+ hash
16
+ end
17
+ @servos['eyes'] = RapiroWrapper::Eyes
18
+ @servos.each do |s, k|
19
+ self.class.class_eval <<-EOF
20
+ def #{s}=(val)
21
+ @#{s} = #{k}.new(val)
22
+ end
23
+
24
+ def #{s}
25
+ @#{s}
26
+ end
27
+ EOF
28
+ instance_variable_set('@'.concat(s).to_sym, k.new)
29
+ end
30
+ end
31
+
32
+ def sequences(duration = 10)
33
+ @commander.sequences(
34
+ @servos.keys.map { |k| instance_variable_get('@'.concat(k).to_sym) },
35
+ duration
36
+ )
37
+ end
38
+
39
+ def execute!(duration = 10)
40
+ @commander.write(sequences(duration))
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module RapiroWrapper
2
+ # Command class for RAPIRO
3
+ class Command
4
+ def initialize(sequences = [])
5
+ @sequences = sequences
6
+ end
7
+
8
+ def to_sequence(duration = 10)
9
+ targets = RapiroWrapper::ServoMotor.find_servos + [RapiroWrapper::Eyes]
10
+ seq = targets.inject([]) do |ary, servo|
11
+ s = @sequences.find { |item| item.instance_of?(servo) }
12
+ ary << (s ? s : servo.new)
13
+ ary
14
+ end
15
+
16
+ format("#P#{seq.map(&:to_code).join}T%03d", duration)
17
+ end
18
+ end
19
+ end