Header Overview

Now, we will control our AscTec UAV through an ACI command. At the beginning, let us start with turning single rotors on and off on demand.

Code

Let us have a look at the code. It is similar to the code in the first two tutorials.

Let us take a deeper look into this code. We define new variables at the beginning.

We want to send them to control the UAV. After connecting to the device, initializing ACI, setting up the callback and starting the thread, we request the list of commands on the device.

After getting the list, the cmdListUpdateFinished(voidfunction will be called.

A message will be displayed on the screen. After that, all our commands are received in two different packages. The first one includes all the different motor values. If you have an AscTec Firefly, you can also added the other two motors for controlling. The second package defines some configuration. You have to send it only one time, so it is not necessary, to send it every time when you change the motor status. After adding all commands to their packages, we send the configuration to the device:

For the first package, we don't need to know, if the package was received successfully. We will see if the motors go on and off and otherwise, we send it manually again. It is the same, if you are sending commands permanently. If one command is dropped down, it is not useful to send it again, because in the mean time a new command was set and sent. For the motor control configuration, it shall be received, because you need to make sure that the correct control mode is set. That's the reason, why we send it with getting an acknowledge. If it doesn't come, ACI sends the command again automatically.

We set the first values and send them to the device:

The command configuration is set. With cmd_ready=1;, we set the variable to continue in the main() function.

A message appears waiting for an input. If you now type in a number, it will start or stop the motor with the chosen number. To see that, you have to turn on the UAV by the remote control and switch the serial interface switch to allow your device to use the commands you have sent to it. Otherwise you will not see any effect. The startStopMotor(motor_start); function will start (by a low rotation speed of course, so don't worry, that your system will fly away) or stop a rotor between 1 and 4.

You can quit the program by using 0 as input.

Warning: If the rotors are all off and you switch back the serial interface switch, the motors are switched on again and will execute the command you send through your remote control! So, make sure, that all sticks stay in the middle and that the thrust stick is completely down.

In the next chapter, the usage of parameters will be introduced.