Difference between revisions of "HANcoder/Training Material/ThrottleValveController/OpenLoopBuild"

From OpenMBD
Jump to: navigation, search
(Created page with "{{HANcoder}} == Open Loop control == An open loop control system is a control system that doesn’t use any feedback. It is the simplest type of control system, with the down...")
 
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{HANcoder}}
 
{{HANcoder}}
 +
 +
[[HANcoder/Examples/ThrottleValveController/HardwareSetup| '''<Go back to part 1''']]
 +
 +
[[HANcoder/Examples/ThrottleValveController/OpenLoopTest| '''>Go to part 3''']]
  
 
== Open Loop control ==
 
== Open Loop control ==
 
An open loop control system is a control system that doesn’t use any feedback. It is the simplest type of control system, with the downside of it being fairly crude. It can’t be used for every system though. Nonlinear systems or unpredictable systems in particular are hard to control with this control scheme.  
 
An open loop control system is a control system that doesn’t use any feedback. It is the simplest type of control system, with the downside of it being fairly crude. It can’t be used for every system though. Nonlinear systems or unpredictable systems in particular are hard to control with this control scheme.  
 
The first part of this practical assignment will be to make an open loop control system to control an automotive throttle body. You will have to send out a PWM signal to the throttle body that is relative to the throttle position (potentiometer).  
 
The first part of this practical assignment will be to make an open loop control system to control an automotive throttle body. You will have to send out a PWM signal to the throttle body that is relative to the throttle position (potentiometer).  
Open Matlab Simulink and run the HANcoder_Olimexino.slx template model that you can find in you HANcoder Target directory. Double click the picture of the Olimexino board to enter the model. Then delete the “Inputs”, “Algorithm”, and “Outputs” blocks, so you’ll have a nice and clean model to start off with. Your model should look now a little something like this:
+
Open MATLAB Simulink&REG; and run the HANcoder_Olimexino.slx template model that you can find in you HANcoder Target directory. Double click the picture of the Olimexino board to enter the model. Then delete the “Inputs”, “Algorithm”, and “Outputs” blocks, so you’ll have a nice and clean model to start off with. Your model should look now a little something like this:
  
 
[[File: ThrottleValveControllerTemplModel.png]]
 
[[File: ThrottleValveControllerTemplModel.png]]
  
 
First, you’ll need to add an input to the model, which in this case will be the potentiometer representing the throttle. From the Library Browser, you’ll need to drag an analog input block into the Simulink model and, under properties, select the input connector that the potentiometer is connected to, A0 in this case.  
 
First, you’ll need to add an input to the model, which in this case will be the potentiometer representing the throttle. From the Library Browser, you’ll need to drag an analog input block into the Simulink model and, under properties, select the input connector that the potentiometer is connected to, A0 in this case.  
Open Simulink, click “Library Browser” and navigate to HANcoder STM32 Target Olimexino STM32 Analog Inputs. In the right column, the Analog Input block will appear. Select the block and drag it into the template model.
+
Open Simulink, click “Library Browser” and navigate to HANcoder STM32 Target -> Olimexino STM32 -> Analog Inputs. In the right column, the Analog Input block will appear. Select the block and drag it into the template model.
  
 
[[File: ThrottleValveControllerAnaIn.png]]
 
[[File: ThrottleValveControllerAnaIn.png]]
Line 30: Line 34:
  
 
Drag both blocks into your model.  
 
Drag both blocks into your model.  
Double click the PWM init block and select a switching frequency of 1 kHz, which Matlab will change to 1004Hz. Also select the PWM module with the correct digital output pins and send out a PWM signal on these pins, in this case the PWM module that contains D0 and D3. Because the PWM module “TIM2: D2 & D3 & n/a & D0” is being used, Channel 1 will be D2, Channel 2 D3, Channel 3 not available, and Channel 4 D0.  Because the opening action of the throttle valve is connected to pin D0, a PWM signal needs to be created on D0. Click the Channel 4 tab and check the checkbox that says “Generate PWM signal on channel 4”.
+
Double click the PWM init block and select a switching frequency of 1 kHz, which MATLAB&REG; will change to 1004Hz. Also select the PWM module with the correct digital output pins and send out a PWM signal on these pins, in this case the PWM module that contains D0 and D3. Because the PWM module “TIM2: D2 & D3 & n/a & D0” is being used, Channel 1 will be D2, Channel 2 D3, Channel 3 not available, and Channel 4 D0.  Because the opening action of the throttle valve is connected to pin D0, a PWM signal needs to be created on D0. Click the Channel 4 tab and check the checkbox that says “Generate PWM signal on channel 4”.
  
 
[[File: ThrottleValveControllerPWMmoduleSelect.png]]
 
