|
|
@ -66,6 +66,7 @@ |
|
|
|
#include <uORB/uORB.h> |
|
|
|
#include <uORB/uORB.h> |
|
|
|
#include <uORB/topics/distance_sensor.h> |
|
|
|
#include <uORB/topics/distance_sensor.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <systemlib/mavlink_log.h> |
|
|
|
using namespace time_literals; |
|
|
|
using namespace time_literals; |
|
|
|
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0])) |
|
|
|
#define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0])) |
|
|
@ -174,8 +175,16 @@ private: |
|
|
|
(ParamInt<px4::params::SENS_TF_3_ROT>) _p_sensor3_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_3_ROT>) _p_sensor3_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_4_ROT>) _p_sensor4_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_4_ROT>) _p_sensor4_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_5_ROT>) _p_sensor5_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_5_ROT>) _p_sensor5_rot, |
|
|
|
(ParamInt<px4::params::SENS_TF_6_ROT>) _p_sensor6_rot |
|
|
|
(ParamInt<px4::params::SENS_TF_6_ROT>) _p_sensor6_rot, |
|
|
|
|
|
|
|
(ParamFloat<px4::params::SENS_TF_AVD_D>) _p_tf_avoid_dist_m, |
|
|
|
|
|
|
|
(ParamInt<px4::params::SENS_TF_AVD_M>) _p_tf_avoid_mode, |
|
|
|
|
|
|
|
(ParamFloat<px4::params::CP_DIST>) _p_cp_dist, |
|
|
|
|
|
|
|
(ParamInt<px4::params::MPC_POS_MODE>) _param_mpc_pos_mode |
|
|
|
|
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
orb_advert_t _mavlink_log_pub{nullptr}; ///< mavlink log pub
|
|
|
|
|
|
|
|
float avoid_distance; |
|
|
|
|
|
|
|
int entra_avoid_area{0}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TFMINI_I2C::TFMINI_I2C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address) : |
|
|
|
TFMINI_I2C::TFMINI_I2C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address) : |
|
|
@ -235,6 +244,18 @@ TFMINI_I2C::init() |
|
|
|
px4_usleep(_measure_interval); |
|
|
|
px4_usleep(_measure_interval); |
|
|
|
} |
|
|
|
} |
|
|
|
printf("\n--------------------\n"); |
|
|
|
printf("\n--------------------\n"); |
|
|
|
|
|
|
|
// float avoid_dist = _p_tf_avoid_dist_m.get();
|
|
|
|
|
|
|
|
// int32_t avoid_mode = _p_tf_avoid_mode.get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(avoid_dist > 0.5f){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// _p_cp_dist.set(avoid_dist);
|
|
|
|
|
|
|
|
// _param_mpc_pos_mode.set(avoid_mode);
|
|
|
|
|
|
|
|
// printf("set avoid distance:%.2fm,mode:%d",(double)avoid_dist,avoid_mode);
|
|
|
|
|
|
|
|
avoid_distance = _p_cp_dist.get(); |
|
|
|
|
|
|
|
printf("get avoid distance:%.2fm,mode:%d\n",(double)avoid_distance,(uint8_t)_param_mpc_pos_mode.get()); |
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Return an error if no sensors were detected.
|
|
|
|
// Return an error if no sensors were detected.
|
|
|
|
if (_sensor_count == 0) { |
|
|
|
if (_sensor_count == 0) { |
|
|
@ -392,6 +413,15 @@ TFMINI_I2C::collect() |
|
|
|
// perf_end(_sample_perf);
|
|
|
|
// perf_end(_sample_perf);
|
|
|
|
// return ret_val;
|
|
|
|
// return ret_val;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if(avoid_distance - distance_m > 0.1f && !entra_avoid_area){ |
|
|
|
|
|
|
|
mavlink_log_info(&_mavlink_log_pub, "(%d)Enter obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m); |
|
|
|
|
|
|
|
printf("(%d)Enter obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m); |
|
|
|
|
|
|
|
entra_avoid_area = 1; |
|
|
|
|
|
|
|
}else if(distance_m - avoid_distance > 0.1f && entra_avoid_area){ |
|
|
|
|
|
|
|
entra_avoid_area = 0; |
|
|
|
|
|
|
|
printf("(%d)Out obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
perf_end(_sample_perf); |
|
|
|
perf_end(_sample_perf); |
|
|
|
return PX4_OK; |
|
|
|
return PX4_OK; |
|
|
|