Commit Graph

7333 Commits

Author SHA1 Message Date
Sean O\'Brien 6474aa2477 AP_HAL_AVR_SITL: added sensor delays to sitl. 2015-04-14 10:10:38 +10:00
Sean O\'Brien bfba8870e2 AP_HAL_AVR_SITL: added sensor delays to sitl. 2015-04-14 10:10:35 +10:00
Lucas De Marchi b292873304 AP_InertialSensor: fix starvation in L3G4200D
The main thread would always be blocked on the semaphore to read the
data from accelerometer and gyroscope. Especially if we have a slow
update of these values in _accumulate() due to the I2C transfer function
taking too much time: the timer thread would never give up the CPU,
causing starvation on the main thread.

This fixes the issue by reducing the critical region using a flip-buffer
so _accumulate() can work on its own copy of the data. Now that the
critical region is smaller, also avoid the semaphore and use a spinlock
instead.
2015-04-14 10:01:47 +10:00
Andrew Tridgell b17878c8c4 SITL: lower default GPS delay to 0.2 seconds
this matches typical uBlox
2015-04-14 09:57:47 +10:00
Andrew Tridgell d7249cc1e6 AP_AHRS: only use EKF for plane and rover if all data available
we need position and velocity to be working for plane and rover
2015-04-14 09:57:45 +10:00
Lucas De Marchi 996739df12 AP_Compass: Do not panic if compass is not found
Copter uses 2 compasses for linux configuration, but one of them may not
be available. Do not panic if a AK8963 isn't found.
2015-04-14 09:29:12 +10:00
Gustavo Jose de Sousa be67b019a7 AP_GPS: Add missing setup for GPS_AUTO_test
GPS_AUTO_test was missing some setup lines.
2015-04-14 09:27:41 +10:00
Andrew Tridgell 7f7d92913e HAL_Linux: allow running as non-root
this is needed for Replay, plus is very useful for debugging
2015-04-14 09:25:35 +10:00
Lucas De Marchi f049c8e4c5 AP_HAL_Linux: remove needless call to mlockall()
All threads share the same address space and have the same pages locked
into memory so it's not necessary to call mlockall() for each of them.

Grepping /proc/<tid>/status gives the same VmLck for all of them, even
when only the main thread locks the memory:

    # for i in `seq 477 482`; do \
	name=$(cat /proc/$i/comm); \
	vm=$(cat /proc/$i/status |grep VmLck); \
        echo -e "$name\t$vm"; \
    done
    ArduCopter.elf  VmLck:     57868 kB
    sched-timer     VmLck:     57868 kB
    sched-uart      VmLck:     57868 kB
    sched-rcin      VmLck:     57868 kB
    sched-tonealarm VmLck:     57868 kB
    sched-io        VmLck:     57868 kB
2015-04-14 09:17:21 +10:00
Lucas De Marchi b7355dc62b AP_HAL_Linux: set thread name for ease debug
Use pthread_setname_np() to set thread name so it's easier to debug
what't going on with each of them. This is the example output of the
relevant par of "ps -Leo class,rtprio,wchan,comm":

FF      12 futex_ ArduCopter.elf
FF      15 usleep sched-timer
FF      14 hrtime sched-uart
FF      13 poll_s sched-rcin
FF      11 hrtime sched-tonealarm
FF      10 hrtime sched-io
2015-04-14 09:17:21 +10:00
Lucas De Marchi 2c48434110 AP_HAL_Linux: use a table to initialize threads
Refactor function calls into a table and pass in the name so it can be
used in error message.
2015-04-14 09:17:21 +10:00
Lucas De Marchi e3d78b8960 AP_HAL_Linux: fix passing callback to member function
It's undefined behavior to pass the callback to pthread to a class
member like we were doing. Refactor the code so the callbacks are static
members.

This fixes the following warnings:

libraries/AP_HAL_Linux/Scheduler.cpp: In member function 'virtual void Linux::LinuxScheduler::init(void*)':
/home/lucas/p/dronecode/ardupilot/libraries/AP_HAL_Linux/Scheduler.cpp:61:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_timer_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:65:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_uart_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:69:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_rcin_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:73:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_tonealarm_thread);
                                                                            ^
