How to solve this warning: This property will be converted to datatype "double" in the Simulink bus.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm a new bee to Simulink and ROS2. When I followed the tutorial to study ROS2 Custom Message Support, I changed the data type of "int_property" from "uint32" to "uint64". Then I genmsg from this example. I haven't had any problems until here.
Then I try to use this custom message in Simulink. I open ros2GetStartedExample.slx, change the Blank Message from "geometry_msgs/Point" to "example_b_msgs/Standalone" and fix some compile bug. Finally, I simplified the model like this.
Then I got this warning.
warning: The property "int_property" in ROS message type "example_b_msgs/Standalone" has an unsupported datatype (uint64). This property
will be converted to datatype "double" in the Simulink bus.
So, how can I prevent Simulink to do this convertion? I find this convertion is type cast in generated C++ code, which may cause loss of accuracy like this.
c++ code:
#include<iostream>
using namespace std;
int main(){
uint64_t test1 = 1311768467463790329;
double test2 = (double)test1;
uint64_t test3 = (uint64_t)test2;
cout << test1 << endl;
cout << test2 << endl;
cout << test3 << endl;
return 0;
}
$ g++ test.cpp -std=c++11 -o test
$ ./test
1311768467463790329
1.31177e+18
1311768467463790336
matlab comand:
>> uint64(1311768467463790329)
ans =
uint64
1311768467463790329
>> uint64(double(uint64(1311768467463790329)))
ans =
uint64
1311768467463790336
1 Kommentar
Antworten (1)
Josh Chen
am 3 Jun. 2024
Hi An and Zheng,
This auto conversion from int64 to double is to align with standard Simuilnk datatype by default. To avoid such conversion, you would need to do the following two steps before generating the code:
1. Use the following command to enable 'Int64' mode for Simulink Buses:
>> ros.slros.internal.bus.Util.setInt64SLBusMode(<model_name>,true)
2. Navigate to 'Hardware Implementation' and check 'Support long long':
Hope this helps,
Thanks.
Josh
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!