PX4 Firmware
PX4 Autopilot Software http://px4.io
Simulator Class Reference

#include <simulator.h>

Inheritance diagram for Simulator:
Collaboration diagram for Simulator:

Classes

struct  _hil_local_proj_ref
 

Public Types

enum  InternetProtocol { InternetProtocol::TCP, InternetProtocol::UDP }
 

Public Member Functions

bool getGPSSample (uint8_t *buf, int len)
 
void write_gps_data (void *buf)
 
void set_ip (InternetProtocol ip)
 
void set_port (unsigned port)
 

Static Public Member Functions

static SimulatorgetInstance ()
 
static int start (int argc, char *argv[])
 

Private Member Functions

 Simulator ()
 
 ~Simulator ()
 
int publish_flow_topic (const mavlink_hil_optical_flow_t *flow)
 
int publish_odometry_topic (const mavlink_message_t *odom_mavlink)
 
int publish_distance_topic (const mavlink_distance_sensor_t *dist)
 
mavlink_hil_actuator_controls_t actuator_controls_from_outputs (const actuator_outputs_s &actuators)
 
void handle_message (const mavlink_message_t *msg)
 
void handle_message_distance_sensor (const mavlink_message_t *msg)
 
void handle_message_hil_gps (const mavlink_message_t *msg)
 
void handle_message_hil_sensor (const mavlink_message_t *msg)
 
void handle_message_hil_state_quaternion (const mavlink_message_t *msg)
 
void handle_message_landing_target (const mavlink_message_t *msg)
 
void handle_message_odometry (const mavlink_message_t *msg)
 
void handle_message_optical_flow (const mavlink_message_t *msg)
 
void handle_message_rc_channels (const mavlink_message_t *msg)
 
void handle_message_vision_position_estimate (const mavlink_message_t *msg)
 
void parameters_update (bool force)
 
void poll_topics ()
 
void poll_for_MAVLink_messages ()
 
void request_hil_state_quaternion ()
 
void send ()
 
void send_controls ()
 
void send_heartbeat ()
 
void send_mavlink_message (const mavlink_message_t &aMsg)
 
void update_sensors (const hrt_abstime &time, const mavlink_hil_sensor_t &imu)
 
void update_gps (const mavlink_hil_gps_t *gps_sim)
 

Static Private Member Functions

static void * sending_trampoline (void *)
 

Private Attributes

PX4Accelerometer _px4_accel {1311244, ORB_PRIO_DEFAULT, ROTATION_NONE}
 
PX4Gyroscope _px4_gyro {2294028, ORB_PRIO_DEFAULT, ROTATION_NONE}
 
PX4Magnetometer _px4_mag {197388, ORB_PRIO_DEFAULT, ROTATION_NONE}
 
PX4Barometer _px4_baro {6620172, ORB_PRIO_DEFAULT}
 
simulator::Report< simulator::RawGPSData_gps {1}
 
perf_counter_t _perf_gps {perf_alloc_once(PC_ELAPSED, "sim_gps_delay")}
 
perf_counter_t _perf_sim_delay {perf_alloc_once(PC_ELAPSED, "sim_network_delay")}
 
perf_counter_t _perf_sim_interval {perf_alloc(PC_INTERVAL, "sim_network_interval")}
 
orb_advert_t _battery_pub {nullptr}
 
orb_advert_t _differential_pressure_pub {nullptr}
 
orb_advert_t _dist_pub {nullptr}
 
orb_advert_t _flow_pub {nullptr}
 
orb_advert_t _irlock_report_pub {nullptr}
 
orb_advert_t _visual_odometry_pub {nullptr}
 
uORB::Subscription _parameter_update_sub {ORB_ID(parameter_update)}
 
unsigned int _port {14560}
 
InternetProtocol _ip {InternetProtocol::UDP}
 
double _realtime_factor {1.0}
 How fast the simulation runs in comparison to real system time. More...
 
hrt_abstime _last_sim_timestamp {0}
 
hrt_abstime _last_sitl_timestamp {0}
 
Battery _battery {}
 
battery_status_s _battery_status {}
 
orb_advert_t _vehicle_angular_velocity_pub {nullptr}
 
orb_advert_t _attitude_pub {nullptr}
 
orb_advert_t _gpos_pub {nullptr}
 
orb_advert_t _lpos_pub {nullptr}
 
orb_advert_t _rc_channels_pub {nullptr}
 
int _actuator_outputs_sub {-1}
 
int _vehicle_status_sub {-1}
 
bool _hil_local_proj_inited {false}
 
