MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
quarc_i2c_imu_demoQUARC I2C IMU Demo
This is an example of using an I2C device with QUARC that requires a combined write-read bus transaction. It interfaces with a nine-axis IMU sensor. Since the IMU requires combined write and read operations in a single I2C bus transaction, this example makes use of the Stream Write-Read block.
System Requirements
This demonstration is run using the QUARC NVidia target. To use QUARC for Linux NVidia, a Quanser challenge employing this target, such as the QCar, is required, as well as a software license for the Linux NVidia target.
For a detailed discussion on the QUARC Linux NVidia target and requirements needed to run models on this target, please refer to the QUARC Linux NVidia Target reference page.
This example also requires an LSM9DS1 nine-axis digital output IMU sensor from STMicroelectronics Inc., wired to I2C port 0 of the target. A convenient peripheral module called the Sparkfun 9DoF IMU Breakout board is provided by Sparkfun Inc. that uses the LSM9DS1 digital output IMU. This example was tested using this peripheral module.
The VDD pin of the breakout board connector should be wired to +3.3V and the GND pin should be wired to ground. The SCL pin should be wired to the serial clock (SCL) of the I2C port and the SDA pin should be wired to the serial data line (SDA) of the I2C port. The CS AG and SDO AG pins should be wired to +3.3V. Note that the base slave address of the IMU will be 0x6B or 0b1101011. See the LSM9DS1 datasheet for details. The LSM9DS1 Breakout Hookup Guide may also be helpful.
Configuring the Demonstration
Open the QUARC Preferences dialog by selecting
from the menu of one of the Simulink diagrams.
Select linux_nvidia
as the Target type on the Model pane. Then change the IP address
in the Default model URI parameter to match your Linux NVidia target. For example, if your target
has an IP address of 172.16.0.155, then the Default model URI should be
tcpip://172.16.0.155:17001?nagle=no
.
A hostname may be used instead of the IP address if the target is configured
with a hostname. The concept of URI's and their use in communications is discussed in
Communicating with the Target .
In this example, communications between Simulink and the model will occur using TCP/IP. This step configures the default communications
scheme used with the Linux NVidia target and does not have to be repeated unless the
address of the target changes.
The slave address of the URI used by the Stream Call block must match the slave address configured for the IMU on its SDO AG pin. If this pins is tied high, then the address should be 0x6B or 0b1101011. Otherwise the slave address will need to be changed to 0x6A or 0b1101010.
To change the URI of the Stream Call block, double-click on the block to open its configuration dialog, as shown below.
In the URI of host to which to connect field, replace the value of the address option in the URI with the appropriate slave address.
Click OK to close the configuration dialog.
Running the Model Using the QUARC Target for Linux NVidia
Please note that in order to be able to run this part of the demo, you must have purchased the QUARC Target for Linux NVidia as part of your license. In addition you must have satisfied the software and hardware requirements found in the QUARC Installation Guide. This target is used, for example, with the Quanser QCar.
To open the model click on the "Open this model" button found on the top right corner of this page.
Select
from the menu of the diagram, or select from the simulation mode combo box on the toolbar.Select Ctrl+B while the diagram is the active window. A great deal of output will appear in the Diagnostic Viewer about the progress of the build. If you cannot see the Diagnostic Viewer, you can open it by selecting from the menu of the diagram, or clicking on the View Diagnostics hyperlink at the bottom of the diagram.
from the menu of the diagram, or pressIf the build is successful, then the line:
*** Created executable quarc_i2c_imu_demo.rt-linux_duovero
will appear in the Command Window. Finally, QUARC will download the model to the QUARC Target for Linux NVidia. The line:
### Model quarc_i2c_imu_demo has been downloaded to target 'tcpip://192.168.111.35:17000' (133584 bytes)
will appear in the Command Window indicating that the code was successfully downloaded to the QUARC Target. The IP address will match the IP address of your Linux NVidia target. If any errors occur, appropriate error messages will appear in the Command Window.
Double click on the Rates (deg/s) block and Accelerations (g) block to open the Scopes.
Click on the
button or select from the menu of the diagram to connect to the model.Start the model by clicking on the
button or selecting from the menu of the diagram. The item of the menu may also be used to both connect and start the model in one operation.Rotate the IMU about its Cartesian axes. The angular velocities in degrees per second will appear in the Scope as shown below. Notice that the Scope trace is moving in actual time. In other words, the trace passes the 10 second mark after 10 seconds have passed since in external mode, QUARC runs the model in real-time.
Move the IMU linearly along its Cartesian axes. The accelerations in g will appear in the Scope as shown below.
Click on the
button or select from the menu of the diagram to stop the model. The item of the menu may also be used.Running the example on a different target
To run the example on a different target, refer to the instructions on the Running QUARC Examples on Remote Targets page.
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.