Skip to main content

Servo Control Tuning Tool for Real and Simulated Actuators. Utilizes Kscale KOS and KOS-SIM

Project description

ktune - Sim2Real Toolkit

ktune is a command-line utility for actuator tuning and simulation-to-reality (Sim2Real) validation. It enables running standardized motion tests (sine, step, chirp) simultaneously in simulation and hardware, providing quantitative comparison for actuator dynamics and control performance.

Features

  • Tuning Tests:
    • Sine Test: Commands an actuator with a sine waveform.
    • Step Test: Performs step-response analysis.
    • Chirp Test: Executes frequency-swept chirp tests.
  • System Identification (SysID):
    • Conduct detailed system identification experiments, including pendulum-based tests, to characterize motor and actuator dynamics.
  • Flexible Configuration:
    • YAML-based configurations for complex experiments.
    • Advanced CLI using the click library for easy parameter setting and overrides.
  • Integrated Data Logging:
    • Automated data logging and plotting for quick visual assessment and comparison between simulations and real-world tests.
  • Servo Management:
    • Easily enable or disable specific servos directly via CLI commands.

Installation

pip install ktune

Ensure the pykos library is also installed and configured for your hardware.

Usage

General CLI Usage

ktune --help

Running Tests

ktune supports three modes of operation:

  • real: Run tests on real hardware only
  • sim: Run tests in simulation only
  • compare: Run tests simultaneously on both real hardware and simulation

Each mode supports three types of tests:

  • Sine wave tests
  • Step response tests
  • Chirp (frequency sweep) tests

Connection Parameters

ktune works with both real hardware (via KOS) and simulation (via KOS-SIM):

  • Real Hardware (KOS):

    • Default IP: 192.168.42.1
    • Use --real-ip to specify a different address
    • Typically used when connected to physical robot's network
  • Simulation (KOS-SIM):

    • Default IP: 127.0.0.1 (localhost)
    • Use --sim-ip to specify a different address
    • Requires running kos-sim instance

Real Hardware Examples

# Default connection (192.168.42.1)
ktune real sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0
ktune real step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2
ktune real chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 --chirp-duration 5.0

# Custom IP address
ktune real sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 --real-ip 192.168.1.100
ktune real step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 --real-ip 192.168.1.100
ktune real chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 --real-ip 192.168.1.100

# With control parameters
ktune real sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 \
    --kp 20.0 --kd 5.0 --ki 0.0 --max-torque 50.0

ktune real step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 \
    --kp 20.0 --kd 5.0 --ki 0.0 --max-torque 50.0

ktune real chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 \
    --kp 20.0 --kd 5.0 --ki 0.0 --max-torque 50.0

Simulation Examples

# Default connection (localhost)
ktune sim sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0
ktune sim step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2
ktune sim chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5

# Custom simulator IP
ktune sim sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 --sim-ip 192.168.1.50
ktune sim step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 --sim-ip 192.168.1.50
ktune sim chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 --sim-ip 192.168.1.50

# With simulation-specific parameters
ktune sim sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0

ktune sim step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0

ktune sim chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0

Comparison Examples

# Default connections
ktune compare sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0
ktune compare step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2
ktune compare chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5

# Custom IPs for both real and simulation
ktune compare sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50

ktune compare step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50

ktune compare chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50

# Full configuration example
ktune compare sine --actuator-id 11 --freq 1.0 --amp 5.0 --duration 5.0 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50 \
    --kp 20.0 --kd 5.0 --ki 0.0 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0 \
    --max-torque 50.0 --sample-rate 100.0

ktune compare step --actuator-id 11 --step-size 10.0 --step-hold-time 3.0 --step-count 2 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50 \
    --kp 20.0 --kd 5.0 --ki 0.0 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0 \
    --max-torque 50.0 --sample-rate 100.0