libraries/AP_HAL_Linux/Scheduler.cpp:77:76: warning: converting from 'void* (Linux::LinuxScheduler::*)()' to 'Linux::LinuxScheduler::pthread_startroutine_t {aka void* (*)(void*)}' [-Wpmf-conversions]
                            (pthread_startroutine_t)&Linux::LinuxScheduler::_io_thread);
2015-04-14 09:17:20 +10:00
Lucas De Marchi 62c2f737d5 AP_HAL_Linux: fix setting RT priorities
LinuxScheduler::init() was not really working as it should. This was the
result of "ps -Leo class,rtprio,wchan,comm | grep ArduCopter":

FF      12 futex_ ArduCopter.elf
FF      12 usleep ArduCopter.elf
FF      12 hrtime ArduCopter.elf
FF      12 poll_s ArduCopter.elf
FF      12 hrtime ArduCopter.elf
FF      12 hrtime ArduCopter.elf

As can be seen all the threads run with the same priority, the one of the main
thread. There were basically 2 mistakes:

	1) pthread_attr_setschedpolicy() needs to be called before
	   pthread_attr_setschedparam(). Otherwise the latter will just return
	   an error and not set the priority

	2) pthread_create() defaults to ignore the priority and inherit the
	   it from the parent thread. pthread_attr_setinheritsched() needs to
	   be called to change the behavior to PTHREAD_EXPLICIT_SCHED. See
	   pthread_attr_setinheritsched(3) for an example program to test the
	   behaviors.

Also, it's undefined behavior to call pthread_attr_init() several times on the
same pthread_attr_t. Although we could reutilize the same attribute without
calling  pthread_attr_init() again, lets refactor the code a little bit, so all
the pthread calls are in a single place. Then also call pthread_attr_destroy()
when we are done.
2015-04-14 09:17:20 +10:00
Lucas De Marchi 29b667efdf AP_HAL_Linux: remove useless mlock of stack
In Linux the default stack size is always greater than 32k, either 2MB
or 8MB depending on the architecture. There's no point in creating a
function to lock 32k.
2015-04-14 09:17:20 +10:00
Randy Mackay e2071a4630 Notify: ToneAlarm fix to stopping continuous tones 2015-04-13 17:44:45 +09:00
Randy Mackay 2472702838 Notify: rename lost_copter to vehicle_lost 2015-04-13 17:44:44 +09:00
Jaime Machuca 043d24f03a Notify: add Lost Copter tone 2015-04-13 17:42:07 +09:00
Andrew Tridgell 0695277773 HAL_SITL: use pthread barriers for synthetic clock synchronisation
this avoids siganls and provides a race free way of keeping time in
lock step
2015-04-13 06:05:55 +10:00
Paul Riseborough e79ccf1fcc AP_NavEKF: Fix bug allowing terrain to be above vehicle position
The terrain state and vehicle state need to be compared at the same time horizon.
2015-04-11 15:51:08 +09:00
Paul Riseborough 6d58c63c4c AP_NavEKF: Prevent potential divide by zeros in OF fusion 2015-04-11 15:51:03 +09:00
Paul Riseborough 89142f1c5f AP_NavEKF: Prevent inadvertent use of DCM roll and pitch estimates.
the use of roll and pitch from the AHRS object is bad because that object could be returning estimates from the backup DCM algorithm.
2015-04-11 15:19:05 +09:00
Randy Mackay 56d2306a18 BattMon_SMBus_PX4: read capacity 2015-04-11 14:10:22 +09:00
Randy Mackay c6440a48b3 BattMon_Backend: add init and set_capacity methods 2015-04-11 14:10:19 +09:00
Paul Riseborough 9268024094 AP_NavEKF: Update default parameters for copter optical flow fusion 2015-04-10 11:08:11 +09:00
Paul Riseborough 4fbdab27ff AP_NavEKF: Use range finder for primary hgt ref in opt flow mode
Falls back to baro if range finder is unavailable
Adds parameter enabling user to select which height source (baro or range finder) will be used during optical flow nav.
2015-04-10 11:08:07 +09:00
Paul Riseborough ff9917d338 AP_AHRS: Fix bug preventing EKF from initialising 2015-04-10 11:07:42 +09:00
Paul Riseborough d618c55e2f AP_NavEKF: Improved handling of noisy GPS speed accuracy data 2015-04-10 11:07:34 +09:00
Paul Riseborough 53358a4e10 AP_OpticalFlow: Add parameter to compensate for flow sensor yaw angle
AP_OpticalFlow: update parameter name
2015-04-10 11:07:31 +09:00
Paul Riseborough cab171b580 AP_InertialNav: Add method to return EKF height above ground estimate
AP_InertialNav: Add validity flag to height above ground estimate
2015-04-10 11:07:27 +09:00
Paul Riseborough e98edaa6cb AP_NavEKF: Return more accurate validity status for height above ground 2015-04-10 11:07:24 +09:00
Paul Riseborough 586e4a7d2b AP_NavEKF: Add Matlab derivations and simulations behind small EKF 2015-04-10 11:07:21 +09:00
Jonathan Challinger dc5bdd5ad8 AP_AHRS: use filtered INS output to compute _accel_ef_blended 2015-04-09 20:19:56 +09:00
Randy Mackay a095a8c3a1 AC_PID: more protection against NaN and Inf 2015-04-09 20:19:55 +09:00
Randy Mackay bdfe8bbc54 AC_AttControl_Heli: remove RATE_RP_MAX, RATE_Y_MAX 2015-04-09 20:19:54 +09:00
Leonard Hall afcd1c6ec3 AC_AttitudeControl: sqrt controller on Stab 2015-04-09 20:19:43 +09:00
Leonard Hall ae77c18a19 AC_PID: Protect against NaN and INF 2015-04-09 18:30:12 +09:00
Andrzej Zaborowski 132cdc4916 Motors: Use _motor_to_channel_map in tricopter consistently.
In AP_MotorsTri.cpp the AP_MOTORS_MOT_1, _2 and _4 constants are
always mapped to actual output channels through _motor_to_channel_map
while the _CH_TRI_YAW is not, but there were a few inconsistencies
in this that could lead to things like PWM min and max values being
set on wrong channels.

