Closed afr2903 closed 1 month ago
Inside the teleop.ino
script, developments were made to receive the complete position and a prefix identifier to tell the ESP which gripper finger to send values.
The scripts udp-test.ino
and servo-test.ino
were used as a base for this functionality. Also, both gripper names were refactored from big
and small
to board
and wire
.
The packet to be received should follow this structure:
identifier + position
Being the possible identifiers:
b
- Boardw
- WireAnd the position
should be an integer.
The following implementation was made to check the identifier received and save it to a flag:
bool board_requested = false;
if (len > 0){
if(incomingPacket[0] == 'b')
board_requested = true;
The iteration for the incoming packages begins now at index 1
and the remaining characters are appended to a string that would be later converted to an integer target_position
. Finally the flag is reviewed and the position is set:
if (board_requested){
board_gripper.write(target_pos);
} else {
wire_gripper.write(target_pos);
}
Based on this script previously used, two sliders were created to manipulate the fingers positions of the gripper.
Once the sliders' position is updated, it will call a function to send the values to the ESP via socket
:
def send_data(position, board_gripper= False):
"""Send the data to the ESP32 via socket"""
data = str(position)
if board_gripper:
data = 'b' + data
else:
data = 'w' + data
print(f"Sending instruction: {data}")
sock.sendto(data.encode(), (UDP_IP, UDP_PORT))
time.sleep(0.1)
To install tkinter
I had to execute:
sudo apt-get install python3-tk
As this feature is working great and sending int
positions work, this should be refactored and used as the main ESP execution, and manage all the predefined positions from the Python code to avoid uploading code constantly to define the static positions.
Warning: My phone restarted and its automatic IP gateway changed from 192.168.18.x
to 192.168.34.x
, so I had to upload new code in the ESP.
The initial idea was to predefine all the required gripper fingers' positions and then don't move those values anymore.
However, the gripper is not mechanically stable, so there should be an easier way of changing those states, something like a teleop controller.
The idea now would be to develop this teleoperation control with Python, and send instead of just number, positions of the fingers via
UDP
, and even more so, control these positions with sliders in Python would be an amazing feature.