ruby-player 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/ranger_spec.rb CHANGED
@@ -1,67 +1,158 @@
1
1
  require "ruby-player"
2
2
 
3
+ include Player
3
4
  describe Player::Ranger do
4
- before do
5
- @cl = Player::Client.connect("localhost")
6
- @ranger = @cl[:ranger,0]
7
- @cl.read
5
+ before do
6
+ @client = mock("Client")
7
+ @client.stub!(:write)
8
+
9
+ @ranger = Player::Ranger.new(
10
+ Player::DevAddr.new(host: 0, robot:0, interface: PLAYER_RANGER_CODE, index: 0),
11
+ @client,
12
+ :debug
13
+ )
14
+ end
15
+
16
+ it 'should have default values' do
17
+ @ranger.rangers.should eql([])
18
+ @ranger.intensities.should eql([])
19
+ @ranger.geom.should eql(px:0.0, py:0.0, pz:0.0, proll:0.0, ppitch:0.0, pyaw:0.0, sw:0.0, sl:0.0, sh:0.0, sensors: [])
20
+ @ranger.config.should eql(min_angle: 0.0, max_angle: 0.0, angular_res: 0.0, min_range: 0.0, max_range: 0.0, range_res: 0.0, frequecy: 0.0)
8
21
  end
9
22
 
10
- it 'should have ranges' do
11
- @ranger.ranges.should eq([3.0, 3.0])
23
+ it 'should query geometry' do
24
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_GEOM)
25
+ @ranger.query_geom
12
26
  end
13
27
 
14
- it 'should have intensities' do
15
- @ranger.intensities.should eq([0.0, 0.0])
28
+ it 'should set power state' do
29
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [1].pack("N"))
30
+ @ranger.turn_on!
31
+
32
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [0].pack("N"))
33
+ @ranger.turn_off!
16
34
  end
17
35
 
18
- it 'should have bearings' do
19
- @ranger.bearings.size.should eql(2)
36
+ it 'should enable\disable intensity ' do
37
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [1].pack("N"))
38
+ @ranger.intensity_enable!
39
+
40
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [0].pack("N"))
41
+ @ranger.intensity_disable!
20
42
  end
21
43
 
22
- it 'should have element count' do
23
- @ranger.element_count.should eq(0)
44
+ it 'should set config' do
45
+ config = {
46
+ min_angle: 0.1,
47
+ max_angle: 0.9,
48
+ angular_res: 0.01,
49
+ min_range: 2.0,
50
+ max_range: 4.0,
51
+ range_res: 1.0,
52
+ frequecy: 60.0
53
+ }
54
+
55
+ msg = config.values.pack("G*")
56
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_SET_CONFIG, msg)
57
+ @ranger.set_config(config)
58
+ end
59
+
60
+ it 'should query config' do
61
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_CONFIG)
62
+ @ranger.query_config
63
+ end
64
+
65
+ it 'should fill rangers data' do
66
+ rangers = [0.4, 0.3, 0.2, 0.1]
67
+ @ranger.fill(
68
+ Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_DATA, PLAYER_RANGER_DATA_RANGE, 0.0, 0, 20]),
69
+ ([4,0] + rangers).pack("NNG*")
70
+ )
71
+ @ranger.rangers.should eql(rangers)
24
72
  end
25
73
 
26
- it 'should have power control' do
27
- pending "Don't work with Player/Stage"
28
- #@ranger.power_enable = false
29
- #@ranger.power_enable = true
74
+ it 'should fill intensities data' do
75
+ intns = [0.1, 0.2, 0.3, 0.4]
76
+ @ranger.fill(
77
+ Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_DATA, PLAYER_RANGER_DATA_INTNS, 0.0, 0, 20]),
78
+ ([4,0] + intns).pack("NNG*")
79
+ )
80
+
81
+ @ranger.intensities.should eql(intns)
30
82
  end
31
83
 
32
- it 'should have intensity control' do
33
- pending "Don't work with Player/Stage"
34
- #@ranger.intensity_enable = false
35
- #@ranger.intensity_enable = true
84
+ it 'should fill geom data' do
85
+ geom = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0,
86
+ 2, 0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 2.0, 1.0, 1.0, 0.0, 0.0, -1.0,
87
+ 2, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
88
+
89
+ msg = geom.pack("G9NNG12NNG6")
90
+ @ranger.fill(
91
+ Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_DATA, PLAYER_RANGER_DATA_GEOM, 0.0, 0, msg.bytesize]),
92
+ msg
93
+ )
94
+
95
+ @ranger.geom.should eql(
96
+ px: 1.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: 0.0, sw: 2.0, sl: 2.0, sh: 2.0,
97
+ sensors: [
98
+ { px: 1.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: 1.0, sw: 0.5, sl: 0.5, sh: 0.5 },
99
+ { px: 2.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: -1.0, sw: 0.5, sl: 0.5, sh: 0.5 }
100
+ ]
101
+ )
36
102
  end
