Monday, 28 July 2014

Saturday, 26 July 2014

How to build your own Quadcopter Autopilot / Flight Controller

Back to my home page
How to build your own Quadcopter Autopilot / Flight ControllerBy Dr Gareth Owen (drgowen@gmail.com)3DR QuadcopterFig 1: 3DR Quadcopter

Friday, 25 July 2014

Pseudovector

Physical examples of pseudovectors include magnetic field, torque, vorticity, and the angular momentum.
Each wheel of a car driving away from an observer has an angular momentum pseudovector pointing left. The same is true for the mirror image of the car.
Consider the pseudovector angular momentum L = r × p. Driving in a car, and looking forward, each of the wheels has an angular momentum vector pointing to the left. If the world is reflected in a mirror which switches the left and right side of the car, the "reflection" of this angular momentum "vector" (viewed as an ordinary vector) points to the right, but the actual angular momentum vector of the wheel (which is still turning forward in the reflection) still points to the left, corresponding to the extra minus sign in the reflection of a pseudovector.
The distinction between vectors and pseudovectors becomes important in understanding the effect of symmetry on the solution to physical systems. Consider an electrical current loop in the z = 0 plane that inside the loop generates a magnetic field oriented in the z direction. This system is symmetric (invariant) under mirror reflections through this plane, with the magnetic field unchanged by the reflection. But reflecting the magnetic field as a vector through that plane would be expected to reverse it; this expectation is corrected by realizing that the magnetic field is a pseudovector, with the extra sign flip leaving it unchanged.
http://www.altdev.co/2013/03/15/what-is-gimbal-lock-and-why-do-we-still-have-to-worry-about-it/
In linear algebra, an orthogonal matrix is a square matrix with real entries whose columns and rows are orthogonal unit vectors (i.e., orthonormal vectors), i.e.
Q^\mathrm{T} Q = Q Q^\mathrm{T} = I,


In mathematics, a linear map (also called a linear mapping, linear transformation or, in some contexts, linear function) is a mapping V ↦ W between two modules (includingvector spaces) that preserves (in the sense defined below) the operations of addition and scalar multiplication. 


In mathematics, the orthogonal group of dimension n, denoted O(n), is the group of distance-preserving transformations of aEuclidean space of dimension n that preserve a fixed point, where the group operation is given by composing transformations. 
Equivalently, it is the group of n×n orthogonal matrices of a given dimension, where the group operation is given by matrix multiplication, and an orthogonal matrix is a real matrix whose inverse equals its transpose.

The determinant of an orthogonal matrix being either 1 or −1, an important subgroup of O(n) is the special orthogonal group, denoted SO(n), of the orthogonal matrices of determinant 1. 

Thursday, 24 July 2014

mode control

-----------control_mode.pde--------------triggered by scheduler_tasks[] -> rc_loop() -> read_control_switch()
set_mode(flight_modes[switchPosition])
exit_mode(control_mode, mode);
control_mode = mode;
Log_Write_Mode(control_mode);
end

-----------flight_mode.pde--------------
triggered by update_flight_mode()
100hz or more (pixhawk 400hz, called directly in fast_loop)

switch (control_mode)
-- stabilize_run();
end

-----------control_stabilize.pde--------------
inside stabilize_run();

// convert pilot input to lean angles
get_pilot_desired_lean_angles(g.rc_1.control_in, g.rc_2.control_in, target_roll, target_pitch); (range 4500)
  • where does control_in come from:
    --radio.pde--
    init_rc_in()
  • g.rc_1.set_angle(ROLL_PITCH_INPUT_MAX); //4500
    g.rc_2.set_angle(ROLL_PITCH_INPUT_MAX);
    g.rc_3.set_range(g.throttle_min, g.throttle_max);
    g.rc_4.set_angle(4500);

    g.rc_1.set_type(RC_CHANNEL_TYPE_ANGLE_RAW);
    g.rc_2.set_type(RC_CHANNEL_TYPE_ANGLE_RAW);
    g.rc_4.set_type(RC_CHANNEL_TYPE_ANGLE_RAW);

    --RCchannel.cpp--
    --set_pwm_no_deadzone(int16_t pwm)--
    if (_type == RC_CHANNEL_TYPE_RANGE) {
            control_in = pwm_to_range_dz(0);
        } else {
            //RC_CHANNEL_ANGLE, RC_CHANNEL_ANGLE_RAW
            control_in = pwm_to_angle_dz(0);
        }

// get pilot's desired yaw rate
target_yaw_rate = get_pilot_desired_yaw_rate(g.rc_4.control_in);

// get pilot's desired throttle
pilot_throttle_scaled = get_pilot_desired_throttle(g.rc_3.control_in);

