|
|
|
@ -16,14 +16,15 @@ bool Copter::start_takeoff(float alt)
@@ -16,14 +16,15 @@ bool Copter::start_takeoff(float alt)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set target location (for use by scripting)
|
|
|
|
|
bool Copter::set_target_location(const Location& target_loc) |
|
|
|
|
bool Copter::set_target_location(const Location& target_loc,int32_t yaw_cd) |
|
|
|
|
{ |
|
|
|
|
// exit if vehicle is not in Guided mode or Auto-Guided mode
|
|
|
|
|
if (!flightmode->in_guided_mode()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return mode_guided.set_destination(target_loc); |
|
|
|
|
// return mode_guided.set_destination(target_loc);
|
|
|
|
|
return mode_guided.set_destination(target_loc, true, (float)yaw_cd, true, 200.0, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set target position (for use by scripting)
|
|
|
|
@ -56,6 +57,14 @@ bool Copter::set_target_velocity_NED(const Vector3f& vel_ned)
@@ -56,6 +57,14 @@ bool Copter::set_target_velocity_NED(const Vector3f& vel_ned)
|
|
|
|
|
|
|
|
|
|
void Copter::zr_app_10hz() |
|
|
|
|
{ |
|
|
|
|
if(zr_serial_api.data_trans_init){ |
|
|
|
|
// void AC_ZR_Serial_API::get_vehicle_status(uint8_t mode,uint8_t in_air,uint32_t home_distance,uint16_t volt_mv,uint8_t bat_remaining)
|
|
|
|
|
uint16_t now_volt = uint16_t(battery.voltage() * 100); |
|
|
|
|
zr_serial_api.get_vehicle_status((uint8_t)control_mode,(uint8_t)flightmode->is_landing(),home_distance(),now_volt,battery.capacity_remaining_pct()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
void Copter::zr_app_50hz(){ |
|
|
|
|
|
|
|
|
|
if(zr_serial_api.data_trans_init){ |
|
|
|
|
zr_serial_api.update(); |
|
|
|
@ -69,15 +78,6 @@ void Copter::zr_app_10hz()
@@ -69,15 +78,6 @@ void Copter::zr_app_10hz()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(zr_serial_api.data_trans_init){ |
|
|
|
|
// void AC_ZR_Serial_API::get_vehicle_status(uint8_t mode,uint8_t in_air,uint32_t home_distance,uint16_t volt_mv,uint8_t bat_remaining)
|
|
|
|
|
uint16_t now_volt = uint16_t(battery.voltage() * 100); |
|
|
|
|
zr_serial_api.get_vehicle_status((uint8_t)control_mode,(uint8_t)flightmode->is_landing(),home_distance(),now_volt,battery.capacity_remaining_pct()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
void Copter::zr_app_50hz(){ |
|
|
|
|
|
|
|
|
|
if(zr_serial_api.data_trans_init){ |
|
|
|
|
Vector3l pos_neu_cm; |
|
|
|
|
|
|
|
|
@ -117,6 +117,8 @@ void Copter::zr_app_50hz(){
@@ -117,6 +117,8 @@ void Copter::zr_app_50hz(){
|
|
|
|
|
float yaw_deg; |
|
|
|
|
bool new_data = zr_serial_api.get_control_data((uint8_t)control_mode ,msg_type,data,yaw_deg); |
|
|
|
|
if(new_data){ |
|
|
|
|
|
|
|
|
|
int32_t ahrs_yaw_cd = wrap_360_cd(int32_t(yaw_deg * 100)); |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"get msg_type:%d, data:%ld,%ld,%ld, y:%.2f",(int)msg_type,data.x,data.y,data.z,yaw_deg); |
|
|
|
|
switch (msg_type) |
|
|
|
|
{ |
|
|
|
@ -140,21 +142,50 @@ void Copter::zr_app_50hz(){
@@ -140,21 +142,50 @@ void Copter::zr_app_50hz(){
|
|
|
|
|
target_loc.lng = data.y; |
|
|
|
|
target_loc.alt = (data.z + 500); |
|
|
|
|
// target_loc.alt = (data.z + 500)/100.0;
|
|
|
|
|
set_target_location(target_loc); |
|
|
|
|
set_target_location(target_loc,ahrs_yaw_cd); |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"set location,lat %ld,%ld,%ld",target_loc.lat,target_loc.lng,target_loc.alt); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case AC_ZR_Serial_API::ZR_Msg_Type::MSG_CONTROL_VEL: |
|
|
|
|
if(motors->armed()){ |
|
|
|
|
Vector3f target_vel; |
|
|
|
|
target_vel.x = data.x / 100.0; |
|
|
|
|
target_vel.y = data.y / 100.0; |
|
|
|
|
target_vel.z = data.z / 100.0; |
|
|
|
|
target_vel.x = data.x / 1.0; |
|
|
|
|
target_vel.y = data.y / 1.0; |
|
|
|
|
target_vel.z = data.z / 1.0; |
|
|
|
|
// target_loc.alt = (data.z + 500)/100.0;
|
|
|
|
|
set_target_velocity_NED(target_vel); |
|
|
|
|
// set_target_velocity_NED(target_vel);
|
|
|
|
|
mode_guided.set_velocity(target_vel,true,ahrs_yaw_cd,false,0.0f,false,true); |
|
|
|
|
|
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"set vel %.2f,%.2f,%.2f",target_vel.x,target_vel.y,target_vel.z); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case AC_ZR_Serial_API::ZR_Msg_Type::MSG_CONTROL_VEL_P: |
|
|
|
|
if(motors->armed()){ |
|
|
|
|
Vector3f target_vel; |
|
|
|
|
target_vel.x = data.x / 1.0; |
|
|
|
|
target_vel.y = data.y / 1.0; |
|
|
|
|
target_vel.z = data.z / 1.0; |
|
|
|
|
// float speed_forward = target_vel.x * ahrs.cos_yaw() + target_vel.y * ahrs.sin_yaw();
|
|
|
|
|
// float speed_right = -target_vel.x * ahrs.sin_yaw() + target_vel.y * ahrs.cos_yaw();
|
|
|
|
|
|
|
|
|
|
// rotate from body-frame to NE frame
|
|
|
|
|
const float ne_x = target_vel.x * ahrs.cos_yaw() - target_vel.y * ahrs.sin_yaw(); |
|
|
|
|
const float ne_y = target_vel.x * ahrs.sin_yaw() + target_vel.y * ahrs.cos_yaw(); |
|
|
|
|
// target_loc.alt = (data.z + 500)/100.0;
|
|
|
|
|
// set_target_velocity_NED(target_vel);
|
|
|
|
|
|
|
|
|
|
// exit if vehicle is not in Guided mode or Auto-Guided mode
|
|
|
|
|
if (!flightmode->in_guided_mode()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// convert vector to neu in cm
|
|
|
|
|
const Vector3f vel_neu_cms(ne_x, ne_y, -target_vel.z); |
|
|
|
|
mode_guided.set_velocity(vel_neu_cms,true,ahrs_yaw_cd,false,0.0f,false,true); |
|
|
|
|
|
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"set speed %.2f,%.2f,%.2f,yaw:%ld",ne_x,ne_y,target_vel.z,ahrs_yaw_cd); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|