In this last part of the tutorial I’ll show the steps needed to compile a simple target and remotely interact with it.
The objective is to display a sine wave and control its amplitude.
Step 1 - Build the model using Scicos
The first thing to do is to use Scicoslab modeling GUI - Scicos - to create the model. Keep in mind the following figure when placing blocks.
Create a subfolder in your home folder named test
- Open Scicoslab.
- In upper bar, toolboxes -> RTAI. Check for “Scicos-RTAI Ready” output.
- Type scicos in command window to open modeling GUI.
- In the new window, Palette -> Pal Tree to open the list of available blocks.
- Expand Sources and grab the red clock. Place it in the upper part of your model.
- Double-click the clock. From here you can set operating frequency. Type 1/1000 as Period (1KHz)
- In Palettes windows, expand Linear and drag gain block to the model, directly below the clock.
- Right-click on the gain block you just placed and select Block Properties -> Identification. Type gain.
- In Palettes windows, expand RTAI-Lib and place a Sine block and a Scope block respectively to the left and right of gain block.
- Double-click the Sine block and set Frequency to 50.
- Now connect blocks as shown in figure. (TIP: to branch a line, just right-click it and select Link).
Step 2 - Compile the real-time executable
- In scicos window, drag a selection that covers all the model except for the clock.
- In upper bar, Diagram -> Region to Super Block. It’s mandatory that all your model is contained in a single Super Block with only Clock as input.
- Highlight the Super Block and, in upper bar, RTAI -> Set Target. Confirm with OK.
- The super block will automatically expand in a new window. Go back to the main scicos windows, highlight again the Super Block and, in upper bar, RTAI -> RTAI CodeGen.
- Under New block’s name you can chose the target name. For this example, name it testsine
- Under Created files Path, enter /home/yourusername/test
- Confirm with OK and check Scicoslab window for compiling results. If you see the output “### Created executable: testsine ###” then your target is ready to run.
Step 3 - Test the target with QRTAILab
- qrtailab &
- Check is “TARGET STARTS.” is prompted as output in terminal.
- Switch to QRTAILab window.
- In upper bar, Target -> Connect. You should see in the lower left-hand corner of the window the message “Target: testsine”.
- In upper bar, View -> Scope. Check “Show/Hide” option and adjust “sec/div” to get a nicer visualization (i.e. 0.05). Then close manager.
- Now we try to control wave amplitude on-the-fly. In upper bar, View -> Parameter.
- Double click on gain, then select Block Parameters tab. Try different values and see changes in the scope
- Now go back to QRTAILab main window. In upper bar, Target -> Stop. Then close QRTAILab.
Step 4 - Remotely control your target with jRTAI-Lab
- The first things to do are to properly configure server machine. In terminal:
- cd /usr/realtime/rtaixml/scripts
- sudo cp TEST STEST
- sudo gedit STEST
- This is the configuration script for rtaixml. You have to configure a copy of it for each target you want to remotely control. NOTE: the file name shouldn’t exceed six characters long.
- Under “#Name of the target executable”, you need target=testsine.
- Under “#Absolute path”, dir=/home/yourusername
- Set “Final Time” to 1000
- Remove the “#” before “wait=true” and set it to false.
- RTAI-XML server is ready. Move on the client machine.
- Start jRTAI-Lab (see the end of Part 2 of this document) and click on the button that pops up.
- In upper bar, File -> Connect
- Edit IP of server machine, leave “Server Port” to default and in “Target ID” insert the script name you created for the target (in this example, STEST).
- In upper bar, View -> Signal. Click on SCOPE then check Plot.
- In upper bar, View -> Parameters. Here you can live adjust model parameters as you did in QRTAILab (NOTE: remember to press ENTER in the parameter value, “Set” button alone isn’t enough).