diff --git a/color_sensor.rb b/color_sensor.rb new file mode 100644 index 0000000..e69de29 diff --git a/ev3_controller.rb b/ev3_controller.rb index 2c12427..8e860b6 100644 --- a/ev3_controller.rb +++ b/ev3_controller.rb @@ -5,9 +5,8 @@ class EV3Controller RIGHT_MOTOR = "B" MOTOR_SPEED = 15 + data=[] attr_reader :last_color, :last_distance - data = 0 - def initialize(port = "COM4") @motors = [LEFT_MOTOR, RIGHT_MOTOR] @brick = EV3::Brick.new(EV3::Connections::Bluetooth.new(port)) @@ -24,7 +23,7 @@ def move_forward(sec, speed = MOTOR_SPEED) sleep sec @brick.stop(true, *@motors) puts @brick.get_sensor(COLOR_SENSOR, 2) - data = @brick.get_sensor(COLOR_SENSOR, 2) + data.push(@brick.get_sensor(COLOR_SENSOR, 2)) end def move_back(sec, speed = MOTOR_SPEED) @@ -34,7 +33,7 @@ def move_back(sec, speed = MOTOR_SPEED) @brick.stop(true, *@motors) @brick.reverse_polarity(*@motors) puts @brick.get_sensor(COLOR_SENSOR, 2) - data = @brick.get_sensor(COLOR_SENSOR, 2) + data.push(@brick.get_sensor(COLOR_SENSOR, 2)) end def right_torun(sec, speed = MOTOR_SPEED) @@ -51,7 +50,7 @@ def right_torun(sec, speed = MOTOR_SPEED) puts @brick.get_sensor(COLOR_SENSOR, 2) - data = @brick.get_sensor(COLOR_SENSOR, 2) + data.push(@brick.get_sensor(COLOR_SENSOR, 2)) end @@ -66,7 +65,7 @@ def left_torun(sec, speed = MOTOR_SPEED) sleep sec + 1 @brick.stop(true, *@motors) puts @brick.get_sensor(COLOR_SENSOR, 2) - data = @brick.get_sensor(COLOR_SENSOR, 2) + data.push(@brick.get_sensor(COLOR_SENSOR, 2)) end def update_sensor_value diff --git a/navigator.rb b/navigator.rb index 4cfc191..a33b72d 100644 --- a/navigator.rb +++ b/navigator.rb @@ -31,7 +31,9 @@ def update(map) if Input.key_push?(K_RETURN) + data = [] @ev3_controller.move_forward(2) + data.push(brick.get_sensor(COLOR_SENSOR, 2)) @ev3_controller.move_forward(2) @ev3_controller.move_forward(2) @ev3_controller.left_torun(1.25) @@ -42,6 +44,7 @@ def update(map) @ev3_controller.right_torun(1.25) @ev3_controller.move_forward(2.2) @ev3_controller.move_forward(2.2) + puts data end