Need to check input between range and convert it if not

2 Ansichten (letzte 30 Tage)
The following subsystem is an error function for a robot which moves in a 2D spaces. So the error is based on the euclidean distance and the orientation error, theta. What I need to do is to check whether theta input is between two values (-pi, pi) and convert it to be in the specified range. For example, 2pi would be a whole circle but since we work on -pi, pi, it would be the same as 0, 3pi would be pi, 3pi/2 would be -pi/2 and so on, This is the subsystem, i have not found any block that could do this so specifying the range in the theta properties as -pi pi is as far as i've gotten.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 28 Okt. 2022
Bearbeitet: Fangjun Jiang am 28 Okt. 2022
The best way is to make sure theta is within [-pi, pi]. All trigonometry functions in MATLAB/Simulink has a defined output range. You may just need to add an offset.
If theta is an input and out of your control, you can use the mod(theta, 2*pi) function. It will gave you the output range of [0,2*pi), you will then add an offset to it.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by