Skip to content
Open

test #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added color_sensor.rb
Empty file.
11 changes: 5 additions & 6 deletions ev3_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions navigator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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


Expand Down