Quick Start

What Programming Tool Do You Use?

Robotic Hand Python Start Guide

NOTE: For more guidance about other environments, please ask our agent to provide it.

0 Receive Package from Us

To receive your complete package, please contact our service team.

1 Preparation

Note:

  • Recommended use Python 3.8 – 3.11

For Windows10/11

cd python

# Install Python dependencies
pip3 install -r requirements.txt  

For MacOS 10.15 +

# install sdk dependencies
./download-lib.sh

cd python
# install python dependencies
pip3 install -r requirements.txt 

For Ubuntu 20/22

# install sdk dependencies
./download-lib.sh

cd python

# install python dependencies
pip3 install -r requirements.txt

# Note:Users must be added to the "dialout" group to gain access over serial port device.
# If you haven't set, use the following command then restart your computer:
sudo usermod -aG dialout $USER 

2.1 Hand Control

Key info:

  • Control the hand by using action_sequences.
  • Remember to change the serial port
#!/usr/bin/env python
import os
import asyncio
from modbus_client_utils import *

filename = os.path.basename(__file__).split(".")[0]
StarkSDK.init(isModbus=True, log_level=logging.INFO, log_file_name=f"{filename}.log")

# Add the serial port info
serial_port_name = "Change_it_to_right_port" 



# Control the hand by using Action sequence
sample_action_sequences = [
    {
        "index": 0,
        "duration_ms": 2000,
        "positions": [0, 0, 100, 100, 100, 100],
        "speeds": [10, 20, 30, 40, 50, 60],
        "forces": [5, 10, 15, 20, 25, 30],
    },
    {
        "index": 1,
        "duration_ms": 2000,
        "positions": [100, 100, 0, 0, 0, 0],
        "speeds": [15, 25, 35, 45, 55, 65],
        "forces": [6, 11, 16, 21, 26, 31],
    },
    {
        "index": 2,
        "duration_ms": 2000,
        "positions": [0, 0, 100, 100, 100, 100],
        "speeds": [10, 20, 30, 40, 50, 60],
        "forces": [5, 10, 15, 20, 25, 30],
    },
]


def action_sequence_info_to_list(action):
    return (
        [action["index"]]
        + [action["duration_ms"]]
        + action["positions"]
        + action["speeds"]
        + action["forces"]
    )
    
    
async def main():

    #==============Initialization Preparation==============
    
    setup_shutdown_event()
    StarkSDK.set_error_callback(lambda error: SKLog.error(f"Error: {error.message}"))

    ports = serial_ports()
    SKLog.info(f"serial_ports: {ports}")
    if len(ports) == 0:
        SKLog.error("No serial ports found")
        return

    client = client_connect(port=serial_port_name, baudrate=BaudRate.baudrate_115200)
    if client is None:
        SKLog.error("Failed to open modbus serial port")
        return

    broadcast_enable = False
    # default slave_id is 1 in Modbus Firmware
    slave_id = 0 if broadcast_enable else 1

    # new modbus device instance
    device = StarkDevice.create_device(slave_id, f"{serial_port_name}_{slave_id}")

    # set modbus device write/read registers callbacks
    device.set_write_registers_callback(
        lambda register_address, values: client_write_registers(
            client, register_address, values=values, slave=slave_id
        )
    )
    device.set_read_holding_registers_callback(
        lambda register_address, count: client_read_holding_registers(
            client, register_address, count, slave=slave_id
        )
    )
    device.set_read_input_registers_callback(
        lambda register_address, count: client_read_input_registers(
            client, register_address, count, slave=slave_id
        )
    )

    global sample_action_sequences
    SKLog.info(f"Action Sequence: {len(sample_action_sequences)}")
    for action in sample_action_sequences:
        print(f"{action},")

    #==============Initialization Preparation Finished==============
    
    # organize data format
    # fmt: off
    mapped_sequences = map(lambda action: action_sequence_info_to_list(action), sample_action_sequences)
    action_sequences = list(mapped_sequences)
    
    
    # write action sequence to hand
    action_id = ActionSequenceId.custom_gesture_1
    device.transfer_action_sequence(action_id, action_sequences=action_sequences)
    # save action sequence on hand
    device.save_action_sequence(action_id)

    # read action sequence
    device.get_action_sequence(action_id,cb=lambda action_sequences: SKLog.info(f"get Action Sequence: {action_sequences}"))
    # run action sequence
    device.run_action_sequence(action_id)

    # waiting for the event to close
    # await shutdown_event.wait()

    # close client
    client_close(client)
    SKLog.info("Modbus client closed")
    sys.exit(0)