37
103
 
38
- it 'should porovide method to configurate' do
39
- pending "Don't work with Player/Stage"
40
- config = {
41
- min_angle: 0.3,
42
- max_angle: 1.0,
43
- angular_res: 0.1,
44
- min_range: 0.3,
45
- max_range: 1,
46
- range_res: 0.1,
47
- frequecy: 2
48
- }
104
+ it 'should get geom by request' do
105
+ geom = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0,
106
+ 2, 0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 2.0, 1.0, 1.0, 0.0, 0.0, -1.0,
107
+ 2, 0, 0.5,
108
+ 0.5, 0.5, 0.5, 0.5, 0.5]
49
109
 
110
+ msg = geom.pack("G9NNG12NNG6")
111
+ @ranger.handle_response(
112
+ Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_RESP_ACK, PLAYER_RANGER_REQ_GET_GEOM, 0.0, 0, msg.bytesize]),
113
+ msg
114
+ )
50
115
 
51
- #@ranger.set_config(config)
116
+ @ranger.geom.should eql(
117
+ px: 1.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: 0.0, sw: 2.0, sl: 2.0, sh: 2.0,
118
+ sensors: [
119
+ { px: 1.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: 1.0, sw: 0.5, sl: 0.5, sh: 0.5 },
120
+ { px: 2.0, py: 1.0, pz: 1.0, proll: 0.0, ppitch: 0.0, pyaw: -1.0, sw: 0.5, sl: 0.5, sh: 0.5 }
121
+ ]
122
+ )
52
123
  end
53
124
 
54
- it 'should have configuration' do
55
- @ranger.config.should eq(
56
- :min_range=>0.1,
57
- :max_range=>3.0,
58
- :angular_res=>0.5235987755982988,
59
- :range_res=>0.02,
60
- :frequecy=>10.0
125
+ it 'should get config by request' do
126
+ config = {
127
+ min_angle: 0.1,
128
+ max_angle: 0.9,
129
+ angular_res: 0.01,
130
+ min_range: 2.0,
131
+ max_range: 4.0,
132
+ range_res: 1.0,
133
+ frequecy: 60.0
134
+ }
135
+
136
+ msg = config.values.pack("G*")
137
+ @ranger.handle_response(
138
+ Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_RESP_ACK, PLAYER_RANGER_REQ_GET_CONFIG, 0.0, 0, msg.bytesize]),
139
+ msg
61
140
  )
141
+
142
+ @ranger.config.should eql(config)
143
+ end
144
+
145
+ it 'should not puts warn message for ACK subtypes 2..4' do
146
+ @ranger.should_not_receive(:unexpected_message)
147
+ (2..4).each do |i|
148
+ @ranger.handle_response(
149
+ Player::Header.from_a([0,0,4,0, PLAYER_MSGTYPE_RESP_ACK, i, 0.0, 0, 0]),
150
+ "")
151
+ end
62
152
  end
63
153
 
64
- after do
65
- @cl.close unless @cl.closed?
154
+ def should_send_message(*args)
155
+ @ranger.should_receive(:send_message)
156
+ .with(*args)
66
157
  end
67
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-player
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-08 00:00:00.000000000 Z
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: ffi
16
- requirement: &20764720 !ruby/object:Gem::Requirement
15
+ name: isna
16
+ requirement: &5675900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0
21
+ version: 0.0.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20764720
24
+ version_requirements: *5675900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &20763500 !ruby/object:Gem::Requirement
27
+ requirement: &5675380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20763500
35
+ version_requirements: *5675380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &20762720 !ruby/object:Gem::Requirement
38
+ requirement: &5674800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *20762720
46
+ version_requirements: *5674800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &20761980 !ruby/object:Gem::Requirement
49
+ requirement: &5674360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20761980
57
+ version_requirements: *5674360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &20760700 !ruby/object:Gem::Requirement
60
+ requirement: &5673740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20760700
68
+ version_requirements: *5673740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redcarpet
71
- requirement: &20759960 !ruby/object:Gem::Requirement
71
+ requirement: &5673080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,18 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *20759960
79
+ version_requirements: *5673080
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &5672240 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *5672240
80
91
  description: Ruby Player - Ruby client library for Player (tools for robots)
81
92
  email:
