Skip to content
Snippets Groups Projects
Commit 0a10d2dd authored by bbartels's avatar bbartels
Browse files

quad: improve virtual quad test scripts and add stack size limit

parent 6598f201
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ test: all
$(MAKE) -C src/quad_app test
ruby scripts/tests/test_safety_checks.rb
ruby scripts/tests/test_unix_uart.rb
ruby scripts/tests/run_virtual_test_flight.rb
clean:
rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR)
......
......@@ -5,40 +5,9 @@
# A simple virtual test flight (take off, hover, and set back down)
#
THROTTLE_MIN = 110200
THROTTLE_MAX = 191900
THROTTLE_MID = (THROTTLE_MAX + THROTTLE_MIN)/2
THROTTLE_3_4 = (THROTTLE_MAX + THROTTLE_MID)/2
THROTTLE_QUAR = (THROTTLE_MID + THROTTLE_MIN)/2
THROTTLE_EIGHTH = (THROTTLE_QUAR + THROTTLE_MIN)/2
THROTTLE_16 = (THROTTLE_EIGHTH + THROTTLE_MIN)/2
MOTOR_MIN = 100000
MOTOR_MAX = 200000
GEAR_ON = 170800
GEAR_OFF = 118300
GRAVITY = 4096
MOTOR1 = "virt-quad-fifos/pwm-output-motor1"
MOTOR2 = "virt-quad-fifos/pwm-output-motor2"
MOTOR3 = "virt-quad-fifos/pwm-output-motor3"
MOTOR4 = "virt-quad-fifos/pwm-output-motor4"
UART_TX = "virt-quad-fifos/uart-tx"
GEAR = "virt-quad-fifos/pwm-input-gear"
THROTTLE = "virt-quad-fifos/pwm-input-throttle"
LED = "virt-quad-fifos/mio7-led"
I2C_MPU_ACCEL_X = "virt-quad-fifos/i2c-mpu-accel-x"
I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y"
I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z"
require 'test/unit/assertions'
require 'thread'
include Test::Unit::Assertions
script_dir = File.expand_path(File.dirname(__FILE__))
require script_dir + "/testing_library"
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
......@@ -52,7 +21,7 @@ sleep 1
##################
begin
puts("Starting flight")
puts("Starting flight...")
# Set gravity
File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
......@@ -96,8 +65,9 @@ begin
# fifo.close()
# puts msg
# puts msg
puts("Flight ended successfully.");
ensure
Process.kill(9, quad)
......
......@@ -4,93 +4,25 @@
#
# Startup the virtual quad and make sure it doesn't allow combinations of things
# that could hurt people.
THROTTLE_MIN = 110200
THROTTLE_MAX = 191900
THROTTLE_MID = (THROTTLE_MAX + THROTTLE_MIN)/2
THROTTLE_3_4 = (THROTTLE_MAX + THROTTLE_MID)/2
THROTTLE_QUAR = (THROTTLE_MID + THROTTLE_MIN)/2
THROTTLE_EIGHTH = (THROTTLE_QUAR + THROTTLE_MIN)/2
THROTTLE_16 = (THROTTLE_EIGHTH + THROTTLE_MIN)/2
MOTOR_MIN = 100000
MOTOR_MAX = 200000
GEAR_ON = 170800
GEAR_OFF = 118300
GRAVITY = 4096
MOTOR1 = "virt-quad-fifos/pwm-output-motor1"
MOTOR2 = "virt-quad-fifos/pwm-output-motor2"
MOTOR3 = "virt-quad-fifos/pwm-output-motor3"
MOTOR4 = "virt-quad-fifos/pwm-output-motor4"
GEAR = "virt-quad-fifos/pwm-input-gear"
THROTTLE = "virt-quad-fifos/pwm-input-throttle"
LED = "virt-quad-fifos/mio7-led"
I2C_MPU_ACCEL_X = "virt-quad-fifos/i2c-mpu-accel-x"
I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y"
I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z"
require 'test/unit/assertions'
require 'timeout'
require 'thread'
include Test::Unit::Assertions
$fifos = Hash.new
def read_fifo_num(f)
if not $fifos.key?(f)
$fifos[f] = File.open(f)
end
$fifos[f].read().chomp.split("\n").last.to_i
end
# Utility functions
def check_motors_are_off
motor1 = read_fifo_num(MOTOR1)
motor2 = read_fifo_num(MOTOR2)
motor3 = read_fifo_num(MOTOR3)
motor4 = read_fifo_num(MOTOR4)
assert_operator motor1, :<=, THROTTLE_MIN
assert_operator motor2, :<=, THROTTLE_MIN
assert_operator motor3, :<=, THROTTLE_MIN
assert_operator motor4, :<=, THROTTLE_MIN
end
def get_motor_averages
motors = [[], [], [], []]
for i in 0..100
motors[0].push(read_fifo_num(MOTOR1))
motors[1].push(read_fifo_num(MOTOR2))
motors[2].push(read_fifo_num(MOTOR3))
motors[3].push(read_fifo_num(MOTOR4))
sleep 0.010
end
average = []
average[0] = motors[0].inject(:+).to_f / motors[0].size
average[1] = motors[1].inject(:+).to_f / motors[1].size
average[2] = motors[2].inject(:+).to_f / motors[2].size
average[3] = motors[3].inject(:+).to_f / motors[3].size
average
end
def check_led(is_on)
led = read_fifo_num(LED)
assert_equal(led, is_on)
end
script_dir = File.expand_path(File.dirname(__FILE__))
require script_dir + "/testing_library"
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
Timeout::timeout(30) {
puts("Setting up...")
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
sleep 1
# Start virtual quad
quad_pid = Process.spawn("./virt-quad", :rlimit_as => 536870912) # 512 MiB RAM
quad_pid = Process.spawn("./virt-quad",
{ :rlimit_as => 536870912, # 512 MiB total RAM
:rlimit_stack => 1048576}) # 1 MiB stack
sleep 5
......
#!/usr/bin/env ruby
# UART test
#
# This test is pretty simple, just a UART smoke test, using
# the debug callback on the quad
GEAR_ON = 170800
GEAR_OFF = 118300
script_dir = File.expand_path(File.dirname(__FILE__))
require script_dir + "/testing_library"
GEAR = "virt-quad-fifos/pwm-input-gear"
UART_RX = "virt-quad-fifos/uart-rx"
UART_TX = "virt-quad-fifos/uart-tx"
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
require 'test/unit/assertions'
require 'thread'
require 'timeout'
include Test::Unit::Assertions
Timeout::timeout(30) {
puts("Setting up...")
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
sleep 1
# Start virtual quad
quad_pid = Process.spawn("./virt-quad", :rlimit_as => 536870912) # 512 MiB RAM
quad_pid = Process.spawn("./virt-quad",
{ :rlimit_as => 536870912, # 512 MiB total RAM
:rlimit_stack => 1048576}) # 1 MiB stack
sleep 5
......
THROTTLE_MIN = 110200
THROTTLE_MAX = 191900
THROTTLE_MID = (THROTTLE_MAX + THROTTLE_MIN)/2
THROTTLE_3_4 = (THROTTLE_MAX + THROTTLE_MID)/2
THROTTLE_QUAR = (THROTTLE_MID + THROTTLE_MIN)/2
THROTTLE_EIGHTH = (THROTTLE_QUAR + THROTTLE_MIN)/2
THROTTLE_16 = (THROTTLE_EIGHTH + THROTTLE_MIN)/2
MOTOR_MIN = 100000
MOTOR_MAX = 200000
GEAR_ON = 170800
GEAR_OFF = 118300
GRAVITY = 4096
MOTOR1 = "virt-quad-fifos/pwm-output-motor1"
MOTOR2 = "virt-quad-fifos/pwm-output-motor2"
MOTOR3 = "virt-quad-fifos/pwm-output-motor3"
MOTOR4 = "virt-quad-fifos/pwm-output-motor4"
GEAR = "virt-quad-fifos/pwm-input-gear"
THROTTLE = "virt-quad-fifos/pwm-input-throttle"
LED = "virt-quad-fifos/mio7-led"
I2C_MPU_ACCEL_X = "virt-quad-fifos/i2c-mpu-accel-x"
I2C_MPU_ACCEL_Y = "virt-quad-fifos/i2c-mpu-accel-y"
I2C_MPU_ACCEL_Z = "virt-quad-fifos/i2c-mpu-accel-z"
UART_RX = "virt-quad-fifos/uart-rx"
UART_TX = "virt-quad-fifos/uart-tx"
require 'test/unit/assertions'
require 'timeout'
require 'thread'
include Test::Unit::Assertions
$fifos = Hash.new
def read_fifo_num(f)
if not $fifos.key?(f)
$fifos[f] = File.open(f)
end
$fifos[f].read().chomp.split("\n").last.to_i
end
# Utility functions
def check_motors_are_off
motor1 = read_fifo_num(MOTOR1)
motor2 = read_fifo_num(MOTOR2)
motor3 = read_fifo_num(MOTOR3)
motor4 = read_fifo_num(MOTOR4)
assert_operator motor1, :<=, THROTTLE_MIN
assert_operator motor2, :<=, THROTTLE_MIN
assert_operator motor3, :<=, THROTTLE_MIN
assert_operator motor4, :<=, THROTTLE_MIN
end
def get_motor_averages
motors = [[], [], [], []]
for i in 0..100
motors[0].push(read_fifo_num(MOTOR1))
motors[1].push(read_fifo_num(MOTOR2))
motors[2].push(read_fifo_num(MOTOR3))
motors[3].push(read_fifo_num(MOTOR4))
sleep 0.010
end
average = []
average[0] = motors[0].inject(:+).to_f / motors[0].size
average[1] = motors[1].inject(:+).to_f / motors[1].size
average[2] = motors[2].inject(:+).to_f / motors[2].size
average[3] = motors[3].inject(:+).to_f / motors[3].size
average
end
def check_led(is_on)
led = read_fifo_num(LED)
assert_equal(led, is_on)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment