49 return 180.0 /
M_PI * x;
53 return M_PI / 180.0 * x;
57 gazebo::physics::WorldPtr world,
58 gazebo::physics::ModelPtr model,
68 std::string bind_host = nh->
param<std::string>(
"gazebo_host",
"localhost");
69 int bind_port = nh->
param<
int>(
"gazebo_port", 14525);
70 std::string remote_host = nh->
param<std::string>(
"ROS_host",
"localhost");
71 int remote_port = nh->
param<
int>(
"ROS_port", 14520);
73 set_ports(bind_host, bind_port, remote_host, remote_port);
74 gzmsg <<
"ROSflight SIL Conneced to " << remote_host <<
":" << remote_port <<
" from " << bind_host <<
":" 106 double inclination =
nh_->
param<
double>(
"inclination", 1.14316156541);
107 double declination =
nh_->
param<
double>(
"declination", 0.198584539676);
181 double inclination_ = 1.14316156541;
182 double declination_ = 0.198584539676;
187 #if GAZEBO_MAJOR_VERSION >= 9 188 using SC = gazebo::common::SphericalCoordinates;
189 using Ang = ignition::math::Angle;
190 sph_coord_.SetSurfaceType(SC::SurfaceType::EARTH_WGS84);
195 sph_coord_.SetHeadingOffset(Ang(-
M_PI / 2.0));
226 y_acc = q_I_NWU.RotateVectorReverse(-
gravity_);
284 (*temperature) = 27.0;
291 ROS_ERROR(
"[gazebo_rosflight_sil] imu not responding");
338 double y_baro = 101325.0f * (float)pow((1 - 2.25694e-5 * alt), 5.2553);
349 (*pressure) = (float)y_baro;
350 (*temperature) = 27.0f;
363 static double rho_ = 1.225;
370 double y_as = rho_ * Va * Va / 2.0;
377 *diff_pressure = y_as;
453 return static_cast<float>(
latestRC_.values[channel] - 1000) / 1000.0;
465 pwm_outputs_[channel] = 1000 + (uint16_t)(1000 * value);
485 std::ifstream memory_file;
486 memory_file.open(directory +
"/mem.bin", std::ios::binary);
488 if (!memory_file.is_open())
490 ROS_ERROR(
"Unable to load rosflight memory file %s/mem.bin", directory.c_str());
494 memory_file.read((
char *)dest, len);
502 std::string mkdir_command =
"mkdir -p " + directory;
503 const int dir_err = system(mkdir_command.c_str());
507 ROS_ERROR(
"Unable to write rosflight memory file %s/mem.bin", directory.c_str());
511 std::ofstream memory_file;
512 memory_file.open(directory +
"/mem.bin", std::ios::binary);
513 memory_file.write((
char *)src, len);
570 return GAZEBO_MAJOR_VERSION >= 9;
577 #if GAZEBO_MAJOR_VERSION >= 9 578 using Vec3 = ignition::math::Vector3d;
579 using Coord = gazebo::common::SphericalCoordinates::CoordinateType;
591 local_vel += vel_noise;
593 Vec3 ecef_pos = sph_coord_.PositionTransform(local_pos, Coord::LOCAL, Coord::ECEF);
594 Vec3 ecef_vel = sph_coord_.VelocityTransform(local_vel, Coord::LOCAL, Coord::ECEF);
595 Vec3 lla = sph_coord_.PositionTransform(local_pos, Coord::LOCAL, Coord::SPHERICAL);
603 out.
vel_n = std::round(local_vel.X() * 1e3);
604 out.
vel_e = std::round(-local_vel.Y() * 1e3);
605 out.
vel_d = std::round(-local_vel.Z() * 1e3);
607 out.
fix_type = rosflight_firmware::GNSSFixType::GNSS_FIX_TYPE_FIX;
615 out.
ecef.x = std::round(ecef_pos.X() * 100);
616 out.
ecef.y = std::round(ecef_pos.Y() * 100);
617 out.
ecef.z = std::round(ecef_pos.Z() * 100);
618 out.
ecef.p_acc = std::round(out.
h_acc / 10.0);
619 out.
ecef.vx = std::round(ecef_vel.X() * 100);
620 out.
ecef.vy = std::round(ecef_vel.Y() * 100);
621 out.
ecef.vz = std::round(ecef_vel.Z() * 100);
632 return GAZEBO_MAJOR_VERSION >= 9;
637 #if GAZEBO_MAJOR_VERSION >= 9 638 using Vec3 = ignition::math::Vector3d;
639 using Vec3 = ignition::math::Vector3d;
640 using Coord = gazebo::common::SphericalCoordinates::CoordinateType;
652 local_vel += vel_noise;
656 Vec3 ecef_pos = sph_coord_.PositionTransform(local_pos, Coord::LOCAL, Coord::ECEF);
657 Vec3 ecef_vel = sph_coord_.VelocityTransform(local_vel, Coord::LOCAL, Coord::ECEF);
658 Vec3 lla = sph_coord_.PositionTransform(local_pos, Coord::LOCAL, Coord::SPHERICAL);
667 out.
vel_n = std::round(local_vel.X() * 1e3);
668 out.
vel_e = std::round(-local_vel.Y() * 1e3);
669 out.
vel_d = std::round(-local_vel.Z() * 1e3);
671 out.
fix_type = rosflight_firmware::GNSSFixType::GNSS_FIX_TYPE_FIX;
689 double vn = local_vel.X();
690 double ve = -local_vel.Y();
691 double ground_speed = std::sqrt(vn * vn + ve * ve);
692 out.
g_speed = std::round(ground_speed * 1000);
694 double head_mot = std::atan2(ve, vn);
#define GZ_COMPAT_SET_X(VECTOR, VALUE)
#define GZ_COMPAT_GET_GRAVITY(WORLD_PTR)
#define GZ_COMPAT_GET_WORLD_LINEAR_VEL(LINK_PTR)
uint8_t backup_memory_[BACKUP_SRAM_SIZE]
static constexpr size_t BACKUP_SRAM_SIZE
#define GZ_COMPAT_SET_Z(VECTOR, VALUE)
double horizontal_gps_stdev_
uint64_t rosflight_timestamp
gazebo::common::Time last_time_
gazebo::physics::WorldPtr world_
bool battery_voltage_present() const override
void baro_read(float *pressure, float *temperature) override
#define GZ_COMPAT_GET_Z(VECTOR)
bool gnss_has_new_data() override
double gyro_bias_walk_stdev_
std::uniform_real_distribution< double > uniform_distribution_
void clock_delay(uint32_t milliseconds) override
bool memory_write(const void *src, size_t len) override
double airspeed_bias_range_
void memory_init(void) override
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool diff_pressure_present(void) override
gazebo::math::Vector3 GazeboVector
bool sonar_present(void) override
void led1_off(void) override
void mag_read(float mag[3]) override
rosflight_firmware::GNSSData gnss_read() override
bool rc_lost(void) override
#define GZ_COMPAT_GET_X(VECTOR)
void sensors_init() override
bool backup_memory_read(void *dest, size_t len) override
bool gnss_present() override
double mag_bias_walk_stdev_
#define GZ_COMPAT_GET_RELATIVE_ANGULAR_VEL(LINK_PTR)
uint64_t next_imu_update_time_us_
void battery_voltage_set_multiplier(double multiplier) override
void gazebo_setup(gazebo::physics::LinkPtr link, gazebo::physics::WorldPtr world, gazebo::physics::ModelPtr model, ros::NodeHandle *nh, std::string mav_type)
float sonar_read(void) override
ros::Time last_rc_message_
void backup_memory_write(const void *src, size_t len) override
void led1_on(void) override
float battery_current_read() const override
void backup_memory_clear(size_t len) override
void diff_pressure_read(float *diff_pressure, float *temperature) override
void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override
void led0_on(void) override
std::normal_distribution< double > normal_distribution_
double acc_bias_walk_stdev_
uint32_t clock_millis() override
bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time_us) override
rosflight_msgs::RCRaw latestRC_
gazebo::common::Time boot_time_
#define GZ_COMPAT_GET_WORLD_POSE(LINK_PTR)
double vertical_gps_stdev_
void backup_memory_init() override
void board_reset(bool bootloader) override
gazebo::math::Pose GazeboPose
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
float battery_current_multiplier
gazebo::physics::LinkPtr link_
void imu_not_responding_error() override
bool new_imu_data() override
double airspeed_bias_walk_stdev_
uint32_t getNumPublishers() const
bool battery_current_present() const override
const std::string & getNamespace() const
#define GZ_COMPAT_GET_ROT(POSE)
void led1_toggle(void) override
void RCCallback(const rosflight_msgs::RCRaw &msg)
void gnss_update() override
double gps_velocity_stdev_
#define GZ_COMPAT_GET_WORLD_LINEAR_ACCEL(LINK_PTR)
void pwm_disable(void) override
float battery_voltage_read() const override
uint64_t clock_micros() override
void battery_current_set_multiplier(double multiplier) override
void set_ports(std::string bind_host, uint16_t bind_port, std::string remote_host, uint16_t remote_port)
uint16_t num_sensor_errors(void) override
float battery_voltage_multiplier
double baro_bias_walk_stdev_
#define GZ_COMPAT_GET_LENGTH(VECTOR)
uint64_t rosflight_timestamp
bool baro_present(void) override
float rc_read(uint8_t channel) override
GazeboVector inertial_magnetic_field_
#define GZ_COMPAT_GET_POS(POSE)
double time_since_epoch()
bool mag_present(void) override
std::default_random_engine random_generator_
void init_board(void) override
gazebo::physics::ModelPtr model_
uint64_t imu_update_period_us_
void rc_init(rc_type_t rc_type) override
rosflight_firmware::GNSSFull gnss_full_read() override
constexpr double deg2Rad(double x)
void led0_off(void) override
void led0_toggle(void) override
#define GZ_COMPAT_GET_SIM_TIME(WORLD_PTR)
void pwm_write(uint8_t channel, float value) override
#define GZ_COMPAT_GET_Y(VECTOR)
constexpr double rad2Deg(double x)
#define GZ_COMPAT_GET_RELATIVE_LINEAR_VEL(LINK_PTR)
bool memory_read(void *dest, size_t len) override
#define GZ_COMPAT_SET_Y(VECTOR, VALUE)
gazebo::math::Quaternion GazeboQuaternion