Blog

Quadcopter Control System Docs

Unreal Engine Marketplace Quadcopter Control System

With this guide you should have all the information you need to modify the appearance and flight characteristics of your quadcopter. The important blueprints are contained within:

“QuadcopterControl/Blueprints” and “QuadcopterControl/Blueprints/QuadcopterModes”.

The quadcopter system is made up of a base class “BP_Quadcopter_Base” and four child classes which are the flight modes.

  • BP_Quadcopter_Acrobatic
  • BP_Quadcopter_Manual
  • BP_Quadcopter_Stabilized
  • BP_Quadcopter_Stabilized_Hover

BP_Quadcopter_Base

The Base class “BP_Quadcopter_Base” is the first place you need to go to customize your quadcopter. It contains the settings and code that control the appearance, thrust output, controller sensitivity and camera control that affect all flight modes.

-Appearance

The quadcopter mesh is a skeletal mesh. The bone structure is extremely simple and requires only the most basic rigging knowledge to set up.  In order for the blueprint system to work all it needs is a root and one child bone for each propeller. The included model also has 2 additional bones, one for each of the landing struts (these are optional). The landing struts are set up in the physics asset tool so they respond to landing more realistically.

If you chose to replace the skeletal mesh you must also update the animation blueprint. If your skeletal mesh differs from the included model you will need to create an animation blueprint for it. Simply copy the blueprint code from the “ABP_Quadcopter” animation blueprint in the Event Graph and the Anim Graph to your new animation blueprint. In the Event graph, ensure that each of the Transform Bone nodes has the correct “Bone to Modify” setting set for each propeller under the Skeletal Control tab in the details panel.

To replace the model, go to the BP_Quadcopter_Base class and select the Quadcopter Skeletal mesh component in the components menu. Replace the Skeletal mesh in the details panel under the Mesh tab. Then select the correct Anim Class under the Animation tab.

Finally, you must create a new material for your quadcopter. If it differs significantly from the included model, you may want to change or remove the code which selects the color of the quadcopter located in BP_Quadcopter_Base in the Construction Script. 

-Thruster Output

If you have created a custom mesh for your quadcopter you will need to create a physics asset for it. In the physics asset you can set the mass of your quadcopter and the desired linear and angular damping. These settings will significantly affect the flight characteristics of your quadcopter, higher linear damping values are good for simulating drag created by air resistance. Higher angular damping values will make flight more stable and less responsive.

In the BP_Quadcopter_Base blueprint you will have to set three main thruster values based on the settings you set in the physics asset. These settings are located in the variables section under “Thrusters”. They are called “MinThrust”, “MaxThrust” and “YawTorque”

Higher mass will require a higher MinThrust and MaxThrust as well as a higher YawTorque. Lower mass will require lower values. To test these settings, place an instance of the BP_Quadcopter_Manual Blueprint in a scene. The manual setting is essentially a direct connection between your controller and the quadcopter without any stabilization so it is great for testing your new quadcopter parameters.

-Max Thrust:

With your quadcopter placed in the scene, slowly increase the throttle until your it starts to take off. If the quadcopter takes off too quickly, you must decrease the MaxThrust value. If the quadcopter fails to take off or takes off too slowly the MaxThrust value must be increased.

– MinThrust:

is the minimum thruster output created by the quadcopter, this setting should be low enough that your quadcopter does not take off on its own when your throttle is completely lowered, but high enough that it slows the descent speed of your quadcopter when you let go of the throttle during flight. The purpose of this setting is to slow down the over-all descent speed of your quadcopter. The desired level of MinThrust is mostly subjective and should be experimented with in order to reach your desired preference.

-YawTorque

This value determines how quickly your quadcopter can turn left or right. Higher mass requires higher torque. Experiment with this setting using the manual quadcopter mode until you find your preferred torque value.

-Control Sensitivity

With the physics settings configured, you can now modify the sensitivity levels for the yaw, pitch and roll controls. These settings are named “YawSensitivity”, “RollSensitivity” and “PitchSensitivity”. Use the Manual quadcopter control mode to tweak these settings to your liking.

-Camera Modes

By default the quadcopter control system comes with two default camera modes. Third person and First person modes. To add a camera mode, open the CameraModes Enumeration file located in “QuadcopterControl/Blueprints” and add a new item to the Enumerators list. Then in BP_Quadcopter_Base. Go to the CameraMode function. In the “Set camera to appropriate camera socket comment section you will see the camera mode switch. This is where you must add your new camera code.

 

Customizing the flight modes

-BP_Quadcopter_Manual:

This flight mode has no stabilization, it simply feeds the controller input to the thrusters directly. Most of the settings that affect this mode are located in BP_Quadcopter_Base. The yaw torque can be set in the overridden Yaw function.

-BP_Quadcopter_Acrobatic:

The acrobatic flight mode behaves like a racing quadcopter. In between the controller input and the thruster output is stabilization code which seeks to keep the quadcopter oriented in the angle set by the pilot. Unlike the manual flight mode in which the quadcopter will keep its momentum If you let go of the controls, the acrobatic quadcopter will seek to remain in the same angle it was in when the controls were let go. This allows the pilot to precisely rotate the quadcopter freely in 360 degrees in all axis of motion and perform acrobatic maneuvers while in flight.

The main settings which need to be configured when using a custom quadcopter model are “YawGainValues” and “PitchRollGainValues”. These are the PID gain values used by the quadcopter stabilization code to keep the quadcopter oriented X, Y and Z correspond to P, I and D respectively. The YawGainValues are used to define the behavior of the Yaw stabilization algorithm. The PitchRollGainValues are used to define the behavior of the pitch and roll stabilization algorithms. These values need to be experimented with in order to achieve the desired results. The theory behind the function of the PID controller algorithm will not be covered in this document. For more information on how PID Controllers work, I would refer you to my previous blog post  (https://protospace.wordpress.com/2017/03/27/pid-controller/) There you will find basic explanations of how PID Controllers work as well as a link to my PID Controller example pack on the Unreal Engine Marketplace, as well as the wikipedia article on PID Controllers which is an excellent place to start.

-BP_Quadcopter_Stabilized:

This mode also uses PID Controllers for the Yaw, Pitch and Roll. The difference between this mode and the Acrobatic mode, is that in this mode the quadcopter seeks to remain level in respect to the world, where as the acrobatic mode seeks to maintain its orientation from user input. When you let go of the controls in stabilized mode the quadcopter will automatically return to a level flying position. The Yaw, Pitch and Roll gain values function in the same fundamental manner in the acrobatic mode and manual mode.  In fact, the Yaw values are exactly the same. Only the pitch/roll values have changed due to the difference in flight modes.

BP_Quadcopter_Stabilized_Hover:

This mode is identical to the previous stabilized hover mode, but with the addition of throttle stabilization. Now in addition to remaining level with the world, the quadcopter also attempts to remain at the same altitude that the pilot last left it in. The throttle PID gain settings are called “ThrottleGainValues” and can be found with the other PID gain values.

Advertisements

Quadcopter Control System

Unreal Engine Marketplace Quadcopter Control System

This blueprint system features a comprehensive physics based quadcopter control system. It includes 4 flight modes typical to real world quadcopter flight systems. Learn to fly a quadcopter!

This control system simulates quadcopter physics using PID Controllers connected to physics thrusters which permit access to the PID gain values allowing you to tune the quadcopter flight modes based on your personal preferences. This system mimics quadcopter controls. The 4 flight modes are:

Manual Mode: This flight mode uses no stabilization algorithms. It gives you direct control over the quadcopter. This is an expert flight mode.

Acrobatic Mode: This flight mode features complete stabilization of quadcopter attitude (Yaw, Pitch and Roll) But allows for 360 degrees of motion in each axis. This is an advanced flight mode.

Stabilized Mode: This flight mode keeps the quadcopter stable horizontally but leaves the throttle control free. This is an intermediate flight mode.

Stabilized Hover Mode: This flight mode keeps the quadcopter stable horizontally and controls the throttle to maintain the altitude of the quadcopter for a “hover” mode. This is a novice flight mode. Also, great for cinematography.

This system relies on gamepad control input.

 

 

 

 

DSLR Camera Gimbal

This DSLR camera gimbal is perfect for stabilizing video on drones or vehicles. The blueprint can easily be used by adding it to any pawn or actor you want.

In addition to stabilization, the camera gimbal can also be manually controlled allowing you to point the camera in any direction you want even while it is stabilized.

This three axis DSLR camera gimbal has two control modes.

Orientation locked: will always keep the camera horizontally stable while facing in the forward direction. It can also be manually controlled on all three axis of rotation, manual inputs are treated as an offset to the stabilization. Allowing you to control the camera and point it in the desired direction while maintaining its relative stabilization.

FPV: The camera will return to the forward facing orientation and will not perform any stabilization.

Action Camera Gimbal

This action camera gimbal is perfect for stabilizing video on drones, vehicles or sports helmets. The blueprint can easily be used by adding it to any pawn or actor you want.

In addition to stabilization, the camera gimbal can also be manually controlled allowing you to point the camera in any direction you want even while it is stabilized.

This three axis camera gimbal has two control modes.

Orientation locked: will always keep the camera horizontally stable while facing in the forward direction. It can also be manually controlled on all three axis of rotation, manual inputs are treated as an offset to the stabilization. Allowing you to control the camera and point it in the desired direction while maintaining its relative stabilization.

FPV: The camera will return to the forward facing orientation and will not perform any stabilization.

 

 

 

 

 

PID Controller

Unrea Engine Marketplace PID Controller

What is a PID Controller?

“A proportional–integral–derivative controller (PID controller) is a control loop feedback mechanism (controller) commonly used in industrial control systems. A PID Controller continuously calculates an error value as the difference between a desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms” – (Wikipedia) PID Controller

Simply put, PID Controllers are used to reliably automate certain kinds of processes. For example, an aircraft may use PID Controllers in their stability assist systems to maintain orientation in flight. They do this by calculating an error value between a desired setpoint (the pilots commands) and a measured process (the attitude readings form the aircraft sensor data). The PID Controller then outputs the results of it’s calculations to the various control surfaces of the aircraft to reach the desired setpoint.

PID Controllers are also commonly used for stabilizing quadcopters. The PID Controller takes in the angular velocity of the quadcopter from the gyroscope, and stabilizes the flight using the speed of the propellers to control the angle of the quadcopter. The same effects can be achieved in a Blueprint by retreiving a PhysicsBody’s angular velocity and outputting the results of a PID Controller to PhysicsThrusters. PID Controllers are also useful in countless other possible applications!

How to use the PID Controller Actor Component

This PID Controller Blueprint is meant to be used as an Actor Component. You can add it to any actor or pawn that requires some form of simple process automation. Multiple automated processes can be managed in a Blueprint Actor. You must add one PID Controller Component for each process you want to automate.

The main function in the PID Controller Component is the PID function, it must be provided with the following variables:

  • P Gain : The Proportional Gain Term tells the PID Controller to output a value that is proportional to the error value.
  •  I Gain : The Integral Gain Term affects the output based on the magnitude and the duration of the error (the longer an error persists the bigger the output)
  •  D Gain : The Derivative Gain Term “predicts” the error over time by continually calculating the slope of the error. It behaves like a damping value.
  • Set Point is the desired state of your system. This could be mapped to a controller axis or any other variable that changes over time.
  • Measured Point is the current state of your system. This could be the angular velocity of a Physics Body, or the position or rotation of an Actor
  • Min and Max values clamp the output to a desired range.

Examples:

The PID Controller Actor Component addon for Unreal Engine 4 comes with 6 example pawns that all use PID controllers in a number of different ways.

  • The first example: The Balance Cone example demonstrates basic use of PID Controllers using player input as the set point, the rotation of an object as the Measured Point and Add Torque as the output. Two PID Controllers are needed, one for pitch and the other for roll. The result is similar to built in UE4 Physics Constraint, Angular Motor.
  • The second exmaple: The Flying Cube Example uses three PID Controllers, one for each axis of movement. Player input is used as the Set Point, Linear Velocity is used for the Measured Point and PhysicsThrusters are sent to the output.
  • The third example: The Rocket example demonstrates how two PID Controllers are used to keep a rocket ship upright using thrust vectoring, while a third PID Controller maintains the vertical velocity. The first two PID Controllers use the x and y rotation of the rocket ship body as the Measured Point, user input as the Set Point. The output of the PID Controller is sent to a Physics Constraint angular motor between the rocket ship body and the thruster nozzle to affect the target angle of the nozzle. The third PID Controller uses the linear velocity of the rocket ship body as a measured point, user input as the set point and the output is sent to a Physics Thruster.
  • Examples 4, 5 and 6: demonstrate how PID Controllers can be linked, allowing multiple simple automated processes to produce complex automated behaviors. This 3-part example shows, in increasing complexity, how to create a stabilized thruster platform that can easily be programmed to automatically navigate along pre-determined paths. All using physics and thrusters!