if __name__ == "__main__":
    asyncio.run(main()) 

2.2 Get Device Information

#!/usr/bin/env python
import os
import asyncio
from modbus_client_utils import *

filename = os.path.basename(__file__).split(".")[0]
StarkSDK.init(isModbus=True, log_level=logging.INFO, log_file_name=f"{filename}.log")


# add the serial port info
serial_port_name = "Change_it_to_right_port" 


async def main():

    #==============Initialization Preparation==============
    
    setup_shutdown_event()
    StarkSDK.set_error_callback(lambda error: SKLog.error(f"Error: {error.message}"))

    ports = serial_ports()
    SKLog.info(f"serial_ports: {ports}")
    if len(ports) == 0:
        SKLog.error("No serial ports found")
        return

    client = client_connect(port=serial_port_name, baudrate=BaudRate.baudrate_115200)
    if client is None:
        SKLog.error("Failed to open modbus serial port")
        return

    broadcast_enable = False
    # default slave_id is 1 in Modbus Firmware
    slave_id = 0 if broadcast_enable else 1

    # new modbus device instance
    device = StarkDevice.create_device(slave_id, f"{serial_port_name}_{slave_id}")

    # set modbus device write/read registers callbacks
    device.set_write_registers_callback(
        lambda register_address, values: client_write_registers(
            client, register_address, values=values, slave=slave_id
        )
    )
    device.set_read_holding_registers_callback(
        lambda register_address, count: client_read_holding_registers(
            client, register_address, count, slave=slave_id
        )
    )
    device.set_read_input_registers_callback(
        lambda register_address, count: client_read_input_registers(
            client, register_address, count, slave=slave_id
        )
    )
    #==============Initialization Preparation Finished==============
    
    
    #==============The following is the sample code for obtaining ==============

    # Get the hand type
    SKLog.info("get_hand_type") 
    device.get_hand_type(lambda hand_type: SKLog.info(f"Hand type: {hand_type.name}"))

    # Get serial port configuration, baud rate, etc.
    SKLog.info("get_serialport_cfg") 
    device.get_serialport_cfg(lambda cfg: SKLog.info(f"Serialport cfg: {cfg}"))

    # Get firmware version number and other informationSKLog.info("get_motorboard_info") 
    device.get_motorboard_info(lambda info: SKLog.critical(f"Motorboard info: {info}"))

    # Get force level, large-medium-small
    SKLog.info("get_force_level") 
    device.get_force_level(
    lambda force_level: SKLog.info(f"Force level: {force_level.name}")
    )

    # Get power
    SKLog.info("get_voltage") 
    device.get_voltage(lambda voltage: SKLog.info(f"Voltage: {voltage:.1f} mV"))

    # Set finger position
    device.set_finger_positions([60, 60, 100, 100, 100, 100]) 

    # Get finger status
    SKLog.info("get_finger_status") 
    device.get_finger_status(lambda status: SKLog.info(f"Finger status: {status}"))

    #==============The following is to get the tactile hand status ==============
    # SKLog.info("get_touch_sensor_status") # Get the tactile sensor status
    # device.get_touch_sensor_status(
    # lambda status: SKLog.info(f"Touch sensor status: {status}")
    # )


    # Close client
    client_close(client)
    SKLog.info("Modbus client closed")
    sys.exit(0)


if __name__ == "__main__":
    asyncio.run(main()) 

Need More Info?

Contact us for more details and help from our service team

请在浏览器中启用JavaScript来完成此表单。