ruby-player 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ include Player
4
+ describe Player::Actuator do
5
+ before do
6
+ client = mock_client
7
+
8
+ @actarray = Player::ActArray.new(
9
+ Player::DevAddr.new(host: 0, robot:0, interface: PLAYER_ACTARRAY_CODE, index: 0),
10
+ client
11
+ )
12
+
13
+ mock_sending_message(@actarray)
14
+ @act = @actarray[0]
15
+ end
16
+
17
+ it 'should have joint number' do
18
+ @act.joint.should eql(0)
19
+ end
20
+
21
+ it 'should have default state' do
22
+ @act.state.should eql(position: 0.0, speed: 0.0, acceleration: 0.0, current: 0.0, state: 0 )
23
+ @act.geom.should eql(type: 0, length: 0.0,
24
+ proll: 0.0, ppitch: 0.0, pyaw: 0.0,
25
+ px: 0.0, py: 0.0, pz: 0.0,
26
+ min: 0.0, centre: 0.0, max: 0.0, home: 0.0,
27
+ config_speed: 0.0, hasbreaks: 0
28
+ )
29
+ end
30
+
31
+ it 'should set speed config ' do
32
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_ACTARRAY_REQ_SPEED, [0, 0.2].pack("Ng"))
33
+ @act.set_speed_config(0.2)
34
+ end
35
+
36
+ it 'should set accel config' do
37
+ should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_ACTARRAY_REQ_ACCEL, [0, 0.3].pack("Ng"))
38
+ @act.set_accel_config(0.3)
39
+ end
40
+
41
+ it 'should set position joint' do
42
+ should_send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_POS, [0, 0.4].pack("Ng"))
43
+ @act.set_position(0.4)
44
+ end
45
+
46
+ it 'should set speed ' do
47
+ should_send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_SPEED, [0, 0.5].pack("Ng"))
48
+ @act.set_speed(0.5)
49
+ end
50
+
51
+ it 'should go to nome' do
52
+ should_send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_HOME, [0].pack("N"))
53
+ @act.go_home!
54
+ end
55
+
56
+ it 'should be idle' do
57
+ @act.should_receive(:state).and_return(state: 0)
58
+ @act.idle?.should be_false
59
+
60
+ @act.should_receive(:state).and_return(state: PLAYER_ACTARRAY_ACTSTATE_IDLE)
61
+ @act.idle?.should be_true
62
+ end
63
+
64
+ it 'should be moving' do
65
+ @act.should_receive(:state).and_return(state: 0)
66
+ @act.moving?.should be_false
67
+
68
+ @act.should_receive(:state).and_return(state: PLAYER_ACTARRAY_ACTSTATE_MOVING)
69
+ @act.moving?.should be_true
70
+ end
71
+
72
+ it 'should be braked' do
73
+ @act.should_receive(:state).and_return(state: 0)
74
+ @act.braked?.should be_false
75
+
76
+ @act.should_receive(:state).and_return(state: PLAYER_ACTARRAY_ACTSTATE_BRAKED)
77
+ @act.braked?.should be_true
78
+ end
79
+
80
+ it 'should be stalled' do
81
+ @act.should_receive(:state).and_return(state: 0)
82
+ @act.stalled?.should be_false
83
+
84
+ @act.should_receive(:state).and_return(state: PLAYER_ACTARRAY_ACTSTATE_STALLED)
85
+ @act.stalled?.should be_true
86
+ end
87
+
88
+ end
89
+
data/spec/client_spec.rb CHANGED
@@ -122,6 +122,7 @@ describe Player::Client do
122
122
  mock_subscribe(PLAYER_POSITION2D_CODE)
123
123
 
124
124
  pos2d = @cl.subscribe("position2d")
125
+ pos2d.should be_an_instance_of(Player::Position2d)
125
126
  pos2d.addr.interface_name.should eql("position2d")
126
127
  pos2d.addr.index.should eql(0)
127
128
  end
@@ -130,6 +131,7 @@ describe Player::Client do
130
131
  mock_subscribe(PLAYER_RANGER_CODE, 1)
131
132
 
132
133
  ranger = @cl.subscribe(:ranger, index: 1)
134
+ ranger.should be_an_instance_of(Player::Ranger)
133
135
  ranger.addr.interface_name.should eql("ranger")
134
136
  ranger.addr.index.should eql(1)
135
137
  end
@@ -138,10 +140,28 @@ describe Player::Client do
138
140
  mock_subscribe(PLAYER_POWER_CODE, 2)
139
141
 
140
142
  power = @cl.subscribe(:power, index: 2)
143
+ power.should be_an_instance_of(Player::Power)
141
144
  power.addr.interface_name.should eql("power")
142
145
  power.addr.index.should eql(2)
143
146
  end
144
147
 
148
+ it "should describe to gripper:3" do
149
+ mock_subscribe(PLAYER_GRIPPER_CODE, 3)
150
+
151
+ gripper = @cl.subscribe(:gripper, index: 3)
152
+ gripper.should be_an_instance_of(Player::Gripper)
153
+ gripper.addr.interface_name.should eql("gripper")
154
+ gripper.addr.index.should eql(3)
155
+ end
156
+
157
+ it "should describe to actarray:4" do
158
+ mock_subscribe(PLAYER_ACTARRAY_CODE, 4)
159
+
160
+ actarray = @cl.subscribe(:actarray, index: 4)
161
+ actarray.should be_an_instance_of(Player::ActArray)
162
+ actarray.addr.interface_name.should eql("actarray")
163
+ actarray.addr.index.should eql(4)
164
+ end
145
165
  end