[[File: ThrottleValveControllerPWMmoduleSelect.png]]
Line 51: Line 55:
 
[[File: ThrottleValveControllerBuildButton.png]]
 
[[File: ThrottleValveControllerBuildButton.png]]
  
After agreeing to a licensing notification, Matlab will call up the GNU ARM Toolchain to convert your model to machine code. After the S file is ready, Matlab will start the Microboot program to flash the code to the Olimexino. A similar window to that of Figure 10 should pop up. Reset your Olimexino to flash the program.  
+
After agreeing to a licensing notification, MATLAB&REG; will call up the GNU ARM Toolchain to convert your model to machine code. After the S file is ready, MATLAB&REG; will start the Microboot program to flash the code to the Olimexino. A similar window to that of Figure 10 should pop up. Reset your Olimexino to flash the program.  
  
 
[[File: ThrottleValveControllerMicroboot.png]]
 
[[File: ThrottleValveControllerMicroboot.png]]
  
Once the model has been uploaded to the Olimexino board, you can test the functioning of the throttle body. Set the lab bench power supply to 12 volts and ask a teacher to make sure the power supply has been set up correctly. Then connect the positive to the red input jack of the throttle body setup and the negative to the black input jack of the setup. Don’t connect anything to the green, blue and yellow input jack. Doing so may break your Olimexino board.
+
[[HANcoder/Examples/ThrottleValveController/HardwareSetup| '''<Go back to part 1''']]
 
Q: What are your findings?
 
 
 
When you build a model, two important files will be created: an S record file (.srec) and an ASAP2 file (.a2l).
 
The S record file contains the compiled model. It contains the machine code that is used to program the microcontroller.
 
The ASAP2 file has information about the model with, amongst other things, the signals that will be visible in HANtune. HANtune needs this file to know which parameters and signals are available in the microcontroller to read or change.
 
To your model, you have added the analog input which the potentiometer is connected to. Now we want to visualize the value using HANtune. Open HANtune from the directory you have saved it to.
 
Tip: Save the HANtune directory under “Documents” and save a HANtune.exe shortcut to your desktop.
 
When HANtune has finished loading up, make a new project. File -> New project
 
 
 
[[File: ThrottleValveControllerAddASAP2.png]]
 
 
 
 
 
[[File: ThrottleValveControllerSelectASAP2.png]]
 
 
 
Now, open the ASAP2 file (a2l) by right clicking “ASAP2 files” and click “Add ASAP2 file”. The ASAP2 file can be found in the same folder as the Simulink template model.
 
The ASAP2 file needs to be loaded up before it can be used. Either right click the “HANcoder_Olimexino.a2l” ASAP2 file and click “(un)Load file” or double click “HANcoder_Olimexino.a2l”.+
 
 
 
Now the ASAP2 file will accommodate HANtune to use the added signals and parameters from Matlab. Next, you’ll put together a dashboard. Click the ASAP Elements tab on the left side of the HANtune window.
 
 
 
[[File: ThrottleValveControllerASAP2Elements.png]]
 
 
 
Under the “ASAP2 elements” tab, there should now be a signal that represents the value of the potentiometer. It will be named the same as the line that you’ve named previously, in the case of this example it will be called “ThrottlePedal”. Select and drag this signal to your dashboard and select GaugeViewer. If you want to move, adjust or remove anything on your dashboard, press CTRL + R. Now you’ll be able to move things around, change sizes or remove something from the dashboard entirely. After you’re done arranging the layout, press CTRL + R again to lock everything in place.
 
