Coder ROS2 Build Error (colcon) with Custom ROS2 Message

17 visualizzazioni (ultimi 30 giorni)
I have a custom ROS2 message that am integrating into a Matlab function that is getting deployed on a remote Linux maching using Coder. During the 'colcon build' step of the Coder execution, I am getting the error:
error: cannot convert 'struct_T*' to 'const uavrt_interfaces_PulseStruct_T*'
82 | MATLABROS2Publisher_publish(pulsePub.PublisherHelper, &pulseMsg);
| ^~~~~~~~~
| |
| struct_T*
The rest of the terminal output after this is at the bottom of this message. My minimally functional Matlab function is below. The error is associated the C++ line of code that corresponds to the send(pulsePub,pulseMsg) line in my Matlab function. It seems to be upset about the type of pulseMsg, but that variable is defined as a ros2message earlier in my code. Below, I have also include the custom ROS2 message definition for Pulse.msg. I have also included the commands I use for using Coder. What is frustrating is that was working a few weeks ago and I can't seem to figure out what changed to cause colcon to error out.
MATLAB Function:
function [] = uavrt_detection_debug()
%#codegen
% ROS2 Setup
ros2Enable = true; %Hard coded switch so that can be ROS2 can be turned off for testing/debugging
if ros2Enable
fprintf("Preparing ROS2 Node and Messages...")
node = ros2node("detector",0);
pulsePub = ros2publisher(node,"/pulse","uavrt_interfaces/Pulse");
pulseMsg = ros2message(pulsePub);
fprintf("complete.\n")
end
pulseCount = 1;
ID = num2str(564321);
for i = 1:5
%Set pulseMsg parameters for sending
pulseMsg.detector_id = char(ID);
pulseMsg.frequency = 1;
pulseMsg.start_time.sec = int32(1);
pulseMsg.start_time.nanosec = uint32(1);
pulseMsg.end_time.sec = int32(1);
pulseMsg.end_time.nanosec = uint32(1);
pulseMsg.predict_next_start.sec = int32(1);
pulseMsg.predict_next_start.nanosec = uint32(1);
pulseMsg.predict_next_end.sec = int32(1);
pulseMsg.predict_next_end.nanosec = uint32(1);
pulseMsg.snr = 100;
pulseMsg.dft_real = 2;
pulseMsg.dft_imag = 3;
pulseMsg.group_ind = uint16(3);
pulseMsg.group_SNR = 123;
pulseMsg.detection_status = true;
pulseMsg.confirmed_status = false;
send(pulsePub,pulseMsg)
pulseCount = pulseCount+1;
pause(1);
fprintf('Transmitted a pulse...\n')
end
fprintf('Complete.\n')
end
The ROS2 Pulse.msg Definition:
# This is our custom message for pulses
string detector_id
float64 frequency
builtin_interfaces/Time start_time
builtin_interfaces/Time end_time
builtin_interfaces/Time predict_next_start
builtin_interfaces/Time predict_next_end
float64 snr
float64 snr_per_sample
float64 psd_sn
float64 psd_n
float64 dft_real
float64 dft_imag
uint16 group_ind
float64 group_snr
bool detection_status
bool confirmed_status
Code Generation Commands:
cfg = coder.config('exe');
cfg.Hardware = coder.hardware('Robot Operating System 2 (ROS 2)');
cfg.Hardware.BuildAction = 'Build and load';
cfg.Hardware.RemoteDeviceAddress = 'XXX.XXX.XXX.XXX'; % IP Address of target machine
cfg.Hardware.RemoteDeviceUsername = 'XXXXXXX'; % Login credentials of target machine
cfg.Hardware.RemoteDevicePassword = 'XXXXXXX';
cfg.Hardware.DeployTo = 'Remote Device';
cfg.Hardware.ROS2Folder = '/opt/ros/galactic';
cfg.Hardware.ROS2Workspace = '~/uavrt_ws';
cfg.HardwareImplementation.ProdHWDeviceType = 'Intel->x86-64 (Linux 64)';
cfg.RuntimeChecks = true;%Disable for final deployments.
codegen uavrt_detection_debug -args {} -config cfg
The error is that shows up in the Matlab Terminal:
/home/dasl/uavrt_ws/src/uavrt_detection_debug/src/uavrt_detection_debug.cpp:82:59: error: cannot convert 'struct_T*' to 'const uavrt_interfaces_PulseStruct_T*'
82 | MATLABROS2Publisher_publish(pulsePub.PublisherHelper, &pulseMsg);
| ^~~~~~~~~
| |
| struct_T*
/home/dasl/uavrt_ws/src/uavrt_detection_debug/include/uavrt_detection_debug/mlros2_pub.h:15:65: note: in definition of macro 'MATLABROS2Publisher_publish'
15 | #define MATLABROS2Publisher_publish(obj,structPtr) obj->publish(structPtr)
| ^~~~~~~~~
/home/dasl/uavrt_ws/src/uavrt_detection_debug/include/uavrt_detection_debug/mlros2_pub.h:50:37: note: initializing argument 1 of 'void MATLABROS2Publisher<MsgType, StructType>::publish(const StructType*) [with MsgType = uavrt_interfaces::msg::Pulse_<std::allocator<void> >; StructType = uavrt_interfaces_PulseStruct_T]'
50 | void publish(const StructType *msgStructPtr) {
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
make[2]: *** [CMakeFiles/uavrt_detection_debug.dir/build.make:144: CMakeFiles/uavrt_detection_debug.dir/src/uavrt_detection_debug.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:81: CMakeFiles/uavrt_detection_debug.dir/all] Error 2
make: *** [Makefile:144: all] Error 2
---
Failed <<< uavrt_detection_debug [8.34s, exited with code 2]
Summary: 1 package finished [10.4s]
1 package failed: uavrt_detection_debug
1 package had stderr output: uavrt_detection_debug
??? The following error occurred during deployment to your hardware board:
Build unsuccessful for model 'uavrt_detection_debug'. Check the build log in the diagnostics viewer for error
messages.

Risposta accettata

Karthik Reddy Vennapureddy
Modificato: Karthik Reddy Vennapureddy il 26 Ott 2022
Hi Michael,
Thank you for providing the custom message definition and necessary scripts to reproduce the issue. I have investigated this and found that there is issue in MATLAB Function: uavrt_detection_debug(). Please change the following line
pulseMsg.group_SNR = 123;
to
pulseMsg.group_snr = 123;
As ros2message is a MATLAB struct, it just appends any new field (group_SNR) to existing struct containing a field (group_snr) and uses the default values. Here, in the custom message definition, there is field group_snr but no such field group_SNR, which is the root cause leading to the build failure.
Let us know, if you still face issues after doing the suggested change.
Thanks,
Karthik Reddy
  8 Commenti
Michael
Michael il 30 Gen 2023
@Karthik Reddy Vennapureddy Any update on why this might still be happening on R2022b when it was supposed to be fixed in R2022a? Thanks.
Karthik Reddy Vennapureddy
Modificato: Karthik Reddy Vennapureddy il 30 Gen 2023
Hi Michael,
This issue is addressed as part of R2022b_update4 and R2022a_update3. Could you please update your MATLAB R2022b to update4. Note that, this fix is available in R2023a as well.
Thanks,
Karthik Reddy

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by