@ -357,6 +357,7 @@ RoverPositionControl::run()
@@ -357,6 +357,7 @@ RoverPositionControl::run()
_att_sp_sub = orb_subscribe ( ORB_ID ( vehicle_attitude_setpoint ) ) ;
_vehicle_attitude_sub = orb_subscribe ( ORB_ID ( vehicle_attitude ) ) ;
_sensor_combined_sub = orb_subscribe ( ORB_ID ( sensor_combined ) ) ;
/* rate limit control mode updates to 5Hz */
orb_set_interval ( _control_mode_sub , 200 ) ;
@ -368,17 +369,19 @@ RoverPositionControl::run()
@@ -368,17 +369,19 @@ RoverPositionControl::run()
parameters_update ( true ) ;
/* wakeup source(s) */
px4_pollfd_struct_t fds [ 4 ] { } ;
px4_pollfd_struct_t fds [ 5 ] ;
/* Setup of loop */
fds [ 0 ] . fd = _global_pos_sub ;
fds [ 0 ] . events = POLLIN ;
fds [ 1 ] . fd = _manual_control_setpoint_sub ;
fds [ 1 ] . events = POLLIN ;
fds [ 2 ] . fd = _vehicle_attitude_sub ; // Poll attitude
fds [ 2 ] . fd = _sensor_combined_sub ;
fds [ 2 ] . events = POLLIN ;
fds [ 3 ] . fd = _local_pos_sub ; // Added local position as source of position
fds [ 3 ] . fd = _vehicle_attitude_sub ; // Poll attitude
fds [ 3 ] . events = POLLIN ;
fds [ 4 ] . fd = _local_pos_sub ; // Added local position as source of position
fds [ 4 ] . events = POLLIN ;
while ( ! should_exit ( ) ) {
@ -404,7 +407,7 @@ RoverPositionControl::run()
@@ -404,7 +407,7 @@ RoverPositionControl::run()
bool manual_mode = _control_mode . flag_control_manual_enabled ;
/* only run controller if position changed */
if ( fds [ 0 ] . revents & POLLIN | | fds [ 3 ] . revents & POLLIN ) {
if ( fds [ 0 ] . revents & POLLIN | | fds [ 4 ] . revents & POLLIN ) {
perf_begin ( _loop_perf ) ;
/* load local copies */
@ -473,7 +476,7 @@ RoverPositionControl::run()
@@ -473,7 +476,7 @@ RoverPositionControl::run()
perf_end ( _loop_perf ) ;
}
if ( fds [ 2 ] . revents & POLLIN ) {
if ( fds [ 3 ] . revents & POLLIN ) {
vehicle_attitude_poll ( ) ;
@ -502,6 +505,24 @@ RoverPositionControl::run()
@@ -502,6 +505,24 @@ RoverPositionControl::run()
_act_controls . control [ actuator_controls_s : : INDEX_THROTTLE ] = _manual_control_setpoint . z ;
}
}
if ( fds [ 2 ] . revents & POLLIN ) {
orb_copy ( ORB_ID ( sensor_combined ) , _sensor_combined_sub , & _sensor_combined ) ;
//orb_copy(ORB_ID(vehicle_attitude), _vehicle_attitude_sub, &_vehicle_att);
_act_controls . timestamp = hrt_absolute_time ( ) ;
/* Only publish if any of the proper modes are enabled */
if ( _control_mode . flag_control_velocity_enabled | |
_control_mode . flag_control_attitude_enabled | |
_control_mode . flag_control_position_enabled | |
manual_mode ) {
/* publish the actuator controls */
_actuator_controls_pub . publish ( _act_controls ) ;
}
}
}
orb_unsubscribe ( _control_mode_sub ) ;
@ -510,6 +531,9 @@ RoverPositionControl::run()
@@ -510,6 +531,9 @@ RoverPositionControl::run()
orb_unsubscribe ( _manual_control_setpoint_sub ) ;
orb_unsubscribe ( _pos_sp_triplet_sub ) ;
orb_unsubscribe ( _vehicle_attitude_sub ) ;
orb_unsubscribe ( _sensor_combined_sub ) ;
warnx ( " exiting. \n " ) ;
}
int RoverPositionControl : : task_spawn ( int argc , char * argv [ ] )