From 52966a42e873f2bec640d0e75e0e7c422229c28a Mon Sep 17 00:00:00 2001 From: David St-Onge Date: Mon, 30 Jan 2017 21:58:48 -0500 Subject: [PATCH] gps transform --- include/roscontroller.h | 5 ++- src/buzzuav_closures.cpp | 6 +-- src/roscontroller.cpp | 79 +++++++++++++++++++++++++++------------- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/include/roscontroller.h b/include/roscontroller.h index 1aef836..c1f3b4a 100644 --- a/include/roscontroller.h +++ b/include/roscontroller.h @@ -97,7 +97,10 @@ private: void cvt_cartesian_coordinates(double neighbours_pos_payload [], double out[]); /*convert from spherical to cartesian coordinate system callback */ - void cvt_rangebearing_coordinates(double neighbours_pos_payload [], double out[]); + void cvt_rangebearing_coordinates(double neighbours_pos_payload [], double out[], double pos[]); + + /*convert from spherical to cartesian coordinate system callback */ + void cvt_rangebearing2D_coordinates(double neighbours_pos_payload [], double out[], double pos[]); /*battery status callback*/ void battery(const mavros_msgs::BatteryStatus::ConstPtr& msg); diff --git a/src/buzzuav_closures.cpp b/src/buzzuav_closures.cpp index 3996847..a40dd48 100644 --- a/src/buzzuav_closures.cpp +++ b/src/buzzuav_closures.cpp @@ -85,8 +85,8 @@ int buzzros_print(buzzvm_t vm) { z = cartesian_pos_payload[2]; try { out[2]=sqrt(pow(x,2.0)+pow(y,2.0)+pow(z,2.0))-EARTH_RADIUS; - out[1]=atan2(y,x)*180/M_PI; - out[0]=atan2(z,(sqrt(pow(x,2.0)+pow(y,2.0))))*180/M_PI; + out[1]=atan2(y,x)*180.0/M_PI; + out[0]=atan2(z,(sqrt(pow(x,2.0)+pow(y,2.0))))*180.0/M_PI; } catch (std::overflow_error e) { // std::cout << e.what() << " Error in convertion to spherical coordinate system "< spherical_pos[0]) { + if (pos[0] > spherical_pos[0]) { out[1] = M_PI/2; out[2] = 0; - } else if (cur_pos[0] < spherical_pos[0]) { + } else if (pos[0] < spherical_pos[0]) { out[1] = 0; out[2] = M_PI/2; } @@ -417,14 +446,13 @@ namespace rosbzz_node{ /*convert from cartesian to spherical coordinate system callback */ void roscontroller::cvt_spherical_coordinates(double cartesian_pos_payload [], double out[]){ - double x, y, z; - x = cartesian_pos_payload[0]; - y = cartesian_pos_payload[1]; - z = cartesian_pos_payload[2]; + double x = cartesian_pos_payload[0]; + double y = cartesian_pos_payload[1]; + double z = cartesian_pos_payload[2]; try { out[0]=sqrt(pow(x,2.0)+pow(y,2.0)+pow(z,2.0)); - out[1]=atan2(x,y); - out[2]=atan2(z,(sqrt(pow(x,2.0)+pow(y,2.0)))); + out[1]=atan2(y,x); + out[2]=atan2((sqrt(pow(x,2.0)+pow(y,2.0))),z); } catch (std::overflow_error e) { std::cout << e.what() << " Error in convertion to spherical coordinate system "<payload64[0]==(uint64_t)UPDATER_MESSAGE_CONSTANT && msg->payload64.size() > 10){ uint16_t obt_msg_size=sizeof(uint64_t)*(msg->payload64.size()); uint64_t message_obt[obt_msg_size]; @@ -472,13 +499,13 @@ namespace rosbzz_node{ //cout<<"[Debug:] obtaind message "<0){ @@ -505,8 +532,8 @@ namespace rosbzz_node{ memcpy(neighbours_pos_payload, message_obt, 3*sizeof(uint64_t)); buzz_utility::Pos_struct raw_neigh_pos(neighbours_pos_payload[0],neighbours_pos_payload[1],neighbours_pos_payload[2]); // cout<<"Got" << neighbours_pos_payload[0] <<", " << neighbours_pos_payload[1] << ", " << neighbours_pos_payload[2] << endl; - // double cvt_neighbours_pos_test[3]; - // cvt_rangebearing_coordinates(neighbours_pos_payload, cvt_neighbours_pos_test); + double cvt_neighbours_pos_test[3]; + cvt_rangebearing_coordinates(neighbours_pos_payload, cvt_neighbours_pos_test, cur_pos); /*Convert obtained position to relative CARTESIAN position*/ double cartesian_neighbours_pos[3], cartesian_cur_pos[3]; cvt_cartesian_coordinates(neighbours_pos_payload, cartesian_neighbours_pos); @@ -515,8 +542,8 @@ namespace rosbzz_node{ for(int i=0;i<3;i++){ neighbours_pos_payload[i]=cartesian_neighbours_pos[i]-cartesian_cur_pos[i]; } - double cvt_neighbours_pos_payload[3]; - cvt_spherical_coordinates(neighbours_pos_payload, cvt_neighbours_pos_payload); + double *cvt_neighbours_pos_payload = cvt_neighbours_pos_test; + // cvt_spherical_coordinates(neighbours_pos_payload, cvt_neighbours_pos_payload); /*Extract robot id of the neighbour*/ uint16_t* out = buzz_utility::u64_cvt_u16((uint64_t)*(message_obt+3)); cout << "Rel Pos of " << (int)out[1] << ": " << cvt_neighbours_pos_payload[0] << ", "<< cvt_neighbours_pos_payload[2] << ", "<< cvt_neighbours_pos_payload[3] << endl;