double _hil_ref_lat {0}
 
double _hil_ref_lon {0}
 
float _hil_ref_alt {0.0f}
 
uint64_t _hil_ref_timestamp {0}
 
input_rc_s _rc_input {}
 
manual_control_setpoint_s _manual {}
 
vehicle_attitude_s _attitude {}
 
vehicle_status_s _vehicle_status {}
 

Static Private Attributes

static Simulator_instance = nullptr
 

Detailed Description

Definition at line 156 of file simulator.h.

Member Enumeration Documentation

◆ InternetProtocol

Enumerator
TCP 
UDP 

Definition at line 161 of file simulator.h.

Constructor & Destructor Documentation

◆ Simulator()

Simulator::Simulator ( )
inlineprivate

Definition at line 176 of file simulator.h.

References simulator::RawGPSData::eph, and hrt_absolute_time().

Here is the call graph for this function:

◆ ~Simulator()

Simulator::~Simulator ( )
inlineprivate

Definition at line 191 of file simulator.h.

References perf_free().

Here is the call graph for this function:

Member Function Documentation

◆ actuator_controls_from_outputs()

mavlink_hil_actuator_controls_t Simulator::actuator_controls_from_outputs ( const actuator_outputs_s actuators)
private

Definition at line 77 of file simulator_mavlink.cpp.

References armed, hrt_absolute_time(), mode_flag_armed, mode_flag_custom, msg, actuator_outputs_s::output, PWM_DEFAULT_MAX, and PWM_DEFAULT_MIN.

Here is the call graph for this function:

◆ getGPSSample()

bool Simulator::getGPSSample ( uint8_t *  buf,
int  len 
)

Definition at line 68 of file simulator.cpp.

Referenced by GPSSIM::receive().

Here is the caller graph for this function:

◆ getInstance()

Simulator * Simulator::getInstance ( )
static

Definition at line 63 of file simulator.cpp.

Referenced by GPSSIM::receive(), and simulator_main().

Here is the caller graph for this function:

◆ handle_message()

void Simulator::handle_message ( const mavlink_message_t *  msg)
private

Definition at line 291 of file simulator_mavlink.cpp.

◆ handle_message_distance_sensor()

void Simulator::handle_message_distance_sensor ( const mavlink_message_t *  msg)
private

Definition at line 332 of file simulator_mavlink.cpp.

◆ handle_message_hil_gps()

void Simulator::handle_message_hil_gps ( const mavlink_message_t *  msg)
private

Definition at line 339 of file simulator_mavlink.cpp.

◆ handle_message_hil_sensor()

void Simulator::handle_message_hil_sensor ( const mavlink_message_t *  msg)
private

Definition at line 347 of file simulator_mavlink.cpp.

References abstime_to_ts(), armed, f(), math::gradual(), hrt_absolute_time(), hrt_abstime, hrt_elapsed_time(), math::max(), ORB_ID, ORB_PRIO_HIGH, and orb_publish_auto().

Here is the call graph for this function:

◆ handle_message_hil_state_quaternion()

◆ handle_message_landing_target()

void Simulator::handle_message_landing_target ( const mavlink_message_t *  msg)
private

Definition at line 513 of file simulator_mavlink.cpp.

References hrt_absolute_time(), ORB_ID, ORB_PRIO_HIGH, orb_publish_auto(), irlock_report_s::pos_x, irlock_report_s::pos_y, irlock_report_s::signature, irlock_report_s::size_x, irlock_report_s::size_y, and irlock_report_s::timestamp.

Here is the call graph for this function:

◆ handle_message_odometry()

void Simulator::handle_message_odometry ( const mavlink_message_t *  msg)
private

Definition at line 531 of file simulator_mavlink.cpp.

◆ handle_message_optical_flow()

void Simulator::handle_message_optical_flow ( const mavlink_message_t *  msg)
private

Definition at line 536 of file simulator_mavlink.cpp.

◆ handle_message_rc_channels()

void Simulator::handle_message_rc_channels ( const mavlink_message_t *  msg)
private

Definition at line 543 of file simulator_mavlink.cpp.

References fill_rc_input_msg(), ORB_ID, ORB_PRIO_HIGH, orb_publish_auto(), and rc_channels.

Here is the call graph for this function:

◆ handle_message_vision_position_estimate()

void Simulator::handle_message_vision_position_estimate ( const mavlink_message_t *  msg)
private

Definition at line 554 of file simulator_mavlink.cpp.

◆ parameters_update()

void Simulator::parameters_update ( bool  force)
private

Definition at line 78 of file simulator.cpp.

