Arduino DUE custom servo block (LCT) not working despite no compile errors

1 vue (au cours des 30 derniers jours)
Multiplexer
Multiplexer le 24 Mar 2022
Modifié(e) : Multiplexer le 24 Mar 2022
Hello,
I'm trying to create my own servo.write block in Simulink for Arduino DUE deployment (and External Mode). Before you ask why if there is one available inside the Support Package, generally my final goal is to create a block that will use Arduino servo.writeMicroseconds function (there is no out of the box block for this one) but first i want to try with something simple to debug to see if i can get it to work....
So, generally I'm using his guide https://www.mathworks.com/matlabcentral/fileexchange/39354-device-drivers and the LCT approach. I based my code on one of the example that is provided there and after making some simple modification (basically renaming functions) code seems to compile without any errors, it deploys to hardware in "Monitor and Tune" mode but thats all that happens. The servo port is simply dead and does not output anything at all. It's like the servo.attach() function is never used and the port is never initialised. Of course if I replace S-Function block with built in "Servo Write" block it all works as expected so hardware is not an issue.
I've triple checked all the names and there are no typos. I made sure to add include directories from the hardware support package directory. I have the "Servo" variable in a scope that should be available for both initialise and output function but no idea where else to look for the cause of this issue.
I'm attaching LCT script, cpp source files used in LCT and the harness model I'm using for the S-Function.
Thank you in advance for help.
  1 commentaire
Multiplexer
Multiplexer le 24 Mar 2022
Modifié(e) : Multiplexer le 24 Mar 2022
I've even simplified it even more by editing the original digitalio_arduino.cpp/h files from the guide (example with digital read/out) which BTW works without any issue.
Step by step i made following modifications:
1. Remove DIO read (leave only write) from CPP and H files
2. Change StartFcnSpec to digitalIOSetup and make changes in H file so port is always in OUTPUT mode
2. Add Servo.h library and create Servo object within CPP files
Up to this point, all edits went fine, no compile errors, all header files detected by Simulink and diode kept blinking as it should so the code actually worked in External Mode.
But of course as soon as i made the final modification and replaced pinMode() with myservo.attach() and digitalWrite() with myservo.write()
(of course i changed the data type in writeDigitalPin function from boolean to uint8_T)
the code despite compiling and building without any issue again does not work at all. Specified servo port is not being initialised at all and nothing happens when i change S-Function input.
I'm attaching simplified version where you can actually see how I edited the original Digital I/O example. Also, here's source:
LCT script
def = legacy_code('initialize');
def.SFunctionName = 'dout_sfun';
def.OutputFcnSpec = 'void NO_OP(uint8 p1, uint8 u1)';
def.StartFcnSpec = 'void NO_OP(uint8 p1)';
legacy_code('sfcn_cmex_generate', def);
legacy_code('compile', def, '-DNO_OP=//')
def.SourceFiles = {fullfile(pwd,'..','src','digitalio_arduino.cpp')};
def.HeaderFiles = {'digitalio_arduino.h'};
def.IncPaths = {fullfile(pwd,'..','src'), 'C:\ProgramData\MATLAB\SupportPackages\R2021b\aIDE\libraries\Servo\src'};
def.OutputFcnSpec = 'void writeDigitalPin(uint8 p1, uint8 u1)';
def.StartFcnSpec = 'void digitalIOSetup(uint8 p1)';
legacy_code('sfcn_cmex_generate', def);
legacy_code('sfcn_tlc_generate', def);
legacy_code('rtwmakecfg_generate',def);
legacy_code('slblock_generate',def);
digitalio_arduino.cpp file
#include <Arduino.h>
#include <Servo.h>
#include "digitalio_arduino.h"
Servo myservo;
// Digital I/O initialization
extern "C" void digitalIOSetup(uint8_T pin)
{
//pinMode(pin, OUTPUT);
myservo.attach(pin);
}
// Write a logic value to pin
extern "C" void writeDigitalPin(uint8_T pin, uint8_T val)
{
//digitalWrite(pin, val);
myservo.write(val);
}
// [EOF]
digitalio_arduino.h file
#ifndef _DIGITALIO_ARDUINO_H_
#define _DIGITALIO_ARDUINO_H_
#include "rtwtypes.h"
#ifdef __cplusplus
extern "C" {
#endif
void digitalIOSetup(uint8_T pin);
void writeDigitalPin(uint8_T pin, uint8_T val);
#ifdef __cplusplus
}
#endif
#endif //_DIGITALIO_ARDUINO_H_

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by