82
93
  - atimin@gmail.com
@@ -85,24 +96,23 @@ extensions: []
85
96
  extra_rdoc_files: []
86
97
  files:
87
98
  - .gitignore
99
+ - .travis.yml
88
100
  - Gemfile
101
+ - Guardfile
89
102
  - LICENSE
90
103
  - README.md
91
104
  - Rakefile
92
105
  - TODO.md
106
+ - examples/simple_example.rb
107
+ - examples/world/test.cfg
108
+ - examples/world/test.world
93
109
  - lib/ruby-player.rb
94
- - lib/ruby-player/c_type.rb
95
- - lib/ruby-player/c_type/bbox3d_t.rb
96
- - lib/ruby-player/c_type/client_t.rb
97
- - lib/ruby-player/c_type/devaddr.rb
98
- - lib/ruby-player/c_type/device_t.rb
99
- - lib/ruby-player/c_type/diagnostic.rb
100
- - lib/ruby-player/c_type/pose3d_t.rb
101
- - lib/ruby-player/c_type/position2d_t.rb
102
- - lib/ruby-player/c_type/ranger_t.rb
103
- - lib/ruby-player/c_type/sockaddr_in_t.rb
104
110
  - lib/ruby-player/client.rb
105
111
  - lib/ruby-player/common.rb
112
+ - lib/ruby-player/constants.rb
113
+ - lib/ruby-player/dev_addr.rb
114
+ - lib/ruby-player/device.rb
115
+ - lib/ruby-player/header.rb
106
116
  - lib/ruby-player/position2d.rb
107
117
  - lib/ruby-player/ranger.rb
108
118
  - lib/ruby-player/version.rb
@@ -110,8 +120,6 @@ files:
110
120
  - spec/client_spec.rb
111
121
  - spec/position2d_spec.rb
112
122
  - spec/ranger_spec.rb
113
- - spec/world/test.cfg
114
- - spec/world/test.world
115
123
  homepage: http://www.github.com/flipback/ruby-player
116
124
  licenses: []
117
125
  post_install_message:
@@ -1,36 +0,0 @@
1
- # Ruby Player - Ruby client library for Player (tools for robots)
2
- #
3
- # Copyright (C) 2012 Timin Aleksey
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require "ffi"
15
-
16
- module Player
17
- module CType
18
- PLAYER_MAX_DRIVER_STRING_LEN = 64
19
- # Device access mode: open
20
- PLAYER_OPEN_MODE = 1
21
- #Device access mode: close
22
- PLAYER_CLOSE_MODE = 2
23
- #Device access mode: error
24
- PLAYER_ERROR_MODE = 3
25
- end
26
- end
27
-
28
- #structs
29
- require File.dirname(__FILE__) + "/c_type/sockaddr_in_t"
30
- require File.dirname(__FILE__) + "/c_type/devaddr"
31
- require File.dirname(__FILE__) + "/c_type/device_t"
32
- require File.dirname(__FILE__) + "/c_type/pose3d_t"
33
- require File.dirname(__FILE__) + "/c_type/bbox3d_t"
34
- require File.dirname(__FILE__) + "/c_type/position2d_t"
35
- require File.dirname(__FILE__) + "/c_type/ranger_t"
36
- require File.dirname(__FILE__) + "/c_type/client_t"
@@ -1,24 +0,0 @@
1
- # Ruby Player - Ruby client library for Player (tools for robots)
2
- #
3
- # Copyright (C) 2012 Timin Aleksey
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
-
15
- module Player
16
- module CType
17
- class BBox3dStruct < FFI::Struct
18
- layout :sw, :double,
19
- :sl, :double,
20
- :sh, :double
21
- end
22
- end
23
- end
24
-
@@ -1,36 +0,0 @@
1
- # Ruby Player - Ruby client library for Player (tools for robots)
2
- #
3
- # Copyright (C) 2012 Timin Aleksey
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
-
15
- module Player
16
- module CType
17
- class ClientStruct < FFI::Struct
18
- layout :id, :pointer,
19
- :host, :string,
20
- :port, :int,
21
- :transport, :int,
22
- :server, SockaddrInStruct,
23
- :connected, :int,
24
- :retry_limit, :int,
25
- :retry_time, :double,
26
- :mode, :uint8,
27
- :data_requested, :int,
28
- :data_received, :int
29
- #TODO Added devinfo, devicem, qitems
30
- #:data, :string,
31
- #:write_xdrdata, :string,
32
- #:read_xdrdata, :string,
33
- #:read_xdrdata_len, :size_t
34
- end
35
- end
36
- end