mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 13:32:33 +00:00
Added Turn state path draw
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -1,4 +1,3 @@
|
|||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "cyberarm_engine"
|
gem "cyberarm_engine"
|
||||||
gem "faker", group: :development
|
|
||||||
@@ -106,7 +106,7 @@ class State
|
|||||||
def initialize(robot:, distance:, power:)
|
def initialize(robot:, distance:, power:)
|
||||||
@robot = robot
|
@robot = robot
|
||||||
@distance = distance
|
@distance = distance
|
||||||
@power = power
|
@power = power.clamp(-1.0, 1.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@@ -116,12 +116,15 @@ class State
|
|||||||
@goal.y += Math.sin(@robot.angle.gosu_to_radians) * @distance
|
@goal.y += Math.sin(@robot.angle.gosu_to_radians) * @distance
|
||||||
|
|
||||||
@complete = false
|
@complete = false
|
||||||
@allowable_error = 3.0
|
@allowable_error = 1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
Gosu.draw_line(@robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2, Gosu::Color::GREEN, @goal.x + @robot.width / 2, @goal.y + @robot.depth / 2, Gosu::Color::GREEN)
|
Gosu.draw_line(
|
||||||
Gosu.draw_rect(@goal.x + (@robot.width / 2 - 2), @goal.y + (@robot.depth / 2 - 2), 4, 4, Gosu::Color::RED)
|
@robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2, TAC::Palette::TIMECRAFTERS_TERTIARY,
|
||||||
|
@goal.x + @robot.width / 2, @goal.y + @robot.depth / 2, TAC::Palette::TIMECRAFTERS_TERTIARY
|
||||||
|
)
|
||||||
|
Gosu.draw_rect(@goal.x + (@robot.width / 2 - 1), @goal.y + (@robot.depth / 2 - 1), 2, 2, Gosu::Color::RED)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(dt)
|
def update(dt)
|
||||||
@@ -144,27 +147,58 @@ class State
|
|||||||
def initialize(robot:, relative_angle:, power:)
|
def initialize(robot:, relative_angle:, power:)
|
||||||
@robot = robot
|
@robot = robot
|
||||||
@relative_angle = relative_angle
|
@relative_angle = relative_angle
|
||||||
@power = power
|
@power = power.clamp(-1.0, 1.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@starting_angle = @robot.angle
|
@starting_angle = @robot.angle
|
||||||
@last_angle = @starting_angle
|
@last_angle = @starting_angle
|
||||||
|
@target_angle = (@starting_angle + @relative_angle) % 360.0
|
||||||
@complete = false
|
@complete = false
|
||||||
@allowable_error = 3.0
|
@allowable_error = 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
Gosu.rotate(@target_angle, @robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2) do
|
||||||
|
fraction = 0
|
||||||
|
angle_difference = Gosu.angle_diff(@target_angle, @robot.angle)
|
||||||
|
|
||||||
|
if angle_difference > 0
|
||||||
|
fraction = angle_difference / 360.0
|
||||||
|
else
|
||||||
|
fraction = (angle_difference - 360 % 360) / 360.0
|
||||||
|
end
|
||||||
|
|
||||||
|
Gosu.draw_arc(
|
||||||
|
@robot.position.x + @robot.width / 2,
|
||||||
|
@robot.position.y + @robot.depth / 2,
|
||||||
|
@robot.width > @robot.depth ? @robot.width : @robot.depth,
|
||||||
|
fraction,
|
||||||
|
360,
|
||||||
|
1,
|
||||||
|
TAC::Palette::TIMECRAFTERS_TERTIARY
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
Gosu.draw_circle(
|
||||||
|
@robot.position.x + @robot.width / 2 + Gosu.offset_x(@target_angle, @robot.width > @robot.depth ? @robot.width : @robot.depth),
|
||||||
|
@robot.position.y + @robot.depth / 2 + Gosu.offset_y(@target_angle, @robot.width > @robot.depth ? @robot.width : @robot.depth),
|
||||||
|
1,
|
||||||
|
9,
|
||||||
|
Gosu::Color::RED
|
||||||
|
)
|
||||||
|
# Gosu.draw_arc(@position.x, @position.y, 6, 1.0, 32, 2, @alliance)
|
||||||
|
end
|
||||||
|
|
||||||
def update(dt)
|
def update(dt)
|
||||||
target_angle = (@starting_angle + @relative_angle) % 360.0
|
if @robot.angle.between?(@target_angle - @allowable_error, @target_angle + @allowable_error)
|
||||||
|
|
||||||
if @robot.angle.between?(target_angle - @allowable_error, target_angle + @allowable_error)
|
|
||||||
@complete = true
|
@complete = true
|
||||||
@robot.angle = target_angle
|
@robot.angle = @target_angle
|
||||||
|
|
||||||
elsif Gosu.angle_diff(@starting_angle, target_angle) > 0
|
elsif Gosu.angle_diff(@starting_angle, @target_angle) > 0
|
||||||
@robot.angle += @power * dt * @robot.speed
|
@robot.angle += @power * dt * @robot.speed
|
||||||
|
|
||||||
elsif Gosu.angle_diff(@starting_angle, target_angle) < 0
|
elsif Gosu.angle_diff(@starting_angle, @target_angle) < 0
|
||||||
@robot.angle -= @power * dt * @robot.speed
|
@robot.angle -= @power * dt * @robot.speed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ module TAC
|
|||||||
flow width: 1.0, height: 0.05 do
|
flow width: 1.0, height: 0.05 do
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Run simulation" do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Run simulation" do
|
||||||
begin
|
begin
|
||||||
|
@simulation_start_time = Gosu.milliseconds
|
||||||
@simulation = TAC::Simulator::Simulation.new(source_code: @source_code.value, field_container: @field_container)
|
@simulation = TAC::Simulator::Simulation.new(source_code: @source_code.value, field_container: @field_container)
|
||||||
@simulation.start
|
@simulation.start
|
||||||
rescue SyntaxError, NameError, NoMethodError, TypeError, ArgumentError => e
|
rescue SyntaxError, NameError, NoMethodError, TypeError, ArgumentError => e
|
||||||
@@ -32,7 +33,7 @@ module TAC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Stop simulation" do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Stop simulation" do
|
||||||
@simulation.queue.clear if @simulation
|
@simulation.robots.each { |robot| robot.queue.clear } if @simulation
|
||||||
end
|
end
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Save source code" do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Save source code" do
|
||||||
File.open("#{TAC::ROOT_PATH}/data/simulator.rb", "w") { |f| f.write @source_code.value }
|
File.open("#{TAC::ROOT_PATH}/data/simulator.rb", "w") { |f| f.write @source_code.value }
|
||||||
@@ -73,6 +74,7 @@ robot.forward 100"
|
|||||||
super
|
super
|
||||||
|
|
||||||
@simulation.update if @simulation
|
@simulation.update if @simulation
|
||||||
|
@simulation_status.value = "Time: #{((Gosu.milliseconds - @simulation_start_time) / 1000.0).round(1)} seconds" if @simulation_start_time
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user