# Design and Calibration of a Sensory System of an Adaptive Gripper
## 3 Results
### Calibrating the Slip Sensor  
In this case, it is also necessary to calibrate the slip sensor for each gripping module. To calibrate the slip sensor, the following steps were necessary:  
1. Development of software for determining angular values  
To determine angular values, dedicated software (Figure 23) was developed for testing, which was installed for each gripping module. The meaning of the main instructions in this software is as follows:  
* setup() function:  
pinMode(channelA, INPUT);  
Figure 23: Software for testing angular variation. pinMode(channelB, INPUT);  
These lines configure the digital pins channelA and channelB as digital inputs. These are the pins to which the two channels of the encoder are connected. attachInterrupt(digitalPinToInterrupt(channelA), updateEncoder, CHANGE);  
attachInterrupt(digitalPinToInterrupt(channelB), updateEncoder, CHANGE);  
These lines attach interrupts to the channelA and channelB pins. digitalPinToInterrupt() converts the pin number into an interrupt identification number. attachInterrupt() sets a function (updateEncoder) that will be called every time the pin state changes (CHANGE). This allows for very fast and accurate detection of encoder state changes, without the need for constant checking in the loop() loop. - loop() function:  
Serial.print(\"Position: \");  
Serial.printIn(position);  
delay(100);  
This main loop displays the current value of the variable position, which represents the encoder position, on the serial monitor. delay(100) introduces a 100-millisecond pause between displays. - updateEncoder() function:  
This is the function that is called each time the state of the channelA or channelB pin changes. int MSB = digitalRead(channelA);  
int LSB = digitalRead(channelB);  
These lines read the state of each encoder pin (0 or 1) and store them in the variables MSB (Most Significant Bit) and LSB (Least Significant Bit). int encoded = (MSB << 1) | LSB;  
This line combines the two bits into a single integer (encoded). << 1 is a bit shift to the left, which moves the MSB bit to the top position. | is a bitwise OR operation, which combines the MSB and LSB bits. int sum = (lastEncoded << 2) | encoded;  
This line combines the current encoded value with the previous value (lastEncoded). Shifting left by 2 bits (<<2) moves the previous value two places so that it can be combined with the current value. if (sum == 0b1101 | | sum == 0b0100 | | sum == 0b0010 | | sum == 0b1011) position++;  
if (sum == 0b1110 | | sum == 0b0111 | | sum == 0b0001 | | sum == 0b1000) position--;  
These lines detect the direction of rotation of the encoder. They compare the sum value with different combinations of bits that correspond to increasing or decreasing the position. These combinations are determined by the specific sequence of signals generated by the encoder. lastEncoded = encoded;  
This line stores the current encoded value for use on the next interrupt. II. Implementation and collection of read values  
The software takes readings at a rate of 10/second to have a much higher accuracy of angular displacement measurement. The slip sensor is folded into the logical flow of the system and will be measured in the steps made in the logic diagram. To integrate the slip sensor into the sensor system, it is essential to collect data in various phases of the gripping process:  
Sequence 1 (Initial Error): The background noise of the optical encoder is evaluated before contact with the object. Tables 2-6 present the error values for each module, over a one-second interval. These errors represent variations in the encoder readings in the absence of movement, probably caused by electronic noise or small vibrations.