ktune compare chirp --actuator-id 11 --chirp-amp 5.0 --chirp-init-freq 1.0 --chirp-sweep-rate 0.5 \
    --real-ip 192.168.1.100 --sim-ip 192.168.1.50 \
    --kp 20.0 --kd 5.0 --ki 0.0 \
    --sim-kp 20.0 --sim-kd 5.0 --stream-delay 0.0 \
    --max-torque 50.0 --sample-rate 100.0

Common Options

All test commands support these common options:

  • --actuator-id: ID of the actuator to test (default: 11)
  • --start-pos: Starting position in degrees (default: 0.0)
  • --kp: Proportional gain (default: 20.0)
  • --kd: Derivative gain (default: 5.0)
  • --ki: Integral gain (default: 0.0)
  • --max-torque: Maximum torque limit (default: 100.0)
  • --acceleration: Acceleration limit in deg/s² (default: 0.0)
  • --sample-rate: Data collection rate in Hz (default: 100.0)

Servo Configuration

Enable servos 11, 12, 13:

ktune tune --enable-servos 11,12,13

Disable servos 31, 32, 33:

ktune tune --disable-servos 31,32,33

System Identification (SysID)

Perform SysID experiments with detailed pendulum setups defined through YAML configurations or CLI parameters.

Pendulum SysID Example

Run a pendulum system identification test with specific parameters:

ktune sysid pendulum --mass 0.535 --length 0.150 --trajectory lift_and_drop --kp 32

YAML-based SysID Configuration

Define complex system identification experiments in YAML files:

sysid:
  actuator_id: 11
  motor_name: "sts3215v12"
  ip: "192.168.42.1"
  mass: 0.535
  arm_mass: 0.036
  length: 0.150
  error_gain: 0.16489
  winding_resistance: 1.0
  torque_constant: 1.0787
  repetitions: 4
  kp_values: [4, 8, 12, 16, 24, 32]
  trajectories: 
    - "lift_and_drop"
    - "sin_sin"
    - "up_and_down"
    - "sin_time_square"
    - "brutal"

Run the experiment based on the YAML configuration:

ktune sysid pendulum --config path/to/pendulum_config.yaml

Command Line Reference

  • General Settings:

    • --sim-ip, --real-ip, --actuator-id, --start-pos
  • Tuning Tests:

    • Sine: --freq, --amp, --duration
    • Step: --size, --hold-time, --count
    • Chirp: --amp, --init-freq, --sweep-rate, --duration
  • Actuator Configuration:

    • Gains: --kp, --kd, --ki
    • Torque and Acceleration Limits: --max-torque, --acceleration, --torque-off
  • Simulation Configuration:

    • --sim-kp, --sim-kv
  • Data Logging Options:

    • --no-log, --log-duration-pad, --sample-rate
  • Servo Management:

    • --enable-servos, --disable-servos

Data Logging

Data and plots are saved automatically to the logs/ and plots/ directories, respectively, with timestamps for easy tracking.

Acknowledgements

Special thanks to Rhoban and their Better Actuator Model paper for valuable insights and contributions to actuator modeling and tuning methodologies.

License

MIT License

Contributing

Your contributions, feature requests, and bug reports are welcome! Please open issues or submit pull requests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ktune-0.2.4.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ktune-0.2.4-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file ktune-0.2.4.tar.gz.

File metadata

  • Download URL: ktune-0.2.4.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ktune-0.2.4.tar.gz
Algorithm Hash digest
SHA256 971d49a0790557254c7ed59c3cfc266e856c526f3a4b15442282b13569c77ee9
MD5 577fddb5d561b7e3174914077226df5c
BLAKE2b-256 86d99fb87115f4a21fbfca5f4fddf7da4e928c2f07675e7fb789d4ba7dd5a1b9

See more details on using hashes here.

File details

Details for the file ktune-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: ktune-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ktune-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 17cf48b74994bdcebb988151c706d82ed2fa08bd595029da62fe940a5ec3f118
MD5 09bd3c8bbb9f19ce210af8b6601a578d
BLAKE2b-256 e50bf0f7926d262951403aba7337dc6816759f75142ebbf590d6a6afa2a09688

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page