Skip to content

Commit fa2dd11

Browse files
committed
update run script and tests
1 parent 88aca60 commit fa2dd11

3 files changed

Lines changed: 42 additions & 42 deletions

File tree

run

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ print_green() {
88

99
# Function to print messages in blue
1010
print_blue() {
11-
echo -e "\e[34m$1\e[0m"
11+
echo -e "\e[36m$1\e[0m"
1212
}
1313

1414
# Function to print messages in red
@@ -17,9 +17,16 @@ print_red() {
1717
}
1818

1919
# Print the blue welcome message
20-
print_blue "------------------------------------------"
21-
print_blue "Purdue RoboMaster Club: Auto Aiming Suite"
22-
print_blue "------------------------------------------"
20+
print_blue "-------------------------------------------"
21+
print_blue " Purdue RoboMaster Club: Auto Aiming Suite "
22+
print_blue " ___________________________ "
23+
print_blue " \_________________________ \ "
24+
print_blue " _________________________| | "
25+
print_blue " | ________________________/ "
26+
print_blue " | | __ __ __ __ "
27+
print_blue " \__/ <__> <__> <__> <__> "
28+
print_blue " "
29+
print_blue "-------------------------------------------"
2330

2431
# Function to clean the workspace
2532
clean() {
@@ -64,6 +71,14 @@ test() {
6471

6572
# Check if a package name is provided
6673
local package_name=$1
74+
if [[ $package_name ]]; then
75+
source install/setup.sh
76+
res=$(ros2 pkg list | grep -c "$package_name$")
77+
if [[ $res -ne 1 ]]; then
78+
print_red "Package [$package_name] not found for testing"
79+
exit 1
80+
fi
81+
fi
6782

6883
# Run tests
6984
if [[ -z "$package_name" ]]; then

src/prm_control/control_communicator/test/test_ControlCommunicator.cpp

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22
#include "ControlCommunicator.h"
3+
#include <list>
34

45
class ControlCommunicatorTest : public ::testing::Test
56
{
@@ -9,31 +10,15 @@ class ControlCommunicatorTest : public ::testing::Test
910

1011
void SetUp() override
1112
{
12-
// Find which port to use
13-
const char *port1 = "/dev/ttyTHS0";
14-
const char *port2 = "/dev/ttyTHS1";
15-
const char *port3 = "/dev/ttyTHS2";
16-
bool port1_exists = access(port1, F_OK) != -1 && open(port1, O_RDWR | O_NOCTTY | O_NONBLOCK) != -1;
17-
bool port2_exists = access(port2, F_OK) != -1 && open(port2, O_RDWR | O_NOCTTY | O_NONBLOCK) != -1;
18-
bool port3_exists = access(port3, F_OK) != -1 && open(port3, O_RDWR | O_NOCTTY | O_NONBLOCK) != -1;
19-
20-
// If either of the ports exist, use it
21-
if (port1_exists)
22-
{
23-
port = port1;
24-
}
25-
else if (port2_exists)
26-
{
27-
port = port2;
28-
}
29-
else if (port3_exists)
13+
// Loop through possible UART ports to fnd one we can access and open
14+
const std::list<const char *> ports = {"/dev/ttyTHS0", "/dev/ttyTHS1", "/dev/ttyTHS2"};
15+
for (const char *p : ports)
3016
{
31-
port = port3;
32-
}
33-
else
34-
{
35-
// Neither port exists on dev server or local machine, since no serial device
36-
port = nullptr;
17+
if (access(p, F_OK) != -1 && open(p, O_RDWR | O_NOCTTY | O_NONBLOCK) != -1)
18+
{
19+
port = p;
20+
break;
21+
}
3722
}
3823
}
3924

@@ -83,7 +68,7 @@ TEST_F(ControlCommunicatorTest, test_read_uart)
8368
if (port != nullptr)
8469
{
8570
EXPECT_TRUE(control_communicator.start_uart_connection(port));
86-
EXPECT_NE(control_communicator.port_fd, -1); // Port should be opened
71+
EXPECT_NE(control_communicator.port_fd, -1); // Port should be opened
8772
EXPECT_TRUE(control_communicator.is_connected); // Connection should be established
8873

8974
PackageIn package;
@@ -99,21 +84,21 @@ TEST_F(ControlCommunicatorTest, test_read_uart)
9984
EXPECT_TRUE(result); // Ensure at least one successful read
10085

10186
// Validate the package data
102-
EXPECT_EQ(package.head, 0xAA); // Check head byte
87+
EXPECT_EQ(package.head, 0xAA); // Check head byte
10388
EXPECT_EQ(package.ref_flags & 0x01, 0); // Check ref_flags (LSB should be 0 since match not started)
104-
EXPECT_LT(package.pitch, M_PI); // Check pitch value
105-
EXPECT_GT(package.pitch, -M_PI); // Check pitch value
106-
EXPECT_LT(package.pitch_vel, M_PI); // Check pitch velocity
107-
EXPECT_GT(package.pitch_vel, -M_PI); // Check pitch velocity
108-
EXPECT_LT(package.yaw_vel, M_PI); // Check yaw velocity
109-
EXPECT_GT(package.yaw_vel, -M_PI); // Check yaw velocity
110-
89+
EXPECT_LT(package.pitch, M_PI); // Check pitch value
90+
EXPECT_GT(package.pitch, -M_PI); // Check pitch value
91+
EXPECT_LT(package.pitch_vel, M_PI); // Check pitch velocity
92+
EXPECT_GT(package.pitch_vel, -M_PI); // Check pitch velocity
93+
EXPECT_LT(package.yaw_vel, M_PI); // Check yaw velocity
94+
EXPECT_GT(package.yaw_vel, -M_PI); // Check yaw velocity
95+
11196
// package x field should exist and be a number
112-
EXPECT_NE(package.x, NAN); // Check x position
113-
EXPECT_NE(package.y, NAN); // Check y position
97+
EXPECT_NE(package.x, NAN); // Check x position
98+
EXPECT_NE(package.y, NAN); // Check y position
11499
EXPECT_NE(package.orientation, NAN); // Check orientation
115-
EXPECT_NE(package.x_vel, NAN); // Check x velocity
116-
EXPECT_NE(package.y_vel, NAN); // Check y velocity
100+
EXPECT_NE(package.x_vel, NAN); // Check x velocity
101+
EXPECT_NE(package.y_vel, NAN); // Check y velocity
117102
}
118103
else
119104
{

src/prm_launch/launch/video2detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def generate_launch_description():
99
webcam_publisher = get_package_share_path('webcam_publisher')
10-
video_path = "/home/purduerm/Videos/moving_but_no_spinning.avi" # example, can change to your liking
10+
video_path = "/home/tom/Videos/far_back_spin_and_move.avi" # example, can change to your liking
1111
return LaunchDescription([
1212
Node(
1313
package='webcam_publisher',

0 commit comments

Comments
 (0)