Skip to content
Snippets Groups Projects
Unverified Commit acb7573b authored by Charles Javerliat's avatar Charles Javerliat
Browse files

test: Add tests for encoders

parent 55d4c04e
No related branches found
No related tags found
1 merge request!16Refactoring
Pipeline #226 passed with stage
in 3 minutes and 52 seconds
......@@ -11,6 +11,7 @@ monitor_port = /dev/ttyACM1
monitor_speed = 115200
test_speed = 115200
test_build_project_src = true
test_transport = custom
[env:nucleo_f303k8]
platform = ststm32
......
#include <mbed.h>
#include <unity.h>
#include <cmath>
#include "regulator/PID.hpp"
#include "odometry/Odometer.hpp"
void wait_for_enter()
{
int c;
while ((c = getchar()) != '\n' && c != EOF)
{
continue;
}
}
DigitalOut led1(LED1);
void test_led_builtin_pin_number()
......@@ -136,21 +148,121 @@ void test_odometer_init_values()
TEST_ASSERT_EQUAL(0, odom.getSpeed().rightWheelSpeed);
}
void test_encoder_left_resolution_X4()
{
Encoder leftEncoder(D7, D8, 1024);
TEST_ASSERT_EQUAL(1024 * 4, leftEncoder.getResolution());
}
void test_encoder_left_still()
{
Encoder leftEncoder(D7, D8, 1024);
TEST_ASSERT_EQUAL(0, leftEncoder.getTicks());
wait_ms(50);
TEST_ASSERT_EQUAL(0, leftEncoder.getTicks());
}
void test_encoder_left_forward()
{
Encoder leftEncoder(D7, D8, 1024);
printf(">> Turn left encoder forward and press [ENTER] to continue.\n");
wait_for_enter();
TEST_ASSERT_GREATER_OR_EQUAL(1, leftEncoder.getTicks());
}
void test_encoder_left_backward()
{
Encoder leftEncoder(D7, D8, 1024);
printf(">> Turn left encoder backward and press [ENTER] to continue.\n");
wait_for_enter();
TEST_ASSERT_LESS_OR_EQUAL(-1, leftEncoder.getTicks());
}
void test_encoder_right_resolution_X4()
{
Encoder rightEncoder(D10, D12, 1000);
TEST_ASSERT_EQUAL(1000 * 4, rightEncoder.getResolution());
}
void test_encoder_right_still()
{
Encoder rightEncoder(D10, D12, 1000);
TEST_ASSERT_EQUAL(0, rightEncoder.getTicks());
wait_ms(50);
TEST_ASSERT_EQUAL(0, rightEncoder.getTicks());
}
void test_encoder_right_backward()
{
Encoder rightEncoder(D10, D12, 1000);
printf(">> Turn right encoder backward and press [ENTER] when done.\n");
wait_for_enter();
TEST_ASSERT_LESS_OR_EQUAL(-1, rightEncoder.getTicks());
}
void test_encoder_right_forward()
{
Encoder rightEncoder(D10, D12, 1000);
printf(">> Turn right encoder forward and press [ENTER] when done.\n");
wait_for_enter();
TEST_ASSERT_GREATER_OR_EQUAL(1, rightEncoder.getTicks());
}
void test_encoder_both_forward()
{
Encoder leftEncoder(D7, D8, 1024);
Encoder rightEncoder(D10, D12, 1000);
printf(">> Turn both encoders forward and press [ENTER] when done.\n");
wait_for_enter();
TEST_ASSERT_GREATER_OR_EQUAL(1, leftEncoder.getTicks());
TEST_ASSERT_GREATER_OR_EQUAL(1, rightEncoder.getTicks());
}
void test_encoder_both_backward()
{
Encoder leftEncoder(D7, D8, 1024);
Encoder rightEncoder(D10, D12, 1000);
printf(">> Turn both encoders backward and press [ENTER] when done.\n");
wait_for_enter();
TEST_ASSERT_LESS_OR_EQUAL(-1, leftEncoder.getTicks());
TEST_ASSERT_LESS_OR_EQUAL(-1, rightEncoder.getTicks());
}
int main()
{
// Wait for serial to setup
wait_ms(2000);
UNITY_BEGIN();
RUN_TEST(test_led_builtin_pin_number);
RUN_TEST(test_led_state_high);
RUN_TEST(test_led_state_low);
RUN_TEST(test_pid_compute_proportional_Kp1);
RUN_TEST(test_pid_cumpute_proportional_Kp2);
RUN_TEST(test_pid_cumpute_integral_Ki_1);
RUN_TEST(test_pid_cumpute_integral_Ki_2);
RUN_TEST(test_pid_compute_derivative_division_by_zero);
RUN_TEST(test_pid_compute_all_Kp_Ki_Kd_1);
RUN_TEST(test_odometer_init_values);
RUN_TEST(test_encoder_left_resolution_X4);
RUN_TEST(test_encoder_right_resolution_X4);
RUN_TEST(test_encoder_left_still);
RUN_TEST(test_encoder_right_still);
RUN_TEST(test_encoder_left_forward);
RUN_TEST(test_encoder_left_backward);
RUN_TEST(test_encoder_right_forward);
RUN_TEST(test_encoder_right_backward);
RUN_TEST(test_encoder_both_forward);
RUN_TEST(test_encoder_both_backward);
UNITY_END();
}
\ No newline at end of file
#ifndef UNITTEST_TRANSPORT_H
#define UNITTEST_TRANSPORT_H
#include <mbed.h>
#include <output_export.h>
Serial pc(USBTX, USBRX);
void unittest_uart_begin()
{
pc.baud(115200);
}
void unittest_uart_putchar(char c)
{
pc.putc(c);
}
void unittest_uart_flush()
{
}
void unittest_uart_end()
{
}
#endif
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment