Newer
Older
#!/usr/bin/env ruby
# Safety Checks
#
# Startup the virtual quad and make sure it doesn't allow combinations of things
# that could hurt people.
script_dir = File.expand_path(File.dirname(__FILE__))
require script_dir + "/testing_library"
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
quad_pid = Process.spawn("./virt-quad",
{ :rlimit_as => 536870912, # 512 MiB total RAM
:rlimit_stack => 1048576}) # 1 MiB stack
sleep 5
#################
# Begin Tests
#################
# Set gravity
File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
puts("Check that motors are off at startup")
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
puts("Check that LED is off at startup")
check_led(0)
puts("Check that increasing the throttle does nothing to motors")
# (because gear is still off)
for i in (THROTTLE_MIN..THROTTLE_MAX).step(1000)
File.write(THROTTLE, i)
check_motors_are_off
sleep 0.005
end
puts("Check that flipping gear to 1 while throttle is high does nothing")
# (motors should still be off, LED should still be off)
File.write(GEAR, GEAR_ON)
sleep 0.015
check_motors_are_off
i = THROTTLE_MAX
while i > THROTTLE_MID
i -= 1000
File.write(THROTTLE, i)
check_motors_are_off
check_led 0
sleep 0.005
end
# (swtich GEAR back to off and bring throttle off)
File.write(GEAR, GEAR_OFF)
File.write(THROTTLE, THROTTLE_MIN)
puts("Check that the LED turns on when gear is flipped on")
# (motors should still be off because our throttle is low)
File.write(GEAR, GEAR_ON)
sleep 0.1
check_led 1
check_motors_are_off
puts("Check that motors turn on")
File.write(THROTTLE, THROTTLE_MID)
averages = get_motor_averages
average = (averages[0] + averages[1] + averages[2] + averages[3])/4
puts averages, "(#{average})"
assert average.between?(THROTTLE_EIGHTH, MOTOR_MAX)
# Check that gear switch kills the motors
# (and that light goes off)
File.write(GEAR, GEAR_OFF)
sleep 0.1
# (Bring the RC throttle back down)
File.write(THROTTLE, THROTTLE_MIN)
sleep 1
puts "All safety checks passed."
Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}