Skip to content

Commit a8b96f4

Browse files
committed
tools: add odometry calibration tool
- Orchestrate calibration via Socket.IO connection to cogip-server - Coordinate firmware operations through FirmwareAdapter - Provide interactive user interface via ConsoleUI - Include calculation engine for odometry parameter tuning
1 parent ed6f8aa commit a8b96f4

File tree

10 files changed

+1311
-0
lines changed

10 files changed

+1311
-0
lines changed

cogip/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@
2323
ShellMenu,
2424
Vertex,
2525
)
26+
from .odometry_calibration import ( # noqa
27+
CalibrationResult,
28+
CalibrationState,
29+
EncoderDeltas,
30+
OdometryParameters,
31+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Odometry Calibration Models
3+
4+
Pydantic models for odometry calibration data.
5+
"""
6+
7+
from pydantic import BaseModel
8+
9+
10+
class CalibrationResult(BaseModel):
11+
"""Result of a calibration computation."""
12+
13+
wheels_distance: float
14+
right_wheel_radius: float
15+
left_wheel_radius: float
16+
17+
18+
class CalibrationState(BaseModel):
19+
"""
20+
State container for calibration intermediate values.
21+
22+
Tracks alpha and beta coefficients computed during calibration phases.
23+
"""
24+
25+
alpha_l: float = 0.0
26+
alpha_r: float = 0.0
27+
beta: float = 0.0
28+
29+
30+
class EncoderDeltas(BaseModel):
31+
"""Encoder tick deltas captured during a motion sequence."""
32+
33+
left: int
34+
right: int
35+
36+
37+
class OdometryParameters(BaseModel):
38+
"""
39+
Container for odometry parameters.
40+
41+
Holds all parameters needed for odometry calibration.
42+
"""
43+
44+
wheels_distance: float = 0.0
45+
right_wheel_radius: float = 0.0
46+
left_wheel_radius: float = 0.0
47+
left_polarity: float = 0.0
48+
right_polarity: float = 0.0
49+
encoder_ticks: float = 0.0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logging
2+
3+
from cogip.utils.logger import Logger
4+
5+
logger = Logger("cogip-odometry-calibration", level=logging.WARNING)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CLI entry point for the Odometry Calibration tool.
4+
5+
Provides a command-line interface to calibrate robot odometry parameters
6+
by communicating with the firmware via SocketIO through cogip-server.
7+
"""
8+
9+
from __future__ import annotations
10+
import asyncio
11+
import logging
12+
from pathlib import Path
13+
from typing import Annotated
14+
15+
import typer
16+
import yaml
17+
18+
from cogip.models import FirmwareParametersGroup
19+
from cogip.tools.firmware_odometry_calibration import logger
20+
from cogip.tools.firmware_odometry_calibration.odometry_calibration import OdometryCalibration
21+
22+
23+
def main_opt(
24+
*,
25+
server_url: Annotated[
26+
str | None,
27+
typer.Option(
28+
"-s",
29+
"--server-url",
30+
help="cogip-server URL",
31+
envvar="COGIP_SOCKETIO_SERVER_URL",
32+
),
33+
] = None,
34+
robot_id: Annotated[
35+
int,
36+
typer.Option(
37+
"-i",
38+
"--id",
39+
min=1,
40+
help="Robot ID.",
41+
envvar=["ROBOT_ID"],
42+
),
43+
] = 1,
44+
debug: Annotated[
45+
bool,
46+
typer.Option(
47+
"-d",
48+
"--debug",
49+
help="Turn on debug messages",
50+
envvar="CALIBRATION_DEBUG",
51+
),
52+
] = False,
53+
):
54+
if debug:
55+
logger.setLevel(logging.DEBUG)
56+
57+
if not server_url:
58+
server_url = f"http://localhost:809{robot_id}"
59+
60+
# Load bundled parameters definition YAML
61+
params_path = Path(__file__).with_name("odometry_parameters.yaml")
62+
parameters_data = yaml.safe_load(params_path.read_text())
63+
64+
parameters_group = FirmwareParametersGroup.model_validate(parameters_data["parameters"])
65+
66+
# Run calibration
67+
calibration = OdometryCalibration(server_url, parameters_group)
68+
asyncio.run(calibration.run())
69+
70+
71+
def main():
72+
"""
73+
Run odometry calibration tool.
74+
75+
During installation of cogip-tools, `setuptools` is configured
76+
to create the `cogip-odometry-calibration` script using this function as entrypoint.
77+
"""
78+
typer.run(main_opt)
79+
80+
81+
if __name__ == "__main__":
82+
main()

0 commit comments

Comments
 (0)