Right click the GaugeViewer to change its properties. Click Modify display range to change the range of the GaugeViewer. We want to set the display range to 0 to 4095, because this is the maximum range that the microcontroller can use to convert an analog signal to a digital value, using its 12-bit ADC.
 
 
 
[[File: ThrottleValveControllerGaugeThrottlePedal.png]]
 
 
 
[[File: ThrottleValveControllerGaugeLimits.png]]
 
 
 
Lastly, you need to connect the Olimexino to the computer to actually be able to read the value of the potentiometer. The Olimexino uses a serial USB connection. If you’ve installed the USB driver properly, your laptop should have assigned a COM port to your Olimexino. The first time you connect the Olimexino to HANtune, you’ll need to select the COM port which has been assigned to the Olimexino. To do this, press (F5) to connect and go to settings. Go to the “USB/UART” tab, select the proper COM port and click OK.
 
To figure out which COM port the Olimexino is using, right click the Windows/Start button on your screen and click Device Manager. Then go to Ports (COM & LPT) and click on it. Now look for STMicroelctronics Virtual COM Port and see which port has been assigned to it.
 
 
 
[[File: ThrottleValveControllerPorts.png]]
 
 
 
Choose XCP on USB/UART as your connection type. In this example, the Olimexino is connected to COM5. This is the port we will need to pick in Settings.
 
 
 
[[File: ThrottleValveControllerHANtuneConnectionWindow.png]]
 
 
 
Now you can connect our Olimexino to HANtune by clicking Connect & Request. Once it’s connected, you can check if the signal of the potentiometer is being shown in the GaugeViewer in HANtune.
 
Q: Turn the potentiometer and write down how the throttle body acts for different potentiometer values given in HANtune.
 
 
 
{| class="wikitable"
 
!Function !!Arguments !!Description
 
|-
 
|<code>connect()</code> ||-
 
|-
 
|<code>disconnect()</code> ||-
 
|-
 
|<code>getSignal('name')</code> ||String
 
|-
 
|<code>getParameter('name')</code> ||String
 
|-
 
|<code>connectToFTP('ip', 'port', 'username', 'password')</code> ||String, int, String, String
 
|-
 
|<code>downloadFile('remotePath', 'localPath')</code> ||String, String
 
|-
 
|<code>uploadFile('localPath', 'remotePath')</code> ||String, String
 
|-
 
|<code>createSignal('name')</code> ||String
 
|-
 
|<code>createTrigger('signal', 'function')</code> ||Signal, Function
 
|-
 
|<code>logSignal('name', 'value')</code> ||String, Any numerical value
 
|}
 
  
Turn off the power supply.
+
[[HANcoder/Examples/ThrottleValveController/OpenLoopTest| '''>Go to part 3''']]

Latest revision as of 14:22, 31 May 2018


<Go back to part 1

>Go to part 3

Open Loop control

An open loop control system is a control system that doesn’t use any feedback. It is the simplest type of control system, with the downside of it being fairly crude. It can’t be used for every system though. Nonlinear systems or unpredictable systems in particular are hard to control with this control scheme. The first part of this practical assignment will be to make an open loop control system to control an automotive throttle body. You will have to send out a PWM signal to the throttle body that is relative to the throttle position (potentiometer). Open MATLAB Simulink&REG; and run the HANcoder_Olimexino.slx template model that you can find in you HANcoder Target directory. Double click the picture of the Olimexino board to enter the model. Then delete the “Inputs”, “Algorithm”, and “Outputs” blocks, so you’ll have a nice and clean model to start off with. Your model should look now a little something like this:

ThrottleValveControllerTemplModel.png

First, you’ll need to add an input to the model, which in this case will be the potentiometer representing the throttle. From the Library Browser, you’ll need to drag an analog input block into the Simulink model and, under properties, select the input connector that the potentiometer is connected to, A0 in this case. Open Simulink, click “Library Browser” and navigate to HANcoder STM32 Target -> Olimexino STM32 -> Analog Inputs. In the right column, the Analog Input block will appear. Select the block and drag it into the template model.

ThrottleValveControllerAnaIn.png

Configure the Analog Input block to read the Input pin A0 by double clicking it. The output of this block needs to be configured to become available in HANtune.

ThrottleValveControllerAnaSetPin.png