◆ poll_for_MAVLink_messages()

void Simulator::poll_for_MAVLink_messages ( )
private

Definition at line 660 of file simulator_mavlink.cpp.

References _addrlen, _buf, _fd, _srcaddr, B460800, B921600, msg, ORB_ID, orb_subscribe(), orb_subscribe_multi(), orb_unsubscribe(), read(), sending_trampoline(), and system_sleep.

Here is the call graph for this function:

◆ poll_topics()

void Simulator::poll_topics ( )
private

Definition at line 580 of file simulator_mavlink.cpp.

References orb_check(), orb_copy(), and ORB_ID.

Here is the call graph for this function:

◆ publish_distance_topic()

int Simulator::publish_distance_topic ( const mavlink_distance_sensor_t *  dist)
private

◆ publish_flow_topic()

◆ publish_odometry_topic()

int Simulator::publish_odometry_topic ( const mavlink_message_t *  odom_mavlink)
private

◆ request_hil_state_quaternion()

void Simulator::request_hil_state_quaternion ( )
private

Definition at line 639 of file simulator_mavlink.cpp.

◆ send()

void Simulator::send ( )
private

Definition at line 598 of file simulator_mavlink.cpp.

References mpu9x50::parameters_update(), and px4_poll().

Here is the call graph for this function:

◆ send_controls()

void Simulator::send_controls ( )
private

Definition at line 172 of file simulator_mavlink.cpp.

References orb_check(), orb_copy(), and ORB_ID.

Here is the call graph for this function:

◆ send_heartbeat()

void Simulator::send_heartbeat ( )
private

Definition at line 650 of file simulator_mavlink.cpp.

◆ send_mavlink_message()

void Simulator::send_mavlink_message ( const mavlink_message_t &  aMsg)
private

Definition at line 559 of file simulator_mavlink.cpp.

References _fd, _srcaddr, and send().

Here is the call graph for this function:

◆ sending_trampoline()

void * Simulator::sending_trampoline ( void *  )
staticprivate

Definition at line 592 of file simulator_mavlink.cpp.

Referenced by poll_for_MAVLink_messages().

Here is the caller graph for this function:

◆ set_ip()

void Simulator::set_ip ( InternetProtocol  ip)

Definition at line 121 of file simulator.cpp.

◆ set_port()

void Simulator::set_port ( unsigned  port)

Definition at line 126 of file simulator.cpp.

◆ start()

int Simulator::start ( int  argc,
char *  argv[] 
)
static

Definition at line 91 of file simulator.cpp.

References drv_led_start().

Referenced by simulator_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_gps()

void Simulator::update_gps ( const mavlink_hil_gps_t *  gps_sim)
private

◆ update_sensors()

void Simulator::update_sensors ( const hrt_abstime time,
const mavlink_hil_sensor_t &  imu 
)
private

Definition at line 222 of file simulator_mavlink.cpp.

References ll40ls::instance, ORB_ID, ORB_PRIO_DEFAULT, orb_publish_auto(), and differential_pressure_s::timestamp.

Here is the call graph for this function:

◆ write_gps_data()

void Simulator::write_gps_data ( void *  buf)

Definition at line 73 of file simulator.cpp.

Member Data Documentation

◆ _actuator_outputs_sub

int Simulator::_actuator_outputs_sub {-1}
private

Definition at line 280 of file simulator.h.

◆ _attitude

vehicle_attitude_s Simulator::_attitude {}
private

Definition at line 296 of file simulator.h.

◆ _attitude_pub

orb_advert_t Simulator::_attitude_pub {nullptr}
private

Definition at line 274 of file simulator.h.

◆ _battery

Battery Simulator::_battery {}
private

Definition at line 241 of file simulator.h.

◆ _battery_pub

orb_advert_t Simulator::_battery_pub {nullptr}
private

Definition at line 222 of file simulator.h.

◆ _battery_status

battery_status_s Simulator::_battery_status {}
private

Definition at line 242 of file simulator.h.

◆ _differential_pressure_pub

orb_advert_t Simulator::_differential_pressure_pub {nullptr}
private

Definition at line 223 of file simulator.h.

◆ _dist_pub

orb_advert_t Simulator::_dist_pub {nullptr}
private

Definition at line 224 of file simulator.h.

◆ _flow_pub

orb_advert_t Simulator::_flow_pub {nullptr}
private

Definition at line 225 of file simulator.h.

◆ _gpos_pub

orb_advert_t Simulator::_gpos_pub {nullptr}
private

Definition at line 275 of file simulator.h.

◆ _gps

