ruby-player 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +2 -0
- data/LICENSE +675 -0
- data/README.md +54 -0
- data/Rakefile +21 -0
- data/TODO.md +91 -0
- data/lib/ruby-player/c_type/bbox3d_t.rb +24 -0
- data/lib/ruby-player/c_type/client_t.rb +36 -0
- data/lib/ruby-player/c_type/devaddr.rb +24 -0
- data/lib/ruby-player/c_type/device_t.rb +35 -0
- data/lib/ruby-player/c_type/diagnostic.rb +22 -0
- data/lib/ruby-player/c_type/pose3d_t.rb +27 -0
- data/lib/ruby-player/c_type/position2d_t.rb +32 -0
- data/lib/ruby-player/c_type/ranger_t.rb +42 -0
- data/lib/ruby-player/c_type/sockaddr_in_t.rb +24 -0
- data/lib/ruby-player/c_type.rb +36 -0
- data/lib/ruby-player/client.rb +116 -0
- data/lib/ruby-player/common.rb +29 -0
- data/lib/ruby-player/position2d.rb +175 -0
- data/lib/ruby-player/ranger.rb +136 -0
- data/lib/ruby-player/version.rb +17 -0
- data/lib/ruby-player.rb +23 -0
- data/ruby-player.gemspec +27 -0
- data/spec/client_spec.rb +32 -0
- data/spec/position2d_spec.rb +77 -0
- data/spec/ranger_spec.rb +67 -0
- data/spec/world/test.cfg +18 -0
- data/spec/world/test.world +89 -0
- metadata +140 -0
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Ruby Player - Ruby client library for Player (tools for robots)
|
2
|
+
|
3
|
+
Summary
|
4
|
+
-------------------------------------
|
5
|
+
Ruby Player provide high level client library to access to Player server.
|
6
|
+
It are using the FFI for binding with playerc C client library.
|
7
|
+
|
8
|
+
API coverage
|
9
|
+
-------------------------------------
|
10
|
+
The list of support objects and devices of Player.
|
11
|
+
|
12
|
+
* Client object
|
13
|
+
* Position2d
|
14
|
+
|
15
|
+
Install
|
16
|
+
-------------------------------------
|
17
|
+
Currently (2012-01-07) the Ruby Player are developing and testing with Player 3.1.0 latest svn version
|
18
|
+
and Stage v4.1.0. See them user guides for installation.
|
19
|
+
|
20
|
+
After installation Player/Stage run:
|
21
|
+
|
22
|
+
`gem install ruby-player`
|
23
|
+
|
24
|
+
For testing library in root dir library:
|
25
|
+
|
26
|
+
player spec/world/test.cfg
|
27
|
+
bundle exec rake spec
|
28
|
+
|
29
|
+
Example
|
30
|
+
-------------------------------------
|
31
|
+
|
32
|
+
require 'ruby-player'
|
33
|
+
Player::Client.connect("localhost") do |robot|
|
34
|
+
pos2d = robot[:position2d, 0]
|
35
|
+
pos2d.set_vel(1, 0, 0.2)
|
36
|
+
robot.loop do
|
37
|
+
puts "Position: x=#{pos2d.px}, y=#{pos2d.py}, a=#{pos2d.pa}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
References
|
42
|
+
-------------------------------------
|
43
|
+
|
44
|
+
[Home page](http://www.github.com/flipback/ruby-player)
|
45
|
+
|
46
|
+
[Player project](http://playerstage.sourceforge.net/)
|
47
|
+
|
48
|
+
[Stage project](https://github.com/rtv/Stage)
|
49
|
+
|
50
|
+
[C API Player](http://playerstage.sourceforge.net/doc/Player-3.0.2/player/group__player__clientlib__libplayerc.html)
|
51
|
+
|
52
|
+
Authors
|
53
|
+
-------------------------------------
|
54
|
+
Aleksey Timin <atimin@gmail.com>
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec)
|
17
|
+
|
18
|
+
task :default => :spec
|
19
|
+
|
20
|
+
require 'yard'
|
21
|
+
YARD::Rake::YardocTask.new
|
data/TODO.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
For supported devices
|
3
|
+
-------------------------------------
|
4
|
+
**ranger** - The ranger proxy provides an interface to ranger sensor devices.
|
5
|
+
|
6
|
+
1. Get geometry of device and sensors
|
7
|
+
2. Get 3d scan points (x,y,z)
|
8
|
+
|
9
|
+
**position2d** - The position2d proxy provides an interface to a mobile robot base, such as the ActiveMedia Pioneer series.
|
10
|
+
1. Set speed and heading - wrap C `func playerc_position2d_set_cmd_vel_head`
|
11
|
+
2. Move to point - wrap C funcs `playerc_position2d_set_cmd_pose_with_vel` and `playerc_position2d_set_cmd_pose`
|
12
|
+
|
13
|
+
Candidates for support
|
14
|
+
--------------------------------------
|
15
|
+
|
16
|
+
**actarray** - The actarray proxy provides an interface to actuator arrays such as the ActivMedia Pioneer Arm.
|
17
|
+
|
18
|
+
**blobfinder** - The blobfinder proxy provides an interface to color blob detectors such as the ACTS vision system.
|
19
|
+
|
20
|
+
**graphics2d** - The graphics2d proxy provides an interface to the graphics2d.
|
21
|
+
|
22
|
+
**graphics3d** - The graphics3d proxy provides an interface to the graphics3d.
|
23
|
+
|
24
|
+
**gripper** - The gripper proxy provides an interface to the gripper.
|
25
|
+
|
26
|
+
**simulation** - The simulation proxy is used to interact with objects in a simulation.
|
27
|
+
|
28
|
+
Device proxies are not started to develop
|
29
|
+
--------------------------------------
|
30
|
+
|
31
|
+
**aio** - The aio proxy provides an interface to the analog input/output sensors.
|
32
|
+
|
33
|
+
**audio** - The audio proxy provides access to drivers supporting the audio_interface.
|
34
|
+
|
35
|
+
**blinkenlight** - The blinkenlight proxy provides an interface to a (possibly colored and/or blinking) indicator light.
|
36
|
+
|
37
|
+
**bumper** - The bumper proxy provides an interface to the bumper sensors built into robots such as the RWI B21R.
|
38
|
+
|
39
|
+
**camera** - The camera proxy can be used to get images from a camera.
|
40
|
+
|
41
|
+
**dio** - The dio proxy provides an interface to the digital input/output sensors.
|
42
|
+
|
43
|
+
**fiducial** - The fiducial proxy provides an interface to a fiducial detector.
|
44
|
+
|
45
|
+
**health** - The health proxy provides an interface to the HEALTH Module.
|
46
|
+
|
47
|
+
**ir** - The ir proxy provides an interface to the ir sensors built into robots such as the RWI B21R.
|
48
|
+
|
49
|
+
**joystick** - The joystick proxy can be used to get images from a joystick.
|
50
|
+
|
51
|
+
**laser** - The laser proxy provides an interface to scanning laser range finders such as the sicklms200.
|
52
|
+
|
53
|
+
**limb** - The limb proxy provides an interface to limbs using forward/inverse kinematics, such as the ActivMedia Pioneer Arm.
|
54
|
+
|
55
|
+
**localize** - The localize proxy provides an interface to localization drivers.
|
56
|
+
|
57
|
+
**log** - The log proxy provides start/stop control of data logging.
|
58
|
+
|
59
|
+
**map** - The map proxy provides an interface to a map.
|
60
|
+
|
61
|
+
**vectormap** - The vectormap proxy provides an interface to a map of geometric features.
|
62
|
+
|
63
|
+
**opaque** - The opaque proxy provides an interface for generic messages to drivers.
|
64
|
+
|
65
|
+
**planner** - The planner proxy provides an interface to a 2D motion planner.
|
66
|
+
|
67
|
+
**position1d** - The position1d proxy provides an interface to 1 DOF actuator such as a linear or rotational actuator.
|
68
|
+
|
69
|
+
**position3d** - The position3d proxy provides an interface to a mobile robot base, such as the Segway RMP series.
|
70
|
+
|
71
|
+
**power** - The power proxy provides an interface through which battery levels can be monitored.
|
72
|
+
|
73
|
+
**ptz** - The ptz proxy provides an interface to pan-tilt units such as the Sony PTZ camera.
|
74
|
+
|
75
|
+
**sonar** - The sonar proxy provides an interface to the sonar range sensors built into robots such as the ActiveMedia Pioneer series.
|
76
|
+
|
77
|
+
**wifi** - The wifi proxy is used to query the state of a wireless network.
|
78
|
+
|
79
|
+
**speech** - The speech proxy provides an interface to a speech synthesis system.
|
80
|
+
|
81
|
+
**speech recognition** - The speech recognition proxy provides an interface to a speech recognition system.
|
82
|
+
|
83
|
+
**rfid** - The rfid proxy provides an interface to a RFID reader.
|
84
|
+
|
85
|
+
**pointcloud3d** - The pointcloud3d proxy provides an interface to a pointcloud3d device.
|
86
|
+
|
87
|
+
**stereo** - The stereo proxy provides an interface to a stereo device.
|
88
|
+
|
89
|
+
**imu** - The imu proxy provides an interface to an Inertial Measurement Unit.
|
90
|
+
|
91
|
+
**wsn** - The wsn proxy provides an interface to a Wireless Sensor Network.
|
@@ -0,0 +1,24 @@
|
|
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
|
+
|
@@ -0,0 +1,36 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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 DevAddrStruct < FFI::Struct
|
18
|
+
layout :host, :uint32,
|
19
|
+
:robot, :uint32,
|
20
|
+
:interf, :uint16,
|
21
|
+
:index, :uint16
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 DeviceStruct < FFI::Struct
|
18
|
+
layout :id, :pointer,
|
19
|
+
:client, :pointer,
|
20
|
+
:addr, DevAddrStruct,
|
21
|
+
:drivername, [:char, PLAYER_MAX_DRIVER_STRING_LEN],
|
22
|
+
:subcribed, :int,
|
23
|
+
:datatime, :double,
|
24
|
+
:lasttime, :double,
|
25
|
+
:fresh, :int,
|
26
|
+
:freshdgeom, :int,
|
27
|
+
:freshconfig, :int,
|
28
|
+
:putmsg, :pointer,
|
29
|
+
:user_data, :pointer,
|
30
|
+
:callback_count, :int,
|
31
|
+
:calback, [:pointer, 4],
|
32
|
+
:calback_data, [:pointer, 4]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
require "ffi"
|
16
|
+
|
17
|
+
module Player
|
18
|
+
module Binding
|
19
|
+
module Diagnostic
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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 Pose3dStruct < FFI::Struct
|
18
|
+
layout :px, :double,
|
19
|
+
:py, :double,
|
20
|
+
:pz, :double,
|
21
|
+
:proll, :double,
|
22
|
+
:ppitch, :double,
|
23
|
+
:pyaw, :double
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,32 @@
|
|
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 Position2dStruct < FFI::Struct
|
18
|
+
layout :info, DeviceStruct,
|
19
|
+
:pose, [:double, 3],
|
20
|
+
:size, [:double, 2],
|
21
|
+
|
22
|
+
:px, :double,
|
23
|
+
:py, :double,
|
24
|
+
:pa, :double,
|
25
|
+
|
26
|
+
:vx, :double,
|
27
|
+
:vy, :double,
|
28
|
+
:va, :double,
|
29
|
+
:stall, :int
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 RangerStruct < FFI::Struct
|
18
|
+
layout :info, DeviceStruct,
|
19
|
+
:element_count, :uint32,
|
20
|
+
:min_angle, :double,
|
21
|
+
:max_angle, :double,
|
22
|
+
:angular_res, :double,
|
23
|
+
:min_range, :double,
|
24
|
+
:max_range, :double,
|
25
|
+
:range_res, :double,
|
26
|
+
:frequecy, :double,
|
27
|
+
:device_pose, Pose3dStruct,
|
28
|
+
:device_size, BBox3dStruct,
|
29
|
+
:element_poses, :pointer,
|
30
|
+
:element_sizes, :pointer,
|
31
|
+
:ranges_count, :uint32,
|
32
|
+
:ranges, :pointer,
|
33
|
+
:intensities_count, :uint32,
|
34
|
+
:intensities, :pointer,
|
35
|
+
:bearings_count, :uint32,
|
36
|
+
:bearings, :pointer,
|
37
|
+
:points_count, :uint32,
|
38
|
+
:points, :pointer
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,24 @@
|
|
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 SockaddrInStruct < FFI::Struct
|
18
|
+
layout :sin_family, :short,
|
19
|
+
:sin_port, :short,
|
20
|
+
:sin_addr, :int32,
|
21
|
+
:sin_zero, [:char, 8]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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"
|
@@ -0,0 +1,116 @@
|
|
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
|
+
# The client object manages the connection with the Player server
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
#
|
20
|
+
# Player::Client.connect("localhost") do |cl|
|
21
|
+
# pos2d = cl[:position2d, 0]
|
22
|
+
# pos2d.set_vel(1, 0, 0.2)
|
23
|
+
# cl.loop do
|
24
|
+
# puts "Position: x=#{pos2d.px}, y=#{pos2d.py}, a=#{pos2d.pa}
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
class Client
|
28
|
+
include CType
|
29
|
+
include Common
|
30
|
+
|
31
|
+
module C
|
32
|
+
extend FFI::Library
|
33
|
+
ffi_lib "playerc"
|
34
|
+
|
35
|
+
attach_function :playerc_client_create, [:pointer, :string, :int], :pointer
|
36
|
+
attach_function :playerc_client_destroy, [:pointer], :void
|
37
|
+
attach_function :playerc_client_connect, [:pointer], :int
|
38
|
+
attach_function :playerc_client_disconnect, [:pointer], :int
|
39
|
+
|
40
|
+
|
41
|
+
attach_function :playerc_client_read, [:pointer], :void
|
42
|
+
end
|
43
|
+
|
44
|
+
# Initialize client
|
45
|
+
# @param [String] host host address
|
46
|
+
# @param port number of port default 6665
|
47
|
+
def initialize(host, port=6665)
|
48
|
+
@client = ClientStruct.new(C.playerc_client_create(nil, host, port.to_i))
|
49
|
+
|
50
|
+
try_with_error C.playerc_client_connect(@client)
|
51
|
+
|
52
|
+
ObjectSpace.define_finalizer(self, Client.finilazer(@client))
|
53
|
+
if block_given?
|
54
|
+
yield self
|
55
|
+
close
|
56
|
+
else
|
57
|
+
self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
alias_method :connect, :new
|
63
|
+
end
|
64
|
+
|
65
|
+
# Read data from server and update all subscribed proxy objects
|
66
|
+
def read
|
67
|
+
C.playerc_client_read(@client)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get proxy object
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# pos2d = client[:position2d, 0]
|
74
|
+
#
|
75
|
+
# @param type type name of proxy object
|
76
|
+
# @param index index of proxy object
|
77
|
+
# @return proxy object
|
78
|
+
def [](type, index)
|
79
|
+
type_name = type.to_s.capitalize
|
80
|
+
(eval type_name).send(:new, @client, index)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Check connection
|
84
|
+
def closed?
|
85
|
+
@client[:connected] == 0
|
86
|
+
end
|
87
|
+
|
88
|
+
# Close connection
|
89
|
+
def close
|
90
|
+
try_with_error C.playerc_client_disconnect(@client)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Loop for control code
|
94
|
+
#
|
95
|
+
# @example
|
96
|
+
# cl.loop(0.5) do
|
97
|
+
# #...you control code
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# @param period period cicles in seconds
|
101
|
+
def loop(period=1.0)
|
102
|
+
while(true) do
|
103
|
+
read
|
104
|
+
yield
|
105
|
+
sleep(period.to_f)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def Client.finilazer(client)
|
110
|
+
lambda do
|
111
|
+
C.playerc_client_disconnect(client) if client[:connected] > 0
|
112
|
+
C.playerc_client_destroy(client)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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 Common
|
17
|
+
module C
|
18
|
+
extend FFI::Library
|
19
|
+
ffi_lib "playerc"
|
20
|
+
|
21
|
+
attach_function :playerc_error_str, [], :string
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def try_with_error(result)
|
26
|
+
raise StandardError.new(C.playerc_error_str) if result != 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|