Now an output needs to be added to the model. Because the throttle body is the thing that needs to be controlled, an output is needed that can control the throttle body. Because a microcontroller isn’t able to meet the throttle body’s power requirements, some interface circuitry in the form of an H-bridge is required as an intermediary between the microcontroller and the throttle body. This H-bridge can send out a 0-12v PWM signal in two directions to regulate the speed, direction of movement and position of the throttle valve. The H-bridge operates using two logic level PWM inputs, one to control the movement of the valve clockwise and the other to control the movement of the valve counter-clockwise. You can use the Olimexino microcontroller to send out a 0-3.3v PWM signal to these PWM inputs. Because the H-bridge uses one PWM signal for each direction, you’ll need to use two PWM output in your model, if you want to operate the throttle bi-directionally.

Q: Which input pin is the potentiometer connected to?

Q: How can you control throttle body that works with a 12v PWM signal with a microcontroller that sends out a 3.3v PWM signal?

With this first assignment though, you will only be driving the electric motor in one direction to open the throttle. The spring that’s built in to the throttle body will be used to close the throttle valve. To open the throttle valve, the PWMA pin on the H-bridge needs to get a PWM signal from the Olimexino microcontroller. This PWMA pin of the H-bridge is connected to the digital output D0 of your Olimexino board. Along with the PWM output block, a PWM Init block needs to be added.

Open the Library Browser in Simulink. Navigate to HANcoder STM32 Target  Olimexino STM32  PWM Outputs. On the right side of the library browser, you’ll find two blocks: PWM Duty Cyble and PWM Init.

ThrottleValveControllerPWMduty.png

Drag both blocks into your model. Double click the PWM init block and select a switching frequency of 1 kHz, which MATLAB&REG; will change to 1004Hz. Also select the PWM module with the correct digital output pins and send out a PWM signal on these pins, in this case the PWM module that contains D0 and D3. Because the PWM module “TIM2: D2 & D3 & n/a & D0” is being used, Channel 1 will be D2, Channel 2 D3, Channel 3 not available, and Channel 4 D0. Because the opening action of the throttle valve is connected to pin D0, a PWM signal needs to be created on D0. Click the Channel 4 tab and check the checkbox that says “Generate PWM signal on channel 4”.

ThrottleValveControllerPWMmoduleSelect.png

ThrottleValveControllerActivateChannel.png

Now double click the PWM duty cycle block and select the correct output pin.

Q: Which digital output pins do you need to send the PWM signal to?

The input and output can now be connected to make a very simple throttle controller that sends out a PWM signal to the throttle valve that is relative to the input signal. However, because the Analog input operates with a 12 bit resolution (0-4095) and the PWM outputs operate with a 10 bit resolution (0-1023), a gain needs to be added to make full use of the potentiometer’s range. Drag a Gain block, from the Simulink Library Browser’s Math Operations category, into your model and put it in-between the analog input and a PWM output. Connect the parts and select the appropriate gain value. Don’t forget to select the correct output data type for the Gain block. The correct datatype, uint16, can be selected by double clicking the gain block.

ThrottleValveControllerOpenLoopModel.png

Q: What gain value needs to be added? It can be very useful to be able to have the ability to view the signal of the throttle pedal (potentiometer) in HANtune. For this purpose, it has to be available as a signal within HANtune. The first thing you’ll need to do, is naming the signal logically. To name the signal, double click the line that runs between the Analog input block and the Gain block. A text box should appear beneath the line. Name it sensibly, you may call it ThrottlePedal for example. Now that the inputs and outputs are assigned, and a gain has been added to make the inputs compatible with the outputs, the model can be uploaded to the Olimexino. The Simulink model is now ready to compile and be programmed to the Olimexino. Build your model.

ThrottleValveControllerBuildButton.png

After agreeing to a licensing notification, MATLAB&REG; will call up the GNU ARM Toolchain to convert your model to machine code. After the S file is ready, MATLAB&REG; will start the Microboot program to flash the code to the Olimexino. A similar window to that of Figure 10 should pop up. Reset your Olimexino to flash the program.

ThrottleValveControllerMicroboot.png

<Go back to part 1

>Go to part 3