s-function builder Simulink for Arduino
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to build an s-function builder for the LSM6DS3 IMU with the following Arduino code:
#include <Arduino_LSM6DS3.h>
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (true); // halt program
}
Serial.println("IMU initialized!");
}
void loop() {
float aX, aY, aZ;
float gX, gY, gZ;
const char * spacer = ", ";
if (
IMU.accelerationAvailable()
&& IMU.gyroscopeAvailable()
) {
IMU.readAcceleration(aX, aY, aZ);
IMU.readGyroscope(gX, gY, gZ);
Serial.print(aX); Serial.print(spacer);
Serial.print(aY); Serial.print(spacer);
Serial.print(aZ); Serial.print(spacer);
Serial.print(gX); Serial.print(spacer);
Serial.print(gY); Serial.print(spacer);
Serial.println(gZ);
delay(1000);
}
}
Data Properties, I deleted the input ports since I will not have any, and added an output port with a random name with uint32 (only because it was suggested in the reference example link below).
I put this in the Libraries Includes:
#include <math.h>
# ifndef MATLAB_MEX_FILE
# include <Arduino.h>
#include <Arduino_LSM6DS3.h>
# endif
Outputs:
if(xD == 1)
# ifndef MATLAB_MEX_FILE
ana[0] = analogRead(A0);
# endif
Update:
if (xD[0] != 1)
xD[0] = 1;
When I compile it, I get the following error code:
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c: In function 'IoT_Outputs_wrapper':
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:47:4: error: 'xD' undeclared (first use in this function)
if(xD == 1)
^~
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:47:4: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:52:1: error: expected expression before '}' token
}
^
What should I modify to get this to display all six values?
Reference:
1 Kommentar
SRance
am 30 Sep. 2020
Your outputs needs to specify the element, i.e: if(xD[0] == 1)
You also need to bracket your functions with the { } on the outputs and update.
For reference, even if you have a constant you will need to reference it like a C array.
Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!