Demonstrating Fly-By-Wire



Demonstrating Fly-By-WireUsing theArduino MicrocontrollerV2014.bA Module for PS114Dr. Padraig HoulahanDepartment of Physics, Embry Riddle Aeronautical University, Prescott, AZ.IntroductionA microcontroller is a computerized device that can accept input from a sensor, process the input, and use the result to control an external device. So the computer dictates how the controlled device responds to the environmental parameters being measured by the sensor.In aviation, large aircraft often no longer use cables, pneumatics, or hydraulics to link the yoke or rudder positions to the desired control surface angles. Instead, sensors at the yoke and rudders provide input data a computer can process, and the computer then sends appropriate signals to the remote motors that manage the control surfaces. Because of the computer being in the loop, sensitivity to pilot control could be adjusted based on phase of flight, and autopilot technology can be easily integrated. We call this approach “fly by wire” and it refers to the computer being a man-in-the-middle between input and output devices.Microcontrollers are devices designed to play this kind of man-in-the-middle role and can easily interface with both sensors and output devices – especially motors and relays. In this module we will concentrate on the Arduino Microcontroller because they are well documented, widely available, and have a large following among hobbiests and robotics enthusiasts. Our objective is to build a demonstration fly-by-wire system where physical movement is processed by an Arduino to produce motion in a connected servo-motor (a type of motor where the shaft angle is set to desired angles) thereby showing how yoke motion could control an aileron (for example) via a computer. Specifically we have 3 tasks to solve:How to detect motion and derive a signal the Arduino can useProgram the Arduino to process the input signalHave the Arduino create an appropriate response in the servo-motor that represents setting the aileron position.In this document we show how each of these aspects is addressed allowing us to assemble a demonstration system.ArduinoArduino microcontrollers come in different types, and the above picture is about the actual size of the Arduino UNO. Note that it includes a row of ports along the top to interact with digital devices, and 6 analog ports on the bottom right.It contains a computer chip, and a USB port at the top left.Along the bottom, there are sources of voltage and ground reference levels.Arduino is Open Source which means you can by a version for about $30, but it is also legal to buy the components and assemble them yourself for about $10.Working with sensors – Detecting Motion for Arduino InputA sensor is a device that can measure a property of its environment. Mercury thermometers and barometers indicate environmental conditions through a mercury column. As such they cannot be used with Arduino directly since they do not provide an electrical signal. Generally speaking, any sensor or device that produces an electrical signal can be used to provide input to a microcontroller. In fact the signal output from a GPS detector, a motion detector, a multi-axis accelerometer, could all be sent to a microcontroller, for display and/or recording, and/or to be used to control a UAV or an RC aircraft or a robot. In fact, a personal black box could be built around an Arduino and the above components.One of the most basic sensors is a variable resistor (called a rheostat, or potentiometer, or ‘pot.’) Most knobs in communication equipment that control volume are rotary pots where the knobs angular position controls the desired resistance and corresponding voltage levels used to control the speaker.When voltage V0 is applied across a potentiometer’s outside terminals, it acts like a voltage divider that can deliver any voltage between 0v up to V0 on the central terminal. For example, if the rheostat’s shaft is used to measure rotational position such as when an aircraft yoke is turned to create a bank angle, the pot creates a voltage indicative of the amount of angle the yoke has been moved and a microcontroller can use this to control an aileron motor. Note that Arduino can provide the V0 needed by the pot to operate as a voltage divider (and many other sensors) which can considerably simplify a project.The Arduino analog pins have an ADC (Analog to Digital Converter) that converts voltages in the expected 0 – 5V range into a number between 0 and 1023. So a sensor that provided a 3V signal to analog pin 4 would have this data read in as:val = analogRead(4);and val would be assigned the value 3/5 x1024 = 615.Programming the ArduinoA program is a list of instructions that controls a computer. An Arduino program is called a ‘sketch’ and is the user friendly text created by the developer that needs to be translated into instructions the Arduino can interpret. The Integrated Development Environment (Arduino IDE) is a free program that can be used to create sketches, to compile them (i.e., turn them into computer ready form,) and to upload them into the Arduino. Here is what the IDE looks like with a simple sketch present:This particular sketch flashes the onboard LED once per second.The IDE communicates with the Arduino board via a USB cable. Often, the cable can be disconnected once the program is uploaded.Sketches usually contain the following elements:A list of additional libraries if needed. (A library is a programming segment provided by a manufacturer that provides the commands needed to control their devices.)A list of convenient definitions that make the code more meaningful and easier to read. For example, if an audio signal was being read on analog pin 4, then defining audioIn=4 would allow us to use the word ‘audioIn’ instead of the number 4 from that point on.The setup() function where we initialize the programThe loop() function were we start the process of listening and responding to sensors and controlling devices if necessary, and keep repeating this until the program is stopped.Discretionary, multi-line comments, to help the reader understand the code, are enclosed between lines starting with ‘/*’ until a line consisting of ‘*/’ while shorter comments on a single line (or part of one) follow ‘//’ through the end of the same line.In the above IDE image, the sketch is very basic and so no definitions are made or additional libraries invoked.For our purposes, the essential point is to note how the sketch controls something attached to pin 13 - an LED – by using the built-in command ‘digitalWrite’ which takes two arguments –the pin to be controlled, and whether to set its voltage HIGH or LOW (turning the LED ON and OFF respectively). This shows us one way the Arduino can send control signals to an attached device – an LED in this case – but for our fly-by-wire we need something more refined than a simple ON/OFF output; we need to be able to set a servo-motor to different angles. Also, we need to be able to modify parameters in real time rather than ‘hard wiring’ them as we did here by using 1000 as a fixed value for the delay() command..Using a keyboard to control a deviceBecause the Arduino UNO is a computer, it can be used to control a device from the keyboard – it doesn’t have to use sensors for input. In the following sketch, pressing the number 1 or 2 will toggle the onboard LED associated with digital pin 13, on and off:A sketch using serial communications to send data back and forth between the Arduino and the keyboard’s computer.The serial monitor is a window that allows text to be sent and received between the user’s computer and the Arduino.In this sketch we tell the Arduino we wish to use Serial communications at a speed of 9600 baud (i.e. characters per second.) In the loop section, we check if anything has been received since we last checked using Serial.available(), and if this is true, we ask for the value (using Serial.read()) and then decide what to do based on testing the value. If the value is 1, we turn on the LED; if 2, we turn it off; anything else we simply note it as an unknown. The loop keeps repeating until we power off the Arduino.We use Serial.println() to report back to the computer so we can see have a separate confirmation of the event – a very useful technique when debugging.The Serial Monitor is a small window we bring up using the IDE Tools menu. It uses the text box to send characters to the microcontroller, and prints what the controller sends back in the larger text window below. The microcontroller detects characters typed into the text box, tells the Serial.available to report (if asked) there are characters waiting to be processed, and places the character in a wait queue. Serial.read takes the next character out of the queue for processing.This example shows how a keyboard can be an input device to the Arduino. Turning an LED on or off is easy, but it’s the same principle for controlling a relay; to activate an alarm system; to raise or lower landing gear; to trigger a change in flight mode settings etc. We are just using serial communications protocols which the developers make available through the various Serial.xyz() commands. This example demonstrates how a pilot provide input into to a flight control system using a keyboard.Note also how when we wanted a capability – in this case the ability to communicate with the microcontroller - the developers made a group of commands available to us of the form Serial.subcommand. It is often the case, other users and developers of Arduino have solved most of the problems you are interested in and you can find their solutions online, and modify them for your purposes.A Temperature Controlled LEDInexpensive temperature sensors can be used to provide sensory input to the Arduino. A common type are called TMP35 or TMP36 and so on. They can differ based on precision and reliability. The one in the Arduino kit looks like a black match-head with 3 attached wires; the outer allow 5V to be applied, while the center one delivers a voltage that depends on ambient temperature. The specifications state there are 10mV per deg. C, so the signal voltage needs to be divided by 100 to get the number of 10mV steps present.Since the analog pin ADC converts voltage to a number between 0 and 1023, the voltage can be calculated by the VALUE returned by analogRead() function, i.e.VALUE = analogRead(4);Voltage_In = VALUE X 5/1024.Hence, the temperature is Voltage_In/100.[Remember, the analog pin only knows it is receiving a voltage and is translating it to a number between 0 and 1023. It is up to the programmer to know how to interpret the number produced by the analogRead() function.]In the following sketch we use a TMP35 to provide input to the Arduino through analog pin 5. The input is read using analogRead(5) which returns a number (val) between 0 and 1023. We convert val to a voltage and then divide by 100 to see the mV present. To allow the sensor to work below freezing, a .5V offset is applied and is included in the calculations.We are using Serial communications to see what is going on for informational purposes, and use Serial.println to report back the value returned by the analogRead() function (val), and the calculated temperature (temp.)Based on an arbitrary temperature threshold of 22.5, we turn on the LED on digital pin 13, if the threshold is exceeded; off, otherwise.Here the TMP36 is mounted on the breadboard and powered by the 5V and ground levels from the Arduino UNO (short leads.) The long lead is the signal line from the TMP36’s middle (signal) terminal to analog pin 5 (A5.)The sketch and Serial Monitor. The Serial Monitor show the digitized value in the range 0 – 1023, and the calculated temperature – as determined every time through the loop (set by the delay(1000) command to once per second.)Controlling a servo motorA servo-motor is a motor that can be commanded to turn to a desired angle. Inexpensive ones ‘know’ their shaft position through a built-in potentiometer.A servo needs a power source, and one can use the 5V available from the Arduino, but if it is expected to handle a heavy load, a separate power supply might be needed.Servo’s have 3 wire connections, typically for 5V, Ground, and Signal. The signal cable is connected to an Arduino digital pin which controls the servo angle by sending pulses of appropriate durations:Servos operate by sending a timed +5V pulse (usually between 500us and 2500us) to the onboard electronics, which is repeated every ~20ms. This pulse corresponds to a servo position, usually from 0 to 180 degrees.5V for 500 microseconds = 0.5 milliseconds and corresponds to 0 degrees5V for 1500 microseconds = 1.5 milliseconds and corresponds to 90 degrees5V for 2500 microseconds = 2.5 milliseconds and corresponds to 180 degreesThe relationship is linear, so use mathematics to determine the pulse which corresponds to a given angle.To create a pulse to set a servo to 90 degrees we would use the following steps in a loop that repeats indefinitely:Set the signal line HIGH (i.e. to 5V)Wait 1500 microsecondsSet the pin LOW (i.e. to GROUND)Wait about 20 msHere is a screenshot of an IDE sketch that uses digital pin 4 and sets a pulse length of 1500 to achieve this:Note that we need to use a different delay command than that which we encountered in the blinking LED example; delayMicroseconds() uses units of microseconds, while the regular delay() command uses milliseconds.Also note the servo motor angle is set through software by defining pulse=1500. In the final section that follows we will use a potentiometer to control the pulse length and hence the servo motor angle for a real fly-by-wire system.A basic fly-by-wire systemFrom what we have learned so far, we have enough information to build a fly-by-wire system if we use a potentiometer to provide a varying input to control the pulse length sent on the servo motor signal line.The above picture shows the quick-and-dirty fly-by-wire system. The servo is on the top right while the pot is near the top left. The pot and the server take power from the Arduino 3v and 5v ports respectively. The yellow lines are for the servo controlling signals on the right, and the potentiometer input on the left. Rotating the pot back and forth causes the armature to move back and forth accordingly.A close up showing the 2 available power ports 3.3V and 5V being used. The servo used the 5V line. Note the yellow input line from the potentiometer on analog 4.If the pot is connected to analog pin 4, (potPin=4) we can read its value with the IDE command:val=analogRead(potPin);This returns a value in the range 0 – 1024. Since the servo signal line needs values between 0 and 2500, we can calculate the pulse with the command:pulse = map(val, 0,1024, 0 ,2500);where thoughtful programmers created the map function to relate a value in the range 0-1024 to the 0-2500 range needed by the servo motor.The final sketch loop functions as follows:Everytime through the loop,-Read the potentiometer pin using analogRead(potPin) and store the result as ‘val’-Convert ‘val’ to the pulse length (a number in the range 0 – 2500 using the map command)-Create the pulse on the servopin line-Pause for 20msAs the potentiometer is changed, the servo motor armature follows the change – as expected in a fly-by-wire system.Finally, while this is a very primitive fly-by-wire system, it is functional and was achieved with remarkably few lines of code. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download