s-function builder Simulink for Arduino

6 次查看(过去 30 天)
EB
EB 2020-6-4
评论: SRance 2020-9-30
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 个评论
SRance
SRance 2020-9-30
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by