Logical operators are used for logical operations on Boolean variables, constants, and simple logical expressions formed with the help of comparison operators.
Operators | Number of operands | illustrate |
NOT | 1 | reverse |
AND | 2 | Logical "AND" |
2 | Logical "OR" | |
EXOR | 2 | XOR |
The operands of a logic operation must be of type BOOL. The result is also always of type BOOL. The following table shows the possible results of the operation:
operate | NOT A | A AND B | A OR B | A EXOR B | |
A = TRUE | B = TRUE | FALSE | TRUE | TRUE | FALSE |
A = TRUE | B = FALSE | FALSE | FALSE | TRUE | TRUE |
A = FALSE | B = TRUE | TRUE | FALSE | TRUE | TRUE |
A = FALSE | B = FALSE | TRUE | FALSE | FALSE | FALSE |
This table also applies to operations performed with bitwise operators.
Example Even multiple operations are allowed.
...
DECL BOOL A,B,C
...
A=TRUE ;A=TRUE
B =NOTA ;B=FALSE
C = (A AND B)OR NOT (B EXORNOTA) ;C=TRUEA = NOTNOT C ;A=TRUE
...
Bitwise Operators
Bitwise operators operate on integers by performing logical operations on their individual bits in sequence. The result of the operation is equal to the result of the logical operator.
A bit value of 1 is equivalent to TRUE.
A bit value of 0 is equivalent to FALSE.
Operators | Number of operands | illustrate |
B_NOT | 1 | Bit Reversal |
B_AND | 2 | Bitwise AND |
B_OR | 2 | Bitwise OR operation |
B_EXOR | 2 | Bitwise XOR |
Bitwise operators can be applied to INT and CHAR data types.
INT has 32 bits in KRL and must be marked with a positive or negative sign. CAHR has 8 bits and does not need to be marked with a positive or negative sign.
The following examples of B_AND, B_OR, and B_EXOR with integer values result in a positive number (most significant bit = 0). As with unsigned values, the result can be converted directly to decimal.
28 leading zeros of an operand are represented by “00 [...]”.
B_AND
Example: Operation on integer values 5 and 12
B_OR
Example: Operation on integer values 5 and 12
B_EXOR
Example: Operation on integer values 5 and 12
B_NOT
For this integer example, the operation results in a negative number (highest value bit = 1). Therefore, the result cannot be converted to decimal in the same way as an unsigned number.
Example: B_NOT with integer value 10
In order for the user to understand the decimal result converted by the robot, he must know the rules for interpreting two's complement numbers. These rules are not the subject of this article.
The decimal result of a B_NOT operation with signed operands can be determined as follows:
1. Decimal value of the operand plus 1
2. Change the positive and negative signs
Other Examples
...
DECL INT A
...
A = 10B_AND9 ;A=8
A = 10B_OR 9 ;A=11
A = 10B_EXOR9 ;A=3
A = B_NOT 197 ; A = -198
A =B_NOT'HC5' ;A=-198
A =B_NOT'B11000101' ;A=-198
A =B_NOT "E" ;A=154
...
Setting and checking bits:
B_AND and B_OR can be used to specifically set individual bits of a bit sequence to 1 or 0. The remaining bits remain unchanged.
A single bit can be set to 0 using B_AND.
With B_OR, you can set a single bit to 1. In addition, you can check whether a single bit is 1 or 0. Example:
There is a digital output with a width of 8 bits. This output can be addressed via the INT variable DIG. Set bits 1, 2 and 6 to 0:
DIG = DIG B_AND 'B10111001' |
Set bits 0, 2, 3, and 7 to 1:
DIG = DIG B_OR 'B10001101' |
Checks whether bits 0 and 7 are set to 1. If so, my_result becomes TRUE:
DECL BOOL my_result
... my_result = DIG B_AND ('B10000001') > 0 |
Operator precedence
The precedence gives the order in which operators are executed within an instruction.
Priority | Operators |
1 | NOT; B_NOT |
2 | *; / |
3 | +; - |
4 | AND; B_AND |
5 | EXOR; B_EXOR |
6 | OR; B_OR |
7 | ==, <>; <, >, <=, >= |
In principle, the following applies:
Edit the enclosed expression first.
Unquoted expressions are parsed according to their precedence.
Operations performed with operators of the same precedence are analyzed from left to right.
Mathematical standard functions
Function | Numeric range independent variable | Numerical range results |
ABS(X)
Total |
REAL_MIN…REAL_MAX | 0 …REAL_MAX |
SQRT(X)
square root |
0 …REAL_MAX | 0 …REAL_MAX |
SIN(X)
Sine |
REAL_MIN…REAL_MAX | -1 …+1 |
COS(X)
cosine |
REAL_MIN…REAL_MAX | -1 …+1 |
TAN(X)
tangent |
REAL_MIN…REAL_MAX | REAL_MIN…REAL_MAX |
OS(X)
arccosine |
-1 … +1 | 0 …+180 |
ATAN2(Y,X)
inverse tangent |
REAL_MIN…REAL_MAX | -180 …+180 |
Data type of all functions: REAL. Data type of all independent variables: REAL.
Absolute value ABS(X) calculates the sum of X.
Example:
B = -3.4
A = 5*ABS(B); A=17.0
Square Root SQRT(X) Calculates the square root of X.
Example:
A = SQRT(16.0801) ;A=4.01
Sine SIN(X) Calculates the sine of angle X.
Example:
A = SIN(30) ;A=0,5
Cosine COS(X) Calculates the cosine of the angle X.
Example:
B = 2*COS(45) ;B=1.41421356
Tangent TAN(X) Calculates the tangent of an angle X.
Example:
The tangent of the following sum is infinite:
±90°
+90° + k*180° (where k = ± integer)
If such a value is attempted, this will result in an error message.
C = TAN(45) ;C=1.0
Arc Cosine ACOS(X) is the inverse function of COS(X).
Example:
A = COS(60) ;A=0.5
B = ACOS(A); B = 60
Inverse sine
There is no predefined function for the inverse function of SIN(X), the inverse cosine. However, the inverse sine can be easily calculated based on the formula SIN(X) = COS(90°-X).
Example:
A=SIN(60) ;A=0.8660254
B=90-ACOS(A) ;B=60 |
Inverse tangent
The tangent of an angle is defined as the adjacent side (X) of a right triangle divided by the opposite side (Y). If the lengths of the two sides are known, the inverse tangent can be used to calculate the angle between the adjacent side and the hypotenuse.
For a full circle, the decisive factor is the sign of X and Y. If only the quotient is considered, the inverse tangent can only be used to calculate angles between 0° and 180°. This is usually the case with pocket calculators.
Here: A positive value of the inverse tangent yields an angle between 0° and 90°. A negative value of the inverse tangent yields an angle between 90° and 180°.
By specifying the signs for Y and X, the quadrant that lies within this angle is determined explicitly. This also allows the calculation of angles within quadrants III and IV.
Example:
A=ATAN2(0.5,0.5) ;A=+45
B=ATAN2(0.5,-0.5) ;B=+135 C=ATAN2(-0.5,-0.5) ;C=-135 D=ATAN2(-0.5,0.5 ) ;D=-45 |
Using X and Y in the ATAN(Y,X) function
Review editor: Liu Qing
Previous article:What is a phonon laser? How can you make one using two ions?
Next article:Advantages and challenges of robots in injection molding processing
- Popular Resources
- Popular amplifiers
- Using IMU to enhance robot positioning: a fundamental technology for accurate navigation
- Researchers develop self-learning robot that can clean washbasins like humans
- Universal Robots launches UR AI Accelerator to inject new AI power into collaborative robots
- The first batch of national standards for embodied intelligence of humanoid robots were released: divided into 4 levels according to limb movement, upper limb operation, etc.
- New chapter in payload: Universal Robots’ new generation UR20 and UR30 have upgraded performance
- Humanoid robots drive the demand for frameless torque motors, and manufacturers are actively deploying
- MiR Launches New Fleet Management Software MiR Fleet Enterprise, Setting New Standards in Scalability and Cybersecurity for Autonomous Mobile Robots
- Nidec Drive Technology produces harmonic reducers for the first time in China, growing together with the Chinese robotics industry
- DC motor driver chip, low voltage, high current, single full-bridge driver - Ruimeng MS31211
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Comparison between fixed-point dsp and floating-point dsp
- Reliability Design of PCB Board for High-speed DSP System
- How to daisy chain 485
- Silergy SY5072 specification sheet help
- Please help me find out which movie the characters in the attached picture are from. Thank you.
- Renovation of old items + transformation of discarded charging heads into bathroom lighting
- How should I draw the various layers of the Allegro pad pins?
- MSP430 variant 3-wire SPI bus implementation (for DS1302 clock chip)
- EEWORLD University Hall----Overview of Operational Amplifier Technology
- Design of multifunctional air quality detection system based on Gizwits IoT platform