Problem with Simulink and arduino

1 view (last 30 days)
peter sender
peter sender on 24 Aug 2016
Commented: PIRC on 17 Oct 2016
Im trying to transform my arduino code into a simulink model. The arduino code:
#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//Define Variables we'll be connecting to
double InputCor, Setpoint, Input, Output;
//Define the aggressive and conservative Tuning Parameters
double consKp=1, consKi=0.05, consKd=0.25;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
int digPinA = 3; // pin digital 10
int digPinB = 11; // pin digital 10
void setup() {
//initialize the variables we're linked to
Input = InputCor;
Setpoint = 17;
//turn the PID on
myPID.SetMode(AUTOMATIC);
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(13, OUTPUT);
Serial.begin(9600);
sensors.begin();
}
void loop() {
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(13, HIGH); //Establishes forward direction of Channel B
analogWrite(digPinA,255);
sensors.requestTemperatures();
Serial.print("Temperature for Device 1 is: ");
Serial.println(sensors.getTempCByIndex(0));
InputCor = sensors.getTempCByIndex(0);
Input = InputCor-2*(InputCor-Setpoint);
Serial.print("input: ");
Serial.println(Input);
myPID.SetTunings(consKp, consKi, consKd);
myPID.Compute();
if(Output>250)
{
Output=250;
}
Serial.print("PWM: ");
Serial.println(Output);
delay (500);
analogWrite(digPinB,Output); //
}
I tried it creating S-function builder for the libraries functions, but when I want to download it to arduino I get this error:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: "C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/tools/avr/bin/avr-gcc" -I"C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/include" -I"C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include" -I"C:/Users/daniel/Desktop/tfg/simulink/V0_rtt" -I"C:/Users/daniel/Desktop/tfg/simulink" -I"D:/temp/extern/include" -I"D:/temp/simulink/include" -I"D:/temp/rtw/c/src" -I"D:/temp/rtw/c/src/ext_mode/common" -I"D:/temp/rtw/c/ert" -I"C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino" -I"C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/variants/standard" -I"C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/libraries/Servo" -mmcu=atmega328p -ffunction-sections -fdata-sections -std=gnu99 -Wall -Wstrict-prototypes -g -Os -D"MODEL=V0" -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"ARDUINO=105" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_RTT_NUMSERVOS_=0" -c -x none ./HardwareSerial.cpp ./IPAddress.cpp ./Print.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp ./wiring.c ./wiring_analog.c ./wiring_digital.c ./io_wrappers.cpp ./PID_wrapper.cpp ./ReqTemp_wrapper.cpp ./V0.c ./V0_data.c ./ert_main.c
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./HardwareSerial.cpp: In function 'void store_char(unsigned char, ring_buffer*)':
./HardwareSerial.cpp:98: warning: comparison between signed and unsigned integer expressions
./HardwareSerial.cpp: In function 'void __vector_18()':
./HardwareSerial.cpp:127: warning: unused variable 'c'
./HardwareSerial.cpp: In member function 'void HardwareSerial::begin(long unsigned int, byte)':
./HardwareSerial.cpp:368: warning: unused variable 'current_config'
./HardwareSerial.cpp: In member function 'virtual size_t HardwareSerial::write(uint8_t)':
./HardwareSerial.cpp:467: warning: comparison between signed and unsigned integer expressions
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./Print.cpp: In member function 'size_t Print::print(const __FlashStringHelper*)':
./Print.cpp:44: warning: '__progmem__' attribute ignored
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./PID_wrapper.cpp:16:2: error: invalid preprocessing directive #definde
./PID_wrapper.cpp:21: error: 'Input' was not declared in this scope
./PID_wrapper.cpp:21: error: 'Output' was not declared in this scope
./PID_wrapper.cpp:21: error: 'Setpoint' was not declared in this scope
./PID_wrapper.cpp:21: error: 'kp' was not declared in this scope
./PID_wrapper.cpp:21: error: 'ki' was not declared in this scope
./PID_wrapper.cpp:21: error: 'kd' was not declared in this scope
./PID_wrapper.cpp: In function 'void PID_Outputs_wrapper(const real_T*, const real_T*, const real_T*, const real_T*, const real_T*, real_T*)':
./PID_wrapper.cpp:58: error: no matching function for call to 'PID::SetTunings(const real_T*&, const real_T*&, const real_T*&)'
C:/Users/daniel/Desktop/tfg/simulink/PID_v1.cpp:83: note: candidates are: void PID::SetTunings(double, double, double)
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./ReqTemp_wrapper.cpp:16:2: error: invalid preprocessing directive #definde
In file included from ./ReqTemp_wrapper.cpp:20:
C:/Users/daniel/Desktop/tfg/simulink/OneWire.cpp:480: warning: only initialized variables can be placed into program memory area
./ReqTemp_wrapper.cpp: In function 'void ReqTemp_Outputs_wrapper(real_T*)':
./ReqTemp_wrapper.cpp:61: error: cannot convert 'float' to 'real_T*' in assignment
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./V0.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:25:1: warning: "true" redefined
In file included from ./V0.h:23,
from ./V0.c:17:
./rtwtypes.h:27:1: warning: this is the location of the previous definition
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./V0.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:26:1: warning: "false" redefined
In file included from ./V0.h:23,
from ./V0.c:17:
./rtwtypes.h:23:1: warning: this is the location of the previous definition
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./V0_data.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:25:1: warning: "true" redefined
In file included from ./V0.h:23,
from ./V0_data.c:17:
./rtwtypes.h:27:1: warning: this is the location of the previous definition
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./V0_data.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:26:1: warning: "false" redefined
In file included from ./V0.h:23,
from ./V0_data.c:17:
./rtwtypes.h:23:1: warning: this is the location of the previous definition
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./ert_main.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:25:1: warning: "true" redefined
In file included from ./V0.h:23,
from ./ert_main.c:17:
./rtwtypes.h:27:1: warning: this is the location of the previous definition
In file included from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_blocks_abstraction.h:8,
from C:/MATLAB/SupportPackages/R2015a/arduinobase/toolbox/realtime/targets/arduino/blocks/sfcn/include/arduino_analogoutput_lct.h:11,
from ./V0.h:26,
from ./ert_main.c:17:
C:/MATLAB/SupportPackages/R2015a/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:26:1: warning: "false" redefined
In file included from ./V0.h:23,
from ./ert_main.c:17:
./rtwtypes.h:23:1: warning: this is the location of the previous definition
./ert_main.c: In function '__vector_13':
./ert_main.c:39: warning: implicit declaration of function 'rt_OneStep'
./ert_main.c: At top level:
./ert_main.c:46: warning: function declaration isn't a prototype
./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: *** [HardwareSerial.o] Error 1
I tried before using a simple default block from simulink, and it works fine.
  1 Comment
PIRC
PIRC on 17 Oct 2016
try to convert you arduino code into s function in matlab

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!