146
166
 
147
167
  private
@@ -24,10 +24,10 @@ describe Player::Position2d do
24
24
 
25
25
  it 'should set motor power state' do
26
26
  should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_POSITION2D_REQ_MOTOR_POWER, [0].pack("N"))
27
- @pos2d.turn_off!
27
+ @pos2d.power_off!
28
28
 
29
29
  should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_POSITION2D_REQ_MOTOR_POWER, [1].pack("N"))
30
- @pos2d.turn_on!
30
+ @pos2d.power_on!
31
31
  end
32
32
 
33
33
  it 'should set velocity mode' do
data/spec/ranger_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe Player::Ranger do
15
15
  it 'should have default values' do
16
16
  @ranger.rangers.should eql([])
17
17
  @ranger.intensities.should eql([])
18
- @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: [])
18
+ @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)
19
19
  @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)
20
20
  end
21
21
 
@@ -26,10 +26,10 @@ describe Player::Ranger do
26
26
 
27
27
  it 'should set power state' do
28
28
  should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [1].pack("N"))
29
- @ranger.turn_on!
29
+ @ranger.power_on!
30
30
 
31
31
  should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [0].pack("N"))
32
- @ranger.turn_off!
32
+ @ranger.power_off!
33
33
  end
34
34
 
35
35
  it 'should enable\disable intensity ' do
@@ -67,7 +67,7 @@ describe Player::Ranger do
67
67
  Player::Header.from_a([0,0,PLAYER_RANGER_CODE,0, PLAYER_MSGTYPE_DATA, PLAYER_RANGER_DATA_RANGE, 0.0, 0, 20]),
68
68
  ([4,0] + rangers).pack("NNG*")
69
69
  )
70
- @ranger.rangers.should eql(rangers)
70
+ @ranger.collect { |r| r.range }.should eql(rangers)
71
71
  end
72
72
 
73
73
  it 'should fill intensities data' do
@@ -77,7 +77,7 @@ describe Player::Ranger do
77
77
  ([4,0] + intns).pack("NNG*")
78
78
  )
79
79
 
80
- @ranger.intensities.should eql(intns)
80
+ @ranger.collect { |r| r.intensity }.should eql(intns)
81
81
  end
82
82
 
83
83
  it 'should fill geom data' do
@@ -91,13 +91,9 @@ describe Player::Ranger do
91
91
  msg
92
92
  )
93
93
 
94
- @ranger.geom.should eql(
95
- 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,
96
- sensors: [
97
- { 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 },
98
- { 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 }
99
- ]
100
- )
94
+ @ranger.geom.should eql(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)
95
+ @ranger[0].geom.should eql(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)
96
+ @ranger[1].geom.should eql(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)
101
97
  end
102
98
 
103
99
  it 'should get geom by request' do
@@ -112,13 +108,9 @@ describe Player::Ranger do
112
108
  msg
113
109
  )
114
110
 
115
- @ranger.geom.should eql(
116
- 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,
117
- sensors: [
118
- { 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 },
119
- { 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 }
120
- ]
121
- )
111
+ @ranger.geom.should eql(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)
112
+ @ranger[0].geom.should eql(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)
113
+ @ranger[1].geom.should eql(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)
122
114
  end
123
115
 
124
116
  it 'should get config by request' do
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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-16 00:00:00.000000000 Z
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: isna
16
- requirement: &18940320 !ruby/object:Gem::Requirement
16
+ requirement: &19658800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18940320
24
+ version_requirements: *19658800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &18939820 !ruby/object:Gem::Requirement
27
+ requirement: &19658340 !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: *18939820
35
+ version_requirements: *19658340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &18939180 !ruby/object:Gem::Requirement
38
+ requirement: &19657880 !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: *18939180
46
+ version_requirements: *19657880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &18938680 !ruby/object:Gem::Requirement
49
+ requirement: &19657500 !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: *18938680
57
+ version_requirements: *19657500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &18938080 !ruby/object:Gem::Requirement
60
+ requirement: &19657040 !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: *18938080
68
+ version_requirements: *19657040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redcarpet
71
- requirement: &18937400 !ruby/object:Gem::Requirement
71
+ requirement: &19656620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *18937400
79
+ version_requirements: *19656620
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &18936740 !ruby/object:Gem::Requirement
82
+ requirement: &19656200 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *18936740
90
+ version_requirements: *19656200
91
91
  description: Ruby Player - Ruby client library for Player (tools for robots)
92
92
  email:
93
93
  - atimin@gmail.com
@@ -108,6 +108,8 @@ files:
108
108
  - examples/world/test.cfg
109
109
  - examples/world/test.world
110
110
  - lib/ruby-player.rb
111
+ - lib/ruby-player/actarray.rb
112
+ - lib/ruby-player/actuator.rb
111
113
  - lib/ruby-player/client.rb
112
114
  - lib/ruby-player/common.rb
113
115
  - lib/ruby-player/constants.rb
@@ -118,8 +120,11 @@ files:
118
120
  - lib/ruby-player/position2d.rb
119
121
  - lib/ruby-player/power.rb
120
122
  - lib/ruby-player/ranger.rb
123
+ - lib/ruby-player/sensor.rb
121
124
  - lib/ruby-player/version.rb
122
125
  - ruby-player.gemspec
126
+ - spec/actarray_spec.rb
127
+ - spec/actuator_spec.rb
123
128
  - spec/client_spec.rb
124
129
  - spec/gripper_spec.rb
125
130
  - spec/position2d_spec.rb