How to create a new block using a library from Arduino that is not in the Simulink Support Package for Arduino?

2 ビュー (過去 30 日間)
Hi,
I'm trying to use the Arduino Leonardo as a mouse, and I want to create a new block using the library file "Mouse.h" from Arduino. I have a sketch that works fine in the Arduino IDE.
I tried to follow this guide and use the S-function builder to create the block that I need, but it doesn't work.
In the Simulink's model I try to make a simple block that activate the mouse, using the function "Mouse.begin()", when a button is pressed, just to test if I could import the Arduino library.
But when I try to deploy to hardware, appears a lot of errors and I don't know how to get rid of them.
These are the errors that appear:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: "C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/tools/avr/bin/avr-gcc" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduinobase/toolbox/realtime/targets/arduino/include" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include" -I"C:/Users/lipe_/Documents/MATLAB/Mouse/Begin_Mouse_rtt" -I"C:/Users/lipe_/Documents/MATLAB/Mouse" -I"C:/Users/lipe_/Documents/MATLAB/Mouse/Simulink" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/extern/include" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/simulink/include" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/src" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/src/ext_mode/common" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/ert" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/variants/leonardo" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/libraries/Servo" -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega32u4 -D"MODEL=Begin_Mouse" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"ALLOCATIONFCN=0" -D"TID01EQ=0" -D"F_CPU=16000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"ARDUINO=105" -D"_ROTH_LEONARDO_=" -D"MMD=" -D"USB_VID=0x2341" -D"USB_PID=0x8036" -D"_RTT_NUMSERVOS_=0" -c -x none ./CDC.cpp ./HID.cpp ./HardwareSerial.cpp ./HardwareSerial0.cpp ./HardwareSerial1.cpp ./HardwareSerial2.cpp ./HardwareSerial3.cpp ./IPAddress.cpp ./PluggableUSB.cpp ./Print.cpp ./Stream.cpp ./Tone.cpp ./USBCore.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp ./wiring.c ./wiring_analog.c ./wiring_digital.c ./wiring_pulse.c ./wiring_shift.c ./io_wrappers.cpp ./BeginMouse_wrapper.cpp ./Begin_Mouse.c ./Begin_Mouse_data.c ./ert_main.c
In file included from ./PluggableUSB.cpp:21:
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: invalid in-class initialization of static data member of non-integral type 'PluggableUSBModule*'
./PluggableUSB.cpp: In member function 'int PluggableUSB_::getInterface(uint8_t*)':
./PluggableUSB.cpp:32: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'int PluggableUSB_::getDescriptor(USBSetup&)':
./PluggableUSB.cpp:44: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'void PluggableUSB_::getShortName(char*)':
./PluggableUSB.cpp:56: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'bool PluggableUSB_::setup(USBSetup&)':
./PluggableUSB.cpp:65: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'bool PluggableUSB_::plug(PluggableUSBModule*)':
./PluggableUSB.cpp:83: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp:84: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp:86: error: 'class PluggableUSBModule' has no member named 'next'
./Print.cpp: In member function 'size_t Print::print(const __FlashStringHelper*)':
./Print.cpp:44: warning: '__progmem__' attribute ignored
./Tone.cpp:210:12: warning: #warning this may not be correct
./Tone.cpp:110: warning: only initialized variables can be placed into program memory area
./USBCore.cpp:25:1: warning: "EP_TYPE_CONTROL" redefined
In file included from C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:225,
from C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/Platform.h:15,
from ./USBCore.cpp:19:
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:50:1: warning: this is the location of the previous definition
./USBCore.cpp:26:1: warning: "EP_TYPE_BULK_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:51:1: warning: this is the location of the previous definition
./USBCore.cpp:27:1: warning: "EP_TYPE_BULK_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:52:1: warning: this is the location of the previous definition
./USBCore.cpp:28:1: warning: "EP_TYPE_INTERRUPT_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:53:1: warning: this is the location of the previous definition
./USBCore.cpp:29:1: warning: "EP_TYPE_INTERRUPT_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:54:1: warning: this is the location of the previous definition
./USBCore.cpp:30:1: warning: "EP_TYPE_ISOCHRONOUS_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:55:1: warning: this is the location of the previous definition
./USBCore.cpp:31:1: warning: "EP_TYPE_ISOCHRONOUS_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:56:1: warning: this is the location of the previous definition
./USBCore.cpp: In function 'int USB_Send(u8, const void*, int)':
./USBCore.cpp:278: warning: unused variable 'zero'
./USBCore.cpp: At global scope:
./USBCore.cpp:364: error: 'Setup' was not declared in this scope
./USBCore.cpp:365: error: expected ',' or ';' before '{' token
./USBCore.cpp: In function 'int SendInterfaces()':
./USBCore.cpp:432: warning: unused variable 'total'
./USBCore.cpp: At global scope:
./USBCore.cpp:467: error: 'Setup' was not declared in this scope
./USBCore.cpp:468: error: expected ',' or ';' before '{' token
./USBCore.cpp:340: warning: 'void InitEP(u8, u8, u8)' defined but not used
./USBCore.cpp:349: warning: 'void InitEndpoints()' defined but not used
./USBCore.cpp:364: warning: 'ClassInterfaceRequest' defined but not used
./USBCore.cpp:450: warning: 'bool SendConfiguration(int)' defined but not used
./USBCore.cpp:467: warning: 'SendDescriptor' defined but not used
./wiring.c:264:3: warning: #warning Timer 2 not finished (may not be present on this CPU)
./wiring.c:273:3: warning: #warning Timer 2 not finished (may not be present on this CPU)
./io_wrappers.cpp: In function 'void Serial_read(int, int, uint8_t*, int16_t*)':
./io_wrappers.cpp:70: warning: 'libFcnOutput' may be used uninitialized in this function
In file included from ./BeginMouse_wrapper.cpp:18:
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: invalid in-class initialization of static data member of non-integral type 'PluggableUSBModule*'
In file included from C:/Users/lipe_/Documents/MATLAB/Mouse/Mouse.h:25,
from ./BeginMouse_wrapper.cpp:19:
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: invalid in-class initialization of static data member of non-integral type 'HIDSubDescriptor*'
./ert_main.c: In function '__vector_35':
./ert_main.c:39: warning: implicit declaration of function 'rt_OneStep'
./ert_main.c: At top level:
./ert_main.c:63: warning: conflicting types for 'rt_OneStep'
./ert_main.c:39: warning: previous implicit declaration of 'rt_OneStep' was here
./ert_main.c: In function 'rt_OneStep':
./ert_main.c:87: warning: 'eventFlags[0]' may be used uninitialized in this function
make: *** [CDC.o] Error 1
The build process will terminate as a result.
The build failed with the following message: "C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/tools/avr/bin/avr-gcc" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduinobase/toolbox/realtime/targets/arduino/include" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include" -I"C:/Users/lipe_/Documents/MATLAB/Mouse/Begin_Mouse_rtt" -I"C:/Users/lipe_/Documents/MATLAB/Mouse" -I"C:/Users/lipe_/Documents/MATLAB/Mouse/Simulink" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/extern/include" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/simulink/include" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/src" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/src/ext_mode/common" -I"C:/Program Files/MATLAB/MATLAB Production Server/R2015a/rtw/c/ert" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/variants/leonardo" -I"C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/libraries/Servo" -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega32u4 -D"MODEL=Begin_Mouse" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"ALLOCATIONFCN=0" -D"TID01EQ=0" -D"F_CPU=16000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"ARDUINO=105" -D"_ROTH_LEONARDO_=" -D"MMD=" -D"USB_VID=0x2341" -D"USB_PID=0x8036" -D"_RTT_NUMSERVOS_=0" -c -x none ./CDC.cpp ./HID.cpp ./HardwareSerial.cpp ./HardwareSerial0.cpp ./HardwareSerial1.cpp ./HardwareSerial2.cpp ./HardwareSerial3.cpp ./IPAddress.cpp ./PluggableUSB.cpp ./Print.cpp ./Stream.cpp ./Tone.cpp ./USBCore.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp ./wiring.c ./wiring_analog.c ./wiring_digital.c ./wiring_pulse.c ./wiring_shift.c ./io_wrappers.cpp ./BeginMouse_wrapper.cpp ./Begin_Mouse.c ./Begin_Mouse_data.c ./ert_main.c
In file included from ./PluggableUSB.cpp:21:
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: invalid in-class initialization of static data member of non-integral type 'PluggableUSBModule*'
./PluggableUSB.cpp: In member function 'int PluggableUSB_::getInterface(uint8_t*)':
./PluggableUSB.cpp:32: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'int PluggableUSB_::getDescriptor(USBSetup&)':
./PluggableUSB.cpp:44: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'void PluggableUSB_::getShortName(char*)':
./PluggableUSB.cpp:56: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'bool PluggableUSB_::setup(USBSetup&)':
./PluggableUSB.cpp:65: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp: In member function 'bool PluggableUSB_::plug(PluggableUSBModule*)':
./PluggableUSB.cpp:83: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp:84: error: 'class PluggableUSBModule' has no member named 'next'
./PluggableUSB.cpp:86: error: 'class PluggableUSBModule' has no member named 'next'
./Print.cpp: In member function 'size_t Print::print(const __FlashStringHelper*)':
./Print.cpp:44: warning: '__progmem__' attribute ignored
./Tone.cpp:210:12: warning: #warning this may not be correct
./Tone.cpp:110: warning: only initialized variables can be placed into program memory area
./USBCore.cpp:25:1: warning: "EP_TYPE_CONTROL" redefined
In file included from C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:225,
from C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/Platform.h:15,
from ./USBCore.cpp:19:
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:50:1: warning: this is the location of the previous definition
./USBCore.cpp:26:1: warning: "EP_TYPE_BULK_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:51:1: warning: this is the location of the previous definition
./USBCore.cpp:27:1: warning: "EP_TYPE_BULK_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:52:1: warning: this is the location of the previous definition
./USBCore.cpp:28:1: warning: "EP_TYPE_INTERRUPT_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:53:1: warning: this is the location of the previous definition
./USBCore.cpp:29:1: warning: "EP_TYPE_INTERRUPT_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:54:1: warning: this is the location of the previous definition
./USBCore.cpp:30:1: warning: "EP_TYPE_ISOCHRONOUS_IN" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:55:1: warning: this is the location of the previous definition
./USBCore.cpp:31:1: warning: "EP_TYPE_ISOCHRONOUS_OUT" redefined
C:/Users/lipe_/Documents/MATLAB/Arduino/arduino-1.0.5/hardware/arduino/cores/arduino/USBAPI.h:56:1: warning: this is the location of the previous definition
./USBCore.cpp: In function 'int USB_Send(u8, const void*, int)':
./USBCore.cpp:278: warning: unused variable 'zero'
./USBCore.cpp: At global scope:
./USBCore.cpp:364: error: 'Setup' was not declared in this scope
./USBCore.cpp:365: error: expected ',' or ';' before '{' token
./USBCore.cpp: In function 'int SendInterfaces()':
./USBCore.cpp:432: warning: unused variable 'total'
./USBCore.cpp: At global scope:
./USBCore.cpp:467: error: 'Setup' was not declared in this scope
./USBCore.cpp:468: error: expected ',' or ';' before '{' token
./USBCore.cpp:340: warning: 'void InitEP(u8, u8, u8)' defined but not used
./USBCore.cpp:349: warning: 'void InitEndpoints()' defined but not used
./USBCore.cpp:364: warning: 'ClassInterfaceRequest' defined but not used
./USBCore.cpp:450: warning: 'bool SendConfiguration(int)' defined but not used
./USBCore.cpp:467: warning: 'SendDescriptor' defined but not used
./wiring.c:264:3: warning: #warning Timer 2 not finished (may not be present on this CPU)
./wiring.c:273:3: warning: #warning Timer 2 not finished (may not be present on this CPU)
./io_wrappers.cpp: In function 'void Serial_read(int, int, uint8_t*, int16_t*)':
./io_wrappers.cpp:70: warning: 'libFcnOutput' may be used uninitialized in this function
In file included from ./BeginMouse_wrapper.cpp:18:
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/PluggableUSB.h:47: error: invalid in-class initialization of static data member of non-integral type 'PluggableUSBModule*'
In file included from C:/Users/lipe_/Documents/MATLAB/Mouse/Mouse.h:25,
from ./BeginMouse_wrapper.cpp:19:
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: ISO C++ forbids initialization of member 'next'
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: making 'next' static
C:/Users/lipe_/Documents/MATLAB/Mouse/HID.h:84: error: invalid in-class initialization of static data member of non-integral type 'HIDSubDescriptor*'
./ert_main.c: In function '__vector_35':
./ert_main.c:39: warning: implicit declaration of function 'rt_OneStep'
./ert_main.c: At top level:
./ert_main.c:63: warning: conflicting types for 'rt_OneStep'
./ert_main.c:39: warning: previous implicit declaration of 'rt_OneStep' was here
./ert_main.c: In function 'rt_OneStep':
./ert_main.c:87: warning: 'eventFlags[0]' may be used uninitialized in this function
make: *** [CDC.o] Error 1
Component: Simulink | Category: Model error
And this is my "s_function_wrapper.cpp":
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifndef MATLAB_MEX_FILE
#include <Arduino.h>
#include "PluggableUSB.h"
#include "Mouse.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output functions
*
*/
extern "C" void BeginMouse_Outputs_wrapper(const boolean_T *in,
const real_T *xD,
const uint8_T *pin, const int_T p_width0)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
y0[0] = u0[0];
For complex signals use: y0[0].re = u0[0].re;
y0[0].im = u0[0].im;
y1[0].re = u1[0].re;
y1[0].im = u1[0].im;
*/
if (xD[0]==1){
#ifndef MATLAB_MEX_FILE
if(digitalRead(pin[0])==HIGH){
Mouse.begin();
}
#endif
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
extern "C" void BeginMouse_Update_wrapper(const boolean_T *in,
real_T *xD,
const uint8_T *pin, const int_T p_width0)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
if(xD[0]!=1){
#ifndef MATLAB_MEX_FILE
//pinMode(pin[0],INPUT);
#endif
xD[0]=1;
}
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
I'm using Matlab R2015a, Windows 10 (64-bit) and Microsoft Visual C++ 2013.
Could anyone help me solve this problem? I'm starting to use Simulink now, so I don't have much experience.
Sorry for bad English, I'm from Brazil.

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by