It looks like all in all _motor_to_channel_map being in PROGMEM
probably doesn't help save memory and I'm not sure how useful it is
in the first place but regardless the usage should be consistent.
2015-04-09 11:43:22 +09:00
Randy Mackay 558018d839 InertialNav: add get_location method 2015-04-09 10:56:57 +09:00
Tom Pittenger 9ecbd0e30f AP_L1_Control: fixed uTurn-wobble
When performing a u-turn in AUTO (waypoints are 180deg turn from each other) sometimes the aircraft can't decide to turn left or right and wobbled back and forth a couple times. There was existing code to solve this but it was not executing all the time like when in LOITER mode. Frankly, I don't understand the criteria that was required to make it execute and i suspect there is still a gremlin in that logic but just executing the check all the time makes prevents the wobble behavior.
2015-04-08 15:21:02 -07:00
Jonathan Challinger 6e8008ab69 AP_SerialManager: use protocol_match in find_baudrate 2015-04-08 09:14:31 -07:00
Randy Mackay f260536373 AC_PID: fix example sketch compile error 2015-04-08 15:05:29 +09:00
Jonathan Challinger 6baec4952b AP_Math: add conversions to and from 3-1-2 euler angles 2015-04-07 21:20:51 -07:00
Jonathan Challinger a1d4f40c16 AP_Math: change quaternion operator* and operator/ to const 2015-04-07 21:20:51 -07:00
Jonathan Challinger 07735fefa6 AP_Math: fix div by zero in quaternion 2015-04-07 21:20:51 -07:00
Paul Riseborough c57e25142c AP_NavEKF: Update optical flow fusion maths to reduce height errors 2015-04-07 20:51:18 -07:00
Andrew Tridgell 35bac3ab4f GCS_MAVLink: regenerate without mavlink_frame_char changes 2015-04-06 16:43:02 -07:00
Andrew Tridgell df948e7358 AP_Mount: fixed for new GIMBAL_REPORT message 2015-04-06 16:42:23 -07:00
Andrew Tridgell 33824e0b2f GCS_MAVLink: re-ran generate.sh 2015-04-06 16:30:16 -07:00
Jonathan Challinger 73b8890bd3 GCS_MAVLink: move GIMBAL_REPORT and GIMBAL_CONTROL and reserve messages 2015-04-06 16:29:02 -07:00
myly10 55befdc345 AP_NavEKF: Typo correction for EAS_NOISE description 2015-04-06 15:52:29 -07:00