// call attitude controller
attitude_control.angle_ef_roll_pitch_rate_ef_yaw_smooth(target_roll, target_pitch, target_yaw_rate, get_smoothing_gain());
parameter used above : RC_FEEL_RP, ACCEL_RP_MAX
  •  // calculate earth-frame feed forward roll rate using linear response when close to the target, sqrt response when we're further away
        angle_to_target = roll_angle_ef (=target_roll,-4500~+4500) - _angle_ef_target.x (angle controller earth-frame targets);
angle_to_target -> calculate rate_ef_desired (linear or sqrt response) -> limit the rate _rate_ef_desired.x ->update new _angle_ef_target,angle_ef_error, update_ef_roll_angle_and_error(_rate_ef_desired.x, angle_ef_error (to be received from the funtion), AC_ATTITUDE_RATE_STAB_ROLL_OVERSHOOT_ANGLE_MAX);


// body-frame rate controller is run directly from 100hz loop

// output pilot's throttle
attitude_control.set_throttle_out(pilot_throttle_scaled, true);

Wednesday, 23 July 2014

Acc and mag direction

Accelerometer: 
x +: accelerate to the front
y +: accelerate to the right
z +: accelerate to the up

Magnetometer:
x +: rotating to the right
y +: rotating to the back
z +: yawing to the right

Roll, Pitch, Yaw:
Roll +: roll to the right
Pitch +: pitch backwards
Yaw +: CW angle from N pole

RCIN:
RC1 +: roll right
RC2 +: pitch backwards
RC3 +: throttle up
RC4 +: yaw right

Monday, 21 July 2014





我来说下,重心无论在上还是下对稳定性没有什么影响,lz要知道即使重心低也不能使四轴和直升机这两类飞行器的稳定能力增加,因为普通四轴在飞行的时候螺旋桨产生的拉力始终是垂直于四个螺旋桨平面的(四个桨在同一平面),飞行器并不会产生一种可以使其重的部位朝下而轻的部位朝上的力矩,这不同于我们提篮子时篮子收到的力,篮子收到的力是始终竖直向上的,所以重的部位才会下垂,而在空气中飞行则不会有始终向上的力,机身一旦偏转那么拉力也跟着偏转了。除非只有一种情况下低重心才能起到稳定效果,那就是像固定翼那样,机翼有上反角,四轴则是四个螺旋桨朝向中心安装,未完稍后继续






对于普通四轴而已,重心离开螺旋桨平面越远只能增加飞行器的惰性,(无论重心在上还是下都是一样的效果),为什么会这样呢?因为重心越远,机身做伏仰和侧倾动作的时候螺旋桨所需要克服的力矩会大大增大,所以使动作变得缓慢迟钝,不适合机动飞行,控制变得缓慢而笨重,此时如果还是使用原来的参数则会显得过底,所以需要把感度调高才行,再次强调:重心在上在下只要距离一样那效果也是一样的,除非螺旋桨内倾才能显出区别!!!













这是理论上的,实际上重力趋稳几乎对四轴没用(对飞控操作的飞行器来说,理论上重心远离运动轴心都是有害的)。
因为飞控的校正速度很快,其加速度是大于重力力臂产生的加速度的,所以飞控校正过程中,远离轴心的重心由于惯性的原因其实是起阻碍飞控校正作用的(重力加速度G是远小于飞控校正加速度的,因此基本上是飞控校正力带着重心围绕轴心在跑)。同时,校正过程中四轴到了水平点后,由于重心远离运动轴心,重心在惯性作用下继续推动四轴绕轴心运动,破坏水平,造成飞控不得不再次校正,反复摇摆。因此不管在上面还是在下面,重心远离四轴轴心都是有害的(轴心在哪,看我前贴,我是这么认为的,不一定对)。
On a quadcopter, there isn’t this point of inefficiency, but having to continuously slow down and speed up the props to remain in the air does waste a lot of energy (however regenerative braking would reduce this wastage, but not many models do this at the moment). What’s interesting is that the effect of this was very evident when we were tuning our quadcopter – our quadcopters were designed to lift about 1kg of payload, but they could be made to lift a brick (about 2.3-2.6kg) ONLY if the stabilization tunings were relaxed so that the craft was less stable in the air, but wasted less energy trying to stay absolutely level. Either way, aerodynamically, larger and slower spinning props are more efficient than small fast-spinning props.
This comes down to a lot of aerodynamics, but in effect it’s to do with the fact that the formula for kinetic energy is 1/2mv^2: it takes four times more energy to move a mass of air at twice the speed; compared to only twice the amount of energy to move twice the mass of air. In both cases, the same amount of momentum is conferred (m*v). So it turns out that it takes less energy to exchange momentum with a large amount of air at slow speed than it is to exchange momentum with a small amount of air at high speed. Therefore a large, slower-moving prop is more efficient than a small large-moving prop, especially at hover.

