Skip to content

Commit

Permalink
completing the course in the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioc76 committed Apr 4, 2024
1 parent 1fb7357 commit 8086169
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
18 changes: 9 additions & 9 deletions autonav_ws/src/autonav_filters/src/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ void FiltersNode::on_MotorFeedback_received(const autonav_msgs::msg::MotorFeedba
autonav_msgs::msg::Position position;
position.x = averages[0];
position.y = averages[1];
RCLCPP_INFO(this->get_logger(), "position.x %f\n", position.x);
RCLCPP_INFO(this->get_logger(), "position.y %f\n", position.y);
//RCLCPP_INFO(this->get_logger(), "position.x %f\n", position.x);
//RCLCPP_INFO(this->get_logger(), "position.y %f\n", position.y);
position.theta = (-1 * M_PI * 2 + averages[2]);
RCLCPP_INFO(this->get_logger(), "position.theta %f\n", position.theta);
//RCLCPP_INFO(this->get_logger(), "position.theta %f\n", position.theta);
if (this->first_gps_received == true) {
double gps_x = this->first_gps.latitude + position.x / this->latitudeLength;
double gps_y = this->first_gps.longitude - position.y / this->longitudeLength;

RCLCPP_INFO(this->get_logger(), "first_gps.latitude %f", first_gps.latitude);
RCLCPP_INFO(this->get_logger(), "first_gps.longitude %f", first_gps.longitude);
RCLCPP_INFO(this->get_logger(), "gps_x %f", gps_x);
RCLCPP_INFO(this->get_logger(), "gps_y %f", gps_y);
//RCLCPP_INFO(this->get_logger(), "first_gps.latitude %f", first_gps.latitude);
//RCLCPP_INFO(this->get_logger(), "first_gps.longitude %f", first_gps.longitude);
//RCLCPP_INFO(this->get_logger(), "gps_x %f", gps_x);
//RCLCPP_INFO(this->get_logger(), "gps_y %f", gps_y);


position.latitude = gps_x;
RCLCPP_INFO(this->get_logger(), "position.latitude %f\n", position.latitude);
//RCLCPP_INFO(this->get_logger(), "position.latitude %f\n", position.latitude);
position.longitude = gps_y;
RCLCPP_INFO(this->get_logger(), "position.longitude %f\n", position.longitude);
//RCLCPP_INFO(this->get_logger(), "position.longitude %f\n", position.longitude);
}

if (this->last_gps_assigned = true) {
Expand Down
26 changes: 13 additions & 13 deletions autonav_ws/src/autonav_filters/src/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ def system_state_transition(self, old: SystemState, updated: SystemState):
self.onReset()

def onGPSReceived(self, msg: GPSFeedback):
self.get_logger().info("RECEIVED GPS")
#self.get_logger().info("RECEIVED GPS")
if msg.gps_fix == 0 and msg.is_locked == False:
return

if self.firstGps is None:
self.firstGps = msg

self.get_logger().info(f"firstGps.latitude {self.firstGps.latitude}\n")
self.get_logger().info(f"firstGps.longitude {self.firstGps.longitude}\n")
#self.get_logger().info(f"firstGps.latitude {self.firstGps.latitude}\n")
#self.get_logger().info(f"firstGps.longitude {self.firstGps.longitude}\n")

self.lastGps = msg

Expand All @@ -111,30 +111,30 @@ def onMotorFeedbackReceived(self, msg: MotorFeedback):
position = Position()
position.x = averages[0]
position.y = averages[1]
self.get_logger().info(f"position.x {position.x}\n")
self.get_logger().info(f"position.y {position.y}\n")
#self.get_logger().info(f"position.x {position.x}\n")
#self.get_logger().info(f"position.y {position.y}\n")
position.theta = (-1 * math.pi * 2 + averages[2]) * 1
self.get_logger().info(f"position.theta {position.theta}\n")
#self.get_logger().info(f"position.theta {position.theta}\n")

if self.firstGps is not None:
gps_x = self.firstGps.latitude + position.x / self.latitudeLength
gps_y = self.firstGps.longitude - position.y / self.longitudeLength
self.get_logger().info(f"firstGps.latitude {self.firstGps.latitude}\n")
self.get_logger().info(f"firstGps.longitude {self.firstGps.longitude}\n")
self.get_logger().info(f"gps_x {gps_x}\n")
self.get_logger().info(f"gps_y {gps_y}\n")
#self.get_logger().info(f"firstGps.latitude {self.firstGps.latitude}\n")
#self.get_logger().info(f"firstGps.longitude {self.firstGps.longitude}\n")
#self.get_logger().info(f"gps_x {gps_x}\n")
#self.get_logger().info(f"gps_y {gps_y}\n")

position.latitude = gps_x
self.get_logger().info(f"position.latitude {position.latitude}\n")
#self.get_logger().info(f"position.latitude {position.latitude}\n")
position.longitude = gps_y
self.get_logger().info(f"position.longitude {position.longitude}\n")
#self.get_logger().info(f"position.longitude {position.longitude}\n")

if self.system_mode == SystemModeEnum.SIMULATION and self.lastGps is not None:
#position.latitude = self.lastGps.latitude
#position.longitude = self.lastGps.longitude
print("do nothing")

self.get_logger().info(f"averages 0: {averages[0]}, averages 1: {averages[1]}, averages 2: {averages[2]}")
#self.get_logger().info(f"averages 0: {averages[0]}, averages 1: {averages[1]}, averages 2: {averages[2]}")
#self.get_logger().info(f"publishing position x: {position.x}, y: {position.y}, {position.theta}")
#self.get_logger().info(f"position latitude: {position.latitude}, longitude {position.longitude}")
self.positionPublisher.publish(position)
Expand Down
1 change: 0 additions & 1 deletion autonav_ws/src/autonav_filters/src/filters_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

int main (int argc, char * argv[]) {
rclcpp::init(argc, argv);
//rclcpp::spin(std::make_shared<FiltersNode>());
SCR::Node::run_node(std::make_shared<FiltersNode>());
rclcpp::shutdown();
return 0;
Expand Down
30 changes: 15 additions & 15 deletions autonav_ws/src/autonav_filters/tests/particle_filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "autonav_filters/rapidcsv.h"

TEST(ParticleFilterTests, initialization_test) {
GTEST_SKIP() << "Skipping init test";
double latitudeLength = 111086.2;
double longitudeLength = 81978.2;
ParticleFilter particle_filter = ParticleFilter(latitudeLength, longitudeLength);
Expand Down Expand Up @@ -40,14 +39,14 @@ TEST(ParticleFilterTests, feedback_test) {
std::vector<double> delta_ys = motor_feedback_sheet.GetColumn<double>(3);
std::vector<double> delta_thetas = motor_feedback_sheet.GetColumn<double>(4);

printf("delta_xs size: %ld\n", delta_xs.size());
//printf("delta_xs size: %ld\n", delta_xs.size());

std::vector sliced_delta_xs(delta_xs.begin(), delta_xs.begin() + 1402);
std::vector sliced_delta_ys(delta_ys.begin(), delta_ys.begin() + 1402);
std::vector sliced_delta_thetas(delta_thetas.begin(), delta_thetas.begin() + 1402);
printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());
printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());
printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());
// printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());
// printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());
// printf("sliced_delta_xs size: %ld\n", sliced_delta_xs.size());


double latitudeLength = 111086.2;
Expand All @@ -68,17 +67,17 @@ TEST(ParticleFilterTests, feedback_test) {
position_vector = particle_filter.feedback(motor_message);
}

printf("%f\n", position_vector[0]);
printf("%f\n", position_vector[1]);
printf("%f\n", position_vector[2]);
// printf("%f\n", position_vector[0]);
// printf("%f\n", position_vector[1]);
// printf("%f\n", position_vector[2]);

EXPECT_EQ(position_vector[0], 1.4589810840940724e-15);
EXPECT_EQ(position_vector[1], -1.1226575225009583e-14);
EXPECT_EQ(position_vector[2], 3.4728605908690113);
}

TEST(ParticleFilterTests, gps_test) {
GTEST_SKIP() << "Skipping gps_test";
//GTEST_SKIP() << "Skipping gps_test";
double latitudeLength = 111086.2;
double longitudeLength = 81978.2;
ParticleFilter particle_filter = ParticleFilter(latitudeLength, longitudeLength);
Expand All @@ -101,6 +100,7 @@ TEST(ParticleFilterTests, gps_test) {
}

TEST(ParticleFilterTests, complete_test) {
// This test will fail sometimes because the particle filter is non-deterministic
double latitudeLength = 111086.2;
double longitudeLength = 81978.2;
ParticleFilter particle_filter = ParticleFilter(latitudeLength, longitudeLength);
Expand Down Expand Up @@ -143,11 +143,11 @@ TEST(ParticleFilterTests, complete_test) {
std::vector<double> gps_vector;
for (int i = 0; i < n; i++) {
motor_message.delta_x = sliced_delta_xs[i];
printf("motor_mesage delta_x %f\n", motor_message.delta_x);
//printf("motor_mesage delta_x %f\n", motor_message.delta_x);
motor_message.delta_y = sliced_delta_ys[i];
printf("motor_mesage delta_y %f\n", motor_message.delta_y);
//printf("motor_mesage delta_y %f\n", motor_message.delta_y);
motor_message.delta_theta = sliced_delta_thetas[i];
printf("motor_mesage delta_theta %f\n\n", motor_message.delta_theta);
//printf("motor_mesage delta_theta %f\n\n", motor_message.delta_theta);

gps_message.latitude = latitudes[i];
gps_message.longitude = longitudes[i];
Expand All @@ -164,9 +164,9 @@ TEST(ParticleFilterTests, complete_test) {
printf("%f\n", position_vector[1]);
printf("%f\n", position_vector[2]);

ASSERT_NEAR(position_vector[0], 18.49585229987204, 1.0);
ASSERT_NEAR(position_vector[1], 18.936964199952953, 1.0);
ASSERT_NEAR(position_vector[2], 1.0485518625679005, 1.0);
ASSERT_NEAR(position_vector[0], 17.507143650199076, 1.0);
ASSERT_NEAR(position_vector[1], 17.762181504279035, 1.0);
ASSERT_NEAR(position_vector[2], 4.3224496833375365, 1.0);

/*std::filesystem::path cwd = std::filesystem::current_path();
std::string cwd_str = cwd.string();
Expand Down

0 comments on commit 8086169

Please sign in to comment.