simulator::Report<simulator::RawGPSData> Simulator::_gps {1}
private

Definition at line 215 of file simulator.h.

◆ _hil_local_proj_inited

bool Simulator::_hil_local_proj_inited {false}
private

Definition at line 286 of file simulator.h.

◆ _hil_ref_alt

float Simulator::_hil_ref_alt {0.0f}
private

Definition at line 290 of file simulator.h.

◆ _hil_ref_lat

double Simulator::_hil_ref_lat {0}
private

Definition at line 288 of file simulator.h.

◆ _hil_ref_lon

double Simulator::_hil_ref_lon {0}
private

Definition at line 289 of file simulator.h.

◆ _hil_ref_timestamp

uint64_t Simulator::_hil_ref_timestamp {0}
private

Definition at line 291 of file simulator.h.

◆ _instance

Simulator * Simulator::_instance = nullptr
staticprivate

Definition at line 207 of file simulator.h.

◆ _ip

InternetProtocol Simulator::_ip {InternetProtocol::UDP}
private

Definition at line 233 of file simulator.h.

◆ _irlock_report_pub

orb_advert_t Simulator::_irlock_report_pub {nullptr}
private

Definition at line 226 of file simulator.h.

◆ _last_sim_timestamp

hrt_abstime Simulator::_last_sim_timestamp {0}
private

Definition at line 237 of file simulator.h.

◆ _last_sitl_timestamp

hrt_abstime Simulator::_last_sitl_timestamp {0}
private

Definition at line 238 of file simulator.h.

◆ _lpos_pub

orb_advert_t Simulator::_lpos_pub {nullptr}
private

Definition at line 276 of file simulator.h.

◆ _manual

manual_control_setpoint_s Simulator::_manual {}
private

Definition at line 295 of file simulator.h.

◆ _parameter_update_sub

uORB::Subscription Simulator::_parameter_update_sub {ORB_ID(parameter_update)}
private

Definition at line 229 of file simulator.h.

◆ _perf_gps

perf_counter_t Simulator::_perf_gps {perf_alloc_once(PC_ELAPSED, "sim_gps_delay")}
private

Definition at line 217 of file simulator.h.

◆ _perf_sim_delay

perf_counter_t Simulator::_perf_sim_delay {perf_alloc_once(PC_ELAPSED, "sim_network_delay")}
private

Definition at line 218 of file simulator.h.

◆ _perf_sim_interval

perf_counter_t Simulator::_perf_sim_interval {perf_alloc(PC_INTERVAL, "sim_network_interval")}
private

Definition at line 219 of file simulator.h.

◆ _port

unsigned int Simulator::_port {14560}
private

Definition at line 231 of file simulator.h.

◆ _px4_accel

PX4Accelerometer Simulator::_px4_accel {1311244, ORB_PRIO_DEFAULT, ROTATION_NONE}
private

Definition at line 210 of file simulator.h.

◆ _px4_baro

PX4Barometer Simulator::_px4_baro {6620172, ORB_PRIO_DEFAULT}
private

Definition at line 213 of file simulator.h.

◆ _px4_gyro

PX4Gyroscope Simulator::_px4_gyro {2294028, ORB_PRIO_DEFAULT, ROTATION_NONE}
private

Definition at line 211 of file simulator.h.

◆ _px4_mag

PX4Magnetometer Simulator::_px4_mag {197388, ORB_PRIO_DEFAULT, ROTATION_NONE}
private

Definition at line 212 of file simulator.h.

◆ _rc_channels_pub

orb_advert_t Simulator::_rc_channels_pub {nullptr}
private

Definition at line 277 of file simulator.h.

◆ _rc_input

input_rc_s Simulator::_rc_input {}
private

Definition at line 294 of file simulator.h.

◆ _realtime_factor

double Simulator::_realtime_factor {1.0}
private

How fast the simulation runs in comparison to real system time.

Definition at line 235 of file simulator.h.

◆ _vehicle_angular_velocity_pub

orb_advert_t Simulator::_vehicle_angular_velocity_pub {nullptr}
private

Definition at line 273 of file simulator.h.

◆ _vehicle_status

vehicle_status_s Simulator::_vehicle_status {}
private

Definition at line 297 of file simulator.h.

◆ _vehicle_status_sub

int Simulator::_vehicle_status_sub {-1}
private

Definition at line 281 of file simulator.h.

◆ _visual_odometry_pub

orb_advert_t Simulator::_visual_odometry_pub {nullptr}
private

Definition at line 227 of file simulator.h.


The documentation for this class was generated from the following files: