Skip to content
Snippets Groups Projects
Commit 82b0bb14 authored by bbartels's avatar bbartels
Browse files

quad: run make deep-clean on ci test

- Add some prints to scripts to help with debugging
- Add timeout if spawn fails
- Add more time to allow changes to take effect
- Fix input design
parent c123eeb9
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,4 @@ set -e
export PATH=/usr/local/bin:$PATH
# Quad
(cd quad && make test)
(cd quad && make deep-clean && make && make test)
......@@ -38,8 +38,8 @@ test: all
$(MAKE) -C src/queue test
$(MAKE) -C src/computation_graph test
$(MAKE) -C src/quad_app test
#ruby scripts/tests/test_safety_checks.rb
#ruby scripts/tests/test_unix_uart.rb
ruby scripts/tests/test_safety_checks.rb
ruby scripts/tests/test_unix_uart.rb
clean:
rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR)
......
......@@ -32,6 +32,7 @@ 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
......@@ -73,97 +74,106 @@ def get_motor_averages
average
end
def check_led(on)
def check_led(is_on)
led = read_fifo_num(LED)
assert_equal(led, on)
assert_equal(led, is_on)
end
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
Timeout::timeout(30) {
# Start virtual quad
quad = Process.spawn("./virt-quad")
puts("Setting up...")
sleep 1
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
#################
# Begin Tests
#################
sleep 1
# Start virtual quad
quad_pid = Process.spawn("./virt-quad")
sleep 5
#################
# Begin Tests
#################
begin
puts("beginning tests")
# Set gravity
File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
begin
puts("Check that motors are off at startup")
check_motors_are_off
puts("Beginning tests...")
puts("Check that LED is off at startup")
check_led(0)
# Set gravity
File.write(I2C_MPU_ACCEL_Z, -1 * GRAVITY)
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)
puts("Check that motors are off at startup")
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)
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
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.020
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.040
check_motors_are_off
check_led 0
# (Bring the RC throttle back down)
File.write(THROTTLE, THROTTLE_MIN)
# Check that we can resume flight
File.write(GEAR, GEAR_ON)
sleep 0.040
check_led 1
# (Bring the RC throttle back down)
File.write(THROTTLE, THROTTLE_MIN)
sleep 1
puts "All safety checks passed."
# Check that we can resume flight
File.write(GEAR, GEAR_ON)
sleep 0.1
check_led 1
ensure
sleep 1
puts "All safety checks passed."
Process.kill(9, quad)
ensure
end
Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}
......@@ -15,54 +15,64 @@ UART_TX = "virt-quad-fifos/uart-tx"
require 'test/unit/assertions'
require 'thread'
require 'timeout'
include Test::Unit::Assertions
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
Timeout::timeout(30) {
# Start virtual quad
quad = Process.spawn("./virt-quad")
puts("Setting up...")
sleep 1
script_dir = File.expand_path(File.dirname(__FILE__))
bin_dir = script_dir + "/../../bin/"
Dir.chdir(bin_dir)
#################
# Begin Tests
#################
sleep 1
begin
# Start virtual quad
quad_pid = Process.spawn("./virt-quad")
# Flip gear on
File.write(GEAR, GEAR_ON)
sleep 0.015
sleep 5
for j in 1..10
# Send a debug command
File.write(UART_RX, [0xBE, 1, 0, 0, 0, 0, 0, 0xBF].pack("CCCCCCCC"))
#################
# Begin Tests
#################
fifo = File.open(UART_TX)
msg = []
for i in 1..7
sleep 0.010
msg.push(fifo.read(1))
end
length = msg[5..7].join().unpack("S")[0]
msg = []
for i in 1..length
sleep 0.010
msg.push(fifo.read(1))
end
fifo.close
begin
puts msg.join()
assert_equal(msg.join().force_encoding("UTF-8"), "Packets received: #{j}")
end
puts("Beginning tests...")
# Flip gear on
File.write(GEAR, GEAR_ON)
sleep 0.015
puts "Basic UART test passed."
for j in 1..10
# Send a debug command
File.write(UART_RX, [0xBE, 1, 0, 0, 0, 0, 0, 0xBF].pack("CCCCCCCC"))
ensure
fifo = File.open(UART_TX)
msg = []
for i in 1..7
sleep 0.010
msg.push(fifo.read(1))
end
length = msg[5..7].join().unpack("S")[0]
msg = []
for i in 1..length
sleep 0.010
msg.push(fifo.read(1))
end
fifo.close
Process.kill(9, quad)
puts msg.join()
assert_equal(msg.join().force_encoding("UTF-8"), "Packets received: #{j}")
end
puts "Basic UART test passed."
end
ensure
Process.kill(9, quad_pid)
Process.wait(quad_pid)
end
}
......@@ -20,14 +20,8 @@ static short last_dev;
static short last_reg;
static short last_val;
static int zero = 0;
static int one = 1;
static int two = 2;
static int three = 3;
static int four = 4;
static int five = 5;
static pthread_t worker;
static int nums[] = {0, 1, 2, 3, 4, 5};
static pthread_t workers[6];
int unix_i2c_reset(struct I2CDriver *self) {
input_names[0] = "i2c-mpu-accel-x";
......@@ -40,12 +34,10 @@ int unix_i2c_reset(struct I2CDriver *self) {
mkdir(VIRT_QUAD_FIFOS_DIR, 0777);
// Start up worker thread whose job is to update the caches
pthread_create(&worker, 0, update_i2c_input_cache, &zero);
pthread_create(&worker, 0, update_i2c_input_cache, &one);
pthread_create(&worker, 0, update_i2c_input_cache, &two);
pthread_create(&worker, 0, update_i2c_input_cache, &three);
pthread_create(&worker, 0, update_i2c_input_cache, &four);
pthread_create(&worker, 0, update_i2c_input_cache, &five);
int i;
for (i = 0; i < 6; i += 1) {
pthread_create(&workers[i], 0, update_i2c_input_cache, &nums[i]);
}
cache[0].s = 0;
cache[1].s = 0;
......
......@@ -10,7 +10,8 @@ void * update_input_cache();
static char *input_names[6];
static int fifos[6];
static unsigned long cache[6];
pthread_t worker;
static pthread_t workers[6];
static int nums[] = {0, 1, 2, 3, 4, 5};
int unix_pwm_input_reset(struct PWMInputDriver *self) {
input_names[0] = "pwm-input-throttle";
......@@ -25,7 +26,8 @@ int unix_pwm_input_reset(struct PWMInputDriver *self) {
// Start up worker thread whose job is to update the caches
int i;
for (i = 0; i < 6; i += 1) {
pthread_create(&worker, 0, update_input_cache, &i);
pthread_create(&workers[i], 0, update_input_cache, &nums[i]);
usleep(1000);
}
cache[0] = THROTTLE_MIN;
......
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