Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
motors-control-card-driver
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
CdF
CdF 2020-2021
modules
motors-control-card
motors-control-card-driver
Commits
acb7573b
Unverified
Commit
acb7573b
authored
4 years ago
by
Charles Javerliat
Browse files
Options
Downloads
Patches
Plain Diff
test: Add tests for encoders
parent
55d4c04e
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Refactoring
Pipeline
#226
passed with stage
in 3 minutes and 52 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
platformio.ini
+1
-0
1 addition, 0 deletions
platformio.ini
test/test_main.cpp
+112
-0
112 additions, 0 deletions
test/test_main.cpp
test/unittest_transport.h
+27
-0
27 additions, 0 deletions
test/unittest_transport.h
with
140 additions
and
0 deletions
platformio.ini
+
1
−
0
View file @
acb7573b
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
test/test_main.cpp
+
112
−
0
View file @
acb7573b
#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
This diff is collapsed.
Click to expand it.
test/unittest_transport.h
0 → 100644
+
27
−
0
View file @
acb7573b
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment