-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobo_sim.rb
More file actions
108 lines (82 loc) · 2.97 KB
/
robo_sim.rb
File metadata and controls
108 lines (82 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
include Java
require 'lib/spoon'
require 'console/environment'
require 'console/simulator'
require 'console/robo_sim_frame'
require 'console/console_comm'
class RoboSim
attr_reader :simulator, :communicator, :environment, :shutting_down, :shut_down
def initialize( environment )
schedule_init environment
end
def exit_robo_sim
#exit
@shut_down = true
end
def initiate_shutdown
puts "initiating shutdown"
@shutting_down = true
@communicator.send_killall()
t = javax.swing.Timer.new( 5000, nil )
t.add_action_listener { |e|
exit_robo_sim
}
t.setRepeats( false )
t.start
end
def schedule_init( environment )
t = javax.swing.Timer.new( 1, nil )
t.add_action_listener do |e|
@shutting_down = false
@shut_down = false
@environment = environment
@simulator = Simulator.new( self )
@console = RoboSimFrame.new( self )
@communicator = ConsoleComm.new( self )
@communicator.open
schedule_msg_check
end
t.setRepeats( false )
t.start
end
def schedule_msg_check
if not @shut_down
t = javax.swing.Timer.new( 0, nil )
t.add_action_listener { |e| @communicator.check_for_msgs }
t.setRepeats( false )
t.start
end
end
end
################################################################################
RUN_ANYWAY = 1
if ( RUN_ANYWAY )
e = Environment.new( 50, 50 )
# e.add_obstacle( 'obstacle', Obstacle( 5, 5, 1 ) )
e.add_obstacle( Obstacle.new( 10, 10, 2 ) )
e.add_obstacle( Obstacle.new( 15, 15, 3 ) )
e.add_wall( Wall.new( 15, 35, 25, 35 ) )
e.add_wall( Wall.new( 25, 35, 35, 25 ) )
#e.add_wall( Wall.new( 35, 25, 35, 15 ) )
e.add_item( Item.new( 49, 49, 1, 'red' ) )
# e.add( 'wall', Wall( 15, 15, 15, 35 ) )
# e.add( 'wall', Wall( 15, 35, 35, 35 ) )
# e.add( 'wall', Wall( 35, 35, 35, 15 ) )
# e.add( 'wall', Wall( 35, 15, 15, 15 ) )
# e.add_wall( Wall.new( 10, 10, 10, 40 ) )
# e.add_wall( Wall.new( 10, 40, 40, 40 ) )
# e.add_wall( Wall.new( 40, 40, 40, 10 ) )
# e.add_wall( Wall.new( 40, 10, 10, 10 ) )
app = RoboSim.new( e )
class_file = "robot/robot_test.class"
rb_file = "robot/robot_test.rb"
exec_target = ((File.exist?(class_file) and class_file) or
(File.exist?(rb_file) and rb_file))
#cmd = "jruby robot/robot_test.rb -i 1 -x 1 -y 1 -c blue -v 1 -a 20"
#Spoon.spawnp( 'jruby', '--profile', exec_target, '-i', '1', '-x', '1', '-y', '1', '-c', 'blue', '-v', '1', '-a', '20' )
Spoon.spawnp( 'jruby', exec_target, '-i', '1', '-x', '1', '-y', '1', '-c', 'blue', '-v', '1', '-a', '20' )
while not app.shut_down
sleep 1
end
puts "ending"
end