Sunday, 20 July 2014

How does an ESC work

Some brushless motors use hall effect sensors to sense the magnet position and provide feedback. However, most of the brushless motors used for RC are sensorless. When energizing the 3 coils, at any given time one wire is driven positive, one is driven negative and the third is undriven. The magnets on the spinning rotor induce a voltage in the undriven coil which the sensorless controller detects and uses to determine when to switch to the next step in the sequence. 

One problem with the sensorless motors is that voltage induced in a coil is proportional to the speed of the magnet moving past it. At very low speed there is not enough voltage to detect so at startup, the controller has to drive the motor without feedback until it is spinning fast enough to induce a detectable voltage.

4-POLE BRUSHLESS DC MOTOR ANIMATION

Todo

Test slip current of motor

Thursday, 17 July 2014

GPS Glitch

  1. The vehicle is loitering normally and then suddenly takes off in the wrong direction.  This is generally caused by a GPS Glitch.  There is no 100% reliable protection against these which means the pilot should always be ready to take-over manual control.  Beyond that ensuring a good GPS HDOP before take-off is always good and it may help to reduce the GPSGLITCH_RADIUS and/or GPSGLITCH_ACCEL parameters (see GPSGlitch wiki page for details) to tighten up on the glitch detection.


ERR-GPS 2 means a GPS glitch. ERR-GPS 0 means a recovery.


FS_GPS_ENABLE should be set to 1

Tuesday, 15 July 2014

Building Mission Planner with Visual Studio

Building Mission Planner with Visual Studio

Downloading the ArduPilot code and setting up SITL in Ubuntu.

Thanks to TheQuestor, there is now a really smooth way for installing and launching SITL.
These Guides contains all you need to get SITL up and running in it's basic form

This one covers installing/running SITL on an Ubuntu machine.
SITL_Installer_launcher_g...

Get this one for info on how to get Ubuntu installed, using VMware
SITL_Manual_Setup_v3.1

This one details how to connect SITL to MissionPlanner, as well as customizing start-up location.
MP_SITL_and_Location

This one deals with getting FlightGear installed and connected to SITL.
FlightGear_SITL

This file is the launcher/installer: (Hint: Download it from the Ubuntu-machine.)
sitl_installer_launcher

Updated July 8, 2014.
I've added guides on connecting MissionPlanner, customizing start-up location and installing and running FlightGear.
Next up is the guide for control with a Taranis.

The Taranis connection is roughly described here:
Install and run FlightGear with SITL. Connect a Taranis.

Loiter_turns Command Troubleshooting

The problem we faced at today's flight test was:
  • The LOITER_TURNS command recognised the centre of the circle, BUT it seemed to rotate around the point with no radius
  • However, the CIRCLE_RADIUS is correctly set, and it is working in CIRCLE mode
  • After it completed LOITER_TURNS, and heading to the next waypoint, the altitude drift to ~33m, far away from the designated 20m height.

The first two bullets indicate that the problem is something to do with the code. AND IT IS!

Here is the code of our concern:
---------------------------------------------------------------------------------------
case MAV_CMD_NAV_LOITER_TURNS:                      // MAV ID: 18
          copy_location = true;
          num_turns = packet.param1;                      // number of times to circle is held in param1
          radius_m = fabs(packet.param3);                 // radius in meters is held in high in param3
          cmd.p1 = (((uint16_t)radius_m)<<8) | (uint16_t)num_turns;   // store radius in high byte of p1, num turns in low byte of p1
          cmd.content.location.flags.loiter_ccw = (packet.param3 < 0);
          break;
---------------------------------------------------------------------------------------

This clearly shows that the third parameter of the LOITER_TURNS command is used to store the radius data. HENCE, we shall not simply put 1 or -1 to indicate direction of turn, but should type in something like +20 or -15.


There is a minor issue hiding in the code above. The cmd structure in the code only accept one general parameter. This means that the num_of_turn and radius_m must be squeezed in to the single uint16_t variable. This is evident below:

-------------------------------------------------------------------------------------
struct PACKED Mission_Command {
        uint16_t index;             // this commands position in the command list
        uint8_t id;                 // mavlink command id
        // CHM - the commande structure have only 1 parameter in short int. This cause the loiter_turn cmd to be squeezed (num of turn + turn_radius).
        uint16_t p1;                // general purpose parameter 1
        Content content;
    };
-------------------------------------------------------------------------------------

In conclusion, the 1 should be changed to larger number. TO BE VERIFIED BY TOMMOROW