diff --git a/implementation/collision-avoidance.tex b/implementation/collision-avoidance.tex index a35a2aa2ad1dffc9215217defeba0a0308b17c09..3521fe1df79e13a8e123bf4cb7a467de931d52df 100644 --- a/implementation/collision-avoidance.tex +++ b/implementation/collision-avoidance.tex @@ -1,21 +1,29 @@ \subsection{Collision avoidance} \subsectionauthor{Author: Lars Jonsson \\Reviewer: Max Unander} -To be able to fly the copter up and down these shafts without colliding, we have put six ultrasonic sensors on the copter in each direction, see figure \ref{label}. -In this case there will be three pair of sensors, where each pair represent one axis in the Cartesian coordinate system. +To be able to fly the copter up and down these shafts without colliding, we have put six ultrasonic sensors on the copter in each direction. +For this project there will be three pair of sensors, where each pair represent one axis in the Cartesian coordinate system. +In Figure~\ref{fig:twosonarcopter} you can see one of these pairs mounted on the x-axis. + +\begin{figure}[H] + \centering + \includegraphics[width=0.6\textwidth]{Pictures/copter_above} + \caption{Copter at early stage with only one sonar-pair mounted.} + \label{fig:twosonarcopter} +\end{figure} + With help of the measurement from each sensor, a controller for collision avoidance will be implemented. The collision avoidance will consist of three individual PID-controllers, where each one will control the position on each axis. - To get this to work we will have to map the copters movement in the Cartesian coordinate system to roll, pitch and throttle commands that will be sent to the flight controller. This will work in the way that the output from the PIDs in each direction will be represented by either a pitch, roll or throttle command to the flight controller. \subsubsection{PID - controller} -The PID controller will have the difference value between the measurement of the two ultrasonic sensors as control variable, and it's task is to converge this difference into 0. +The PID controller will have the difference value between the measurement of the two ultrasonic sensors as control variable, and it's task is to converge this difference into 0. When the difference value goes to 0 it means that the copter is right in the middle between two objects. The output of the PID will be a number between 1000 and 2000, because that is the input the flight controller can receive. -The input to the flight controller is a linear function where for the roll and pitch command where 1000 represents by a setpoint of $-10^\circ$ and 2000 will induce a setpoint of $+10^\circ$. +The input to the flight controller is a linear function where for the roll and pitch command 1000 represents by a setpoint of $-10^\circ$ and 2000 will induce a setpoint of $+10^\circ$. This function is linear so 1500 represent no inclination. -For the throttle command 1000 will be no throttle at all and 2000 will set full throttle to the motors. +For the throttle command 1000 will be no throttle at all and 2000 will set full throttle to the motors. The yaw command do differ a bit, it will not set a specific set-point, it will instead set an angular velocity to the copter. This so that the copter can spin freely around it's own axis. With this setup we wont have any controller to keep the heading of the copter, which should be implemented in the future. @@ -30,24 +38,37 @@ When we had the hovering function working quite good, we started out with trying To do this we used the SonarDifference algorithm mentioned above. We started out with just the P variable and saw that it "bounced" a lot between the walls. We concluded that we needed the D parameter as well to reduce the bouncing. -When we saw that this worked we started to fine tune the variables. -This was done by logging data while flying, and afterwards we could check the graphs and from those do some conclusions on how we should change the variables. -The graphs from the final tuning of the \texttt{PID\_Roll} is shown in Fiugre~\ref{fig:PIDtuning1}. +When we saw that this worked, we started to fine tune the variables. +This was done by logging data while flying, plotting of the data, and from those do some conclusions on how we should change the variables. +Before tuning the plots did look like the on in Figure~\ref{fig:PIDtuning1}. +In this graph we see that the Roll command is clipped a lot. +This is because the controller is to aggressive and the roll command reaches its maximum/minimum values at 1750 and 1250. +These maximum values are changeable, and we saw that $1500\pm{250}$ worked quite well. \begin{figure}[H] \centering - \includegraphics[width=0.7\textwidth]{Pictures/PIDtuning1} - \caption{This shows how the intended communication between the radio-transmitter, MCU and flight controller was going to be implemented.} + \includegraphics[width=0.6\textwidth]{Pictures/PIDtuning1} + \caption{SonarDiff X, shows the difference between the measurement of two sonars placed on the same axis. ROLL command show the value that is sent to the flight controller. SWH is the switch that starts the PID, how these are mapped on the RC transmitter can be seen in Table~\ref{tab:controller_channels}.} \label{fig:PIDtuning1} \end{figure} \begin{figure}[H] \centering - \includegraphics[width=0.7\textwidth]{Pictures/PIDtuning3} - \caption{This shows how the intended communication between the radio-transmitter, MCU and flight controller was going to be implemented.} + \includegraphics[width=0.6\textwidth]{Pictures/PIDtuning3} + \caption{Plot of the final testing of the gain variables in the \texttt{PID\_ROLL} function.} \label{fig:PIDtuning3} \end{figure} +We tested to lower the P gain and increase the D gain and this resulted in the plots shown in Figure~\ref{fig:PIDtuning3}. +Here we see that the roll command never saturates, and that the Sonar Difference do less oscillations. +Of course these controllers needs to be further improved for an finished product, but this is good enough to show that this is possible. +We used the same variables for the \texttt{PID\_PITCH} function, as the pitch controller is implemented in the same way as the roll controller. + +When trying out these PID's we flew the copter with the RC controller up to a certain height, started the hovering function. +Tried to keep the copter in the middle of the corridor before starting the PID roll or pitch controller. +At this point we could let go of the RC controller and the copter stayed between the walls with some oscillations. +To land we turned off the PID(roll/pitch) started the landing function, lowered the throttle and the copter should land smoothly. +How these functions are mapped on the RC controller is show in Table~\ref{tab:controller_channels}. \begin{table}[h] \centering diff --git a/implementation/flightcontroller_imp.tex b/implementation/flightcontroller_imp.tex index b07f85b20e0cd07c79670ed1aa722d63f21ca5b9..189171229ba60b4294bf048b51d39b19c150be08 100644 --- a/implementation/flightcontroller_imp.tex +++ b/implementation/flightcontroller_imp.tex @@ -76,7 +76,7 @@ There are some things that was needed to be setup in Cleanflight to be able to f \end{itemize} All our configurations that was set in Cleanflight can be shown in the Appendix \ref{label}. -TODO: Ta config från cleanflight lägga in i en appendix. +TODO: Add the configs from Cleanflight into an Appendix, will be done after Christmas.