THE ANNIN ROBOTICS FORUM HAS MOVED TO A NEW COMMUNITY. 👉
Python Programming
 
Notifications
Clear all

Python Programming

2 Posts
1 Users
0 Reactions
70 Views
Avatar of snibnib
(@snibnib)
New Member
Joined: 3 months ago
Posts: 2
Topic starter  

Hello everyone, First off, congratulations on the project. I am currently trying to program the AR4 arm with Python, I read that we can control it over serial commands so I am generating those commands with the AR4 Software and "mapping" them to Python functions.

I am having a problem with the gripper though, my code looks like this:

def send_command(command, board):
    """Send a command to the specified board and wait for a response."""
    if board == "teensy":
        ser = teensy_ser
    elif board == "arduino":
        ser = arduino_ser
    ser.write((command + '\n').encode())  # Ensure the command ends with a newline character
    print(f"Sent command {command}")
    response = ""
    start_time = time.time()
    while response == "":
        response = ser.readline().decode('utf-8').strip()
        if time.time() - start_time > 60:  # Timeout after 10 seconds
            raise TimeoutError("No response from robot arm within the expected time frame.") 
    return response
def open_grip():
    command = "ONX8"
    board = "arduino"
    response = send_command(command, board)
    if response:  # Check if a valid response is received
        print("OK")
    else:
        print(f"No response or invalid response from {board}, retrying...")

def close_grip():
    command = "OFX8"
    board = "arduino"
    response = send_command(command, board)
    if response:  # Check if a valid response is received
        print("OK")
    else:
        print(f"No response or invalid response from {board}, retrying...")
 

The close_grip command makes the grip open and close fast but obviously that is not what is wanted, open_grip doesnt really react. I dont understand what is the issue here. Could anyone help? Thank you



   
Quote
Avatar of snibnib
(@snibnib)
New Member
Joined: 3 months ago
Posts: 2
Topic starter  

Problem fixed, what was happening was that, when first establishing communication, the servo somehow resets and does not accept any commands in the first 3 seconds, then I used SV0P180 to open the grip and SV0P0 to close the grip.



   
ReplyQuote
Share:
Upload your Photo