Converting double into custom data type (eg int14)

조회 수: 4 (최근 30일)
Khalid Hersafril
Khalid Hersafril 2024년 1월 15일
댓글: Khalid Hersafril 2024년 3월 10일
I'm currently working on a library which will handle the DroneCAN transmission. However, one of the data types which is the uavcan.equipment.esc.RawCommand are using int14 data types which makes it a problem as most byte packs library and even natively, Simulink does not support int14. You can find the definition of this data type from here. I've also included the definition for the RawCommand below:
#
# Raw ESC command normalized into [-8192, 8191]; negative values indicate reverse rotation.
# The ESC should normalize the setpoint into its effective input range.
# Non-zero setpoint value below minimum should be interpreted as min valid setpoint for the given motor.
#
int14[<=20] cmd
I was wondering how should one go about this and try to get it working?
I am also fully aware that I could probably use the S-function, but I could not find much guidance on how I could possibly do this.
  댓글 수: 5
Oliver Reimer
Oliver Reimer 2024년 2월 13일
Do you plan to read in the DSDL definition files and generate the Matlab code for it, or do you want to implement them by hand?
Khalid Hersafril
Khalid Hersafril 2024년 3월 10일
I was planning to simply implement it by hand since it is a lot faster to achieve my end goal for now. I may need to use the former approach if needed in the future, but I dont see any reason in spending time on it now

댓글을 달려면 로그인하십시오.

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2024년 1월 20일
The embedded microcontroller or processing using the data can probably only work with 8-bit or 16-bit integers in doing calculations and storing in memory. There is no need to try to leave it in 14-bit format unless you need to send it back to the CAN network. So when you read this information from CAN, convert it all to 16-bit and perform calculations. Then convert it to 14-bit if you need to transmit it or store it.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by