|
|
@@ -15,6 +15,20 @@ from jsonschema import Draft202012Validator
|
|
|
PROFILE = "prod2u-normal-multiproject-115200-v1"
|
|
|
SCHEMA_PATH = Path(__file__).resolve().parents[1] / "schemas" / "project.schema.json"
|
|
|
SOURCE_CLOSURE_PATH = Path(__file__).resolve().parents[1] / "config" / "source_closure.json"
|
|
|
+CAL_COUNTER_WIDTH_BITS = 13
|
|
|
+CAL_COUNTER_MAX = (1 << CAL_COUNTER_WIDTH_BITS) - 1
|
|
|
+FORBIDDEN_MOTOR_KEYS = {
|
|
|
+ "fixed_steps",
|
|
|
+ "busy_wait_ms",
|
|
|
+ "command_values",
|
|
|
+ "heartbeat_value",
|
|
|
+}
|
|
|
+FORBIDDEN_STARTUP_KEYS = {
|
|
|
+ "backoff_step_count",
|
|
|
+ "close_step_count",
|
|
|
+ "direction_value",
|
|
|
+ "direction_meaning",
|
|
|
+}
|
|
|
|
|
|
_TOP_LEVEL_KEYS = {
|
|
|
"project_id",
|
|
|
@@ -202,23 +216,22 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_require(door_axes == ["x", "y", "z"], "door_axes must be x,y,z")
|
|
|
|
|
|
motors = _object(payload["motors"], "motors")
|
|
|
+ forbidden_motor = FORBIDDEN_MOTOR_KEYS & set(motors)
|
|
|
+ _require(not forbidden_motor, f"obsolete motors keys present: {sorted(forbidden_motor)}")
|
|
|
_keys(
|
|
|
motors,
|
|
|
{
|
|
|
"count",
|
|
|
"order",
|
|
|
"role",
|
|
|
- "fixed_steps",
|
|
|
"execution",
|
|
|
- "busy_wait_ms",
|
|
|
"step_rate_hz",
|
|
|
"step_half_cycles",
|
|
|
"dir_setup_cycles",
|
|
|
- "command_values",
|
|
|
- "heartbeat_value",
|
|
|
"open_dir_value",
|
|
|
"close_dir_value",
|
|
|
"dir_close_level",
|
|
|
+ "positioning",
|
|
|
"mapping",
|
|
|
"enable_n",
|
|
|
},
|
|
|
@@ -227,14 +240,13 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_integer(motors["count"], "motors.count", minimum=1)
|
|
|
_require(len(motors["order"]) == motors["count"] and all(isinstance(axis, str) and axis for axis in motors["order"]), "motor order mismatch")
|
|
|
_require(isinstance(motors["role"], str) and motors["role"], "invalid motor role")
|
|
|
- _require(motors["execution"] in {"overlap", "serial"}, "invalid motor execution")
|
|
|
- _integer(motors["busy_wait_ms"], "motors.busy_wait_ms", minimum=0)
|
|
|
- _integer(motors["fixed_steps"], "motors.fixed_steps", minimum=1)
|
|
|
+ _require(motors["execution"] == "overlap", "motor execution must be overlap")
|
|
|
_integer(motors["step_rate_hz"], "motors.step_rate_hz", minimum=1)
|
|
|
+ _require(motors["step_rate_hz"] == 1000, "motor step rate must be 1000")
|
|
|
_integer(motors["step_half_cycles"], "motors.step_half_cycles", minimum=1)
|
|
|
+ _require(motors["step_half_cycles"] == 12500, "motor step half cycles must be 12500")
|
|
|
_integer(motors["dir_setup_cycles"], "motors.dir_setup_cycles", minimum=0)
|
|
|
- _require(isinstance(motors["command_values"], list) and motors["command_values"], "invalid motor commands")
|
|
|
- _require(motors["heartbeat_value"] in motors["command_values"], "motor heartbeat is not a command")
|
|
|
+ _require(motors["dir_setup_cycles"] == 25000, "motor dir setup cycles must be 25000")
|
|
|
_integer(motors["open_dir_value"], "motors.open_dir_value", minimum=0)
|
|
|
_integer(motors["close_dir_value"], "motors.close_dir_value", minimum=0)
|
|
|
_require(motors["open_dir_value"] == 0, "logical open_dir_value must be 0")
|
|
|
@@ -243,7 +255,49 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
for index, level in enumerate(dir_close_level):
|
|
|
_require(isinstance(level, int) and not isinstance(level, bool) and level in (0, 1),
|
|
|
f"motors.dir_close_level[{index}] must be 0 or 1")
|
|
|
- # Per-axis dir_close_level is the sole authority; mixed 0/1 configs are allowed.
|
|
|
+ positioning = _object(motors["positioning"], "motors.positioning")
|
|
|
+ _keys(
|
|
|
+ positioning,
|
|
|
+ {
|
|
|
+ "mode",
|
|
|
+ "percent_min",
|
|
|
+ "percent_max",
|
|
|
+ "open_endpoint_percent",
|
|
|
+ "close_endpoint_percent",
|
|
|
+ "mid_percent_min",
|
|
|
+ "mid_percent_max",
|
|
|
+ "rounding",
|
|
|
+ "mid_clamp",
|
|
|
+ "latest_wins",
|
|
|
+ "idempotent_same_target",
|
|
|
+ "command_interrupt",
|
|
|
+ "shared_percent_planner",
|
|
|
+ "planner_count",
|
|
|
+ "endpoint_guard_extra_steps",
|
|
|
+ },
|
|
|
+ "motors.positioning",
|
|
|
+ )
|
|
|
+ _require(positioning["mode"] == "percent_close", "positioning mode must be percent_close")
|
|
|
+ _integer(positioning["percent_min"], "motors.positioning.percent_min", minimum=0)
|
|
|
+ _integer(positioning["percent_max"], "motors.positioning.percent_max", minimum=0)
|
|
|
+ _require(positioning["percent_min"] == 0 and positioning["percent_max"] == 100, "percent range must be 0..100")
|
|
|
+ _require(positioning["open_endpoint_percent"] == 0, "open endpoint percent must be 0")
|
|
|
+ _require(positioning["close_endpoint_percent"] == 100, "close endpoint percent must be 100")
|
|
|
+ _require(positioning["mid_percent_min"] == 1, "mid percent min must be 1")
|
|
|
+ _require(positioning["mid_percent_max"] == 99, "mid percent max must be 99")
|
|
|
+ _require(positioning["rounding"] == "half_up", "rounding must be half_up")
|
|
|
+ _require(positioning["mid_clamp"] == "1_to_travel_minus_1", "mid clamp policy mismatch")
|
|
|
+ _require(positioning["latest_wins"] is True, "latest_wins must be true")
|
|
|
+ _require(positioning["idempotent_same_target"] is True, "idempotent_same_target must be true")
|
|
|
+ _require(
|
|
|
+ positioning["command_interrupt"] == "finish_current_high_pulse_then_replan",
|
|
|
+ "command interrupt policy mismatch",
|
|
|
+ )
|
|
|
+ _require(positioning["shared_percent_planner"] is True, "shared_percent_planner must be true")
|
|
|
+ _integer(positioning["planner_count"], "motors.positioning.planner_count", minimum=1)
|
|
|
+ _require(positioning["planner_count"] == 1, "planner_count must be 1")
|
|
|
+ _integer(positioning["endpoint_guard_extra_steps"], "motors.positioning.endpoint_guard_extra_steps", minimum=0)
|
|
|
+ _require(positioning["endpoint_guard_extra_steps"] == 500, "endpoint guard extra steps must be 500")
|
|
|
mapping = _object(motors["mapping"], "motors.mapping")
|
|
|
_require(motors["count"] == 3 and motors["order"] == ["x", "y", "z"], "production motor count/order must be x,y,z")
|
|
|
_keys(mapping, {"x", "y", "z"}, "motors.mapping")
|
|
|
@@ -290,25 +344,30 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
# Per-axis limit_active_high / close_limit_is_ls / dir_close_level alone decide
|
|
|
# generated masks. Mixed-axis configs must not force active_level sync.
|
|
|
startup = _object(limits["startup"], "limits.startup")
|
|
|
+ forbidden_startup = FORBIDDEN_STARTUP_KEYS & set(startup)
|
|
|
+ _require(not forbidden_startup, f"obsolete limits.startup keys present: {sorted(forbidden_startup)}")
|
|
|
_keys(
|
|
|
startup,
|
|
|
{
|
|
|
"enabled",
|
|
|
- "direction_value",
|
|
|
- "direction_meaning",
|
|
|
- "close_step_count",
|
|
|
- "backoff_step_count",
|
|
|
+ "mode",
|
|
|
+ "max_steps",
|
|
|
+ "min_travel_steps",
|
|
|
"step_rate_hz",
|
|
|
"axis_order",
|
|
|
+ "final_position",
|
|
|
"limit_stop_during_move",
|
|
|
"stop_semantics",
|
|
|
"additional_rising_edges_after_synchronized_limit",
|
|
|
"runtime_limit_use",
|
|
|
+ "partial_axis_failure_allowed",
|
|
|
+ "fault_lock_until_reset",
|
|
|
},
|
|
|
"limits.startup",
|
|
|
)
|
|
|
_require(startup["enabled"] is True, "startup must be enabled")
|
|
|
- _require(startup["direction_meaning"] == "close", "startup direction must be close")
|
|
|
+ _require(startup["mode"] == "seek_close_then_measure_open", "startup mode must be seek_close_then_measure_open")
|
|
|
+ _require(startup["final_position"] == "open", "startup final position must be open")
|
|
|
_require(startup["limit_stop_during_move"] is True, "startup limit stop during move must be enabled")
|
|
|
_require(
|
|
|
startup["stop_semantics"] == "truncate_current_high_pulse_immediately_after_synchronized_limit",
|
|
|
@@ -316,12 +375,19 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
)
|
|
|
_require(startup["additional_rising_edges_after_synchronized_limit"] == 0, "additional rising edges after limit must be zero")
|
|
|
_require(startup["runtime_limit_use"] is True, "startup runtime limit use must be true")
|
|
|
- _integer(startup["direction_value"], "limits.startup.direction_value", minimum=0)
|
|
|
- _integer(startup["close_step_count"], "limits.startup.close_step_count", minimum=1)
|
|
|
- _integer(startup["backoff_step_count"], "limits.startup.backoff_step_count", minimum=0)
|
|
|
+ _require(startup["partial_axis_failure_allowed"] is True, "partial axis failure must be allowed")
|
|
|
+ _require(startup["fault_lock_until_reset"] is True, "fault lock until reset must be true")
|
|
|
+ _integer(startup["max_steps"], "limits.startup.max_steps", minimum=1)
|
|
|
+ _integer(startup["min_travel_steps"], "limits.startup.min_travel_steps", minimum=0)
|
|
|
_integer(startup["step_rate_hz"], "limits.startup.step_rate_hz", minimum=1)
|
|
|
- _require(startup["close_step_count"] == 5000, "startup close step count must be 5000")
|
|
|
- _require(startup["backoff_step_count"] == 500, "startup backoff step count must be 500")
|
|
|
+ _require(startup["max_steps"] == 5000, "startup max_steps must be 5000")
|
|
|
+ _require(startup["min_travel_steps"] >= 2, "min_travel_steps must be >= 2")
|
|
|
+ _require(startup["min_travel_steps"] == 2, "startup min_travel_steps must be 2")
|
|
|
+ _require(startup["step_rate_hz"] == 1000, "startup step rate must be 1000")
|
|
|
+ _require(startup["max_steps"] <= CAL_COUNTER_MAX, "max_steps exceeds calibration counter width")
|
|
|
+ endpoint_guard_max = startup["max_steps"] + positioning["endpoint_guard_extra_steps"]
|
|
|
+ _require(endpoint_guard_max <= CAL_COUNTER_MAX, "endpoint guard max exceeds calibration counter width")
|
|
|
+ _require(endpoint_guard_max == 5500, "endpoint guard max must be 5500")
|
|
|
_require(len(startup["axis_order"]) == 3 and startup["axis_order"] == ["x", "y", "z"], "startup axis order mismatch")
|
|
|
expected_limit_names = [
|
|
|
"x_limit_ls",
|
|
|
@@ -414,7 +480,7 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
"temperature_ram",
|
|
|
"dsp",
|
|
|
"shared_pwm_comparators",
|
|
|
- "shared_motor_executors",
|
|
|
+ "shared_percent_planner",
|
|
|
"shared_i2c_readers",
|
|
|
},
|
|
|
"resource_policy",
|
|
|
@@ -427,9 +493,24 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
)
|
|
|
else:
|
|
|
_integer(value, f"resource_policy.{key}", minimum=0)
|
|
|
+ _require(resources["dsp"] == 0, "resource_policy.dsp must be 0")
|
|
|
+ _require(resources["shared_percent_planner"] == 1, "resource_policy.shared_percent_planner must be 1")
|
|
|
+ _require(resources["shared_percent_planner"] == positioning["planner_count"], "shared planner count mismatch")
|
|
|
|
|
|
protocol = _object(payload["protocol"], "protocol")
|
|
|
- _keys(protocol, {"header_hex", "crc", "commands", "set_all", "temperature_data"}, "protocol")
|
|
|
+ _keys(
|
|
|
+ protocol,
|
|
|
+ {
|
|
|
+ "header_hex",
|
|
|
+ "crc",
|
|
|
+ "commands",
|
|
|
+ "set_all",
|
|
|
+ "get_motor_status",
|
|
|
+ "temperature_data",
|
|
|
+ "motor_status_data",
|
|
|
+ },
|
|
|
+ "protocol",
|
|
|
+ )
|
|
|
_require(isinstance(protocol["header_hex"], str) and protocol["header_hex"], "frame header missing")
|
|
|
crc = _object(protocol["crc"], "protocol.crc")
|
|
|
_keys(crc, {"name", "polynomial", "initial", "reflect_input", "reflect_output", "xor_output", "coverage", "wire_order"}, "protocol.crc")
|
|
|
@@ -447,26 +528,39 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
},
|
|
|
"CRC contract mismatch",
|
|
|
)
|
|
|
- _require(set(protocol["commands"]) == {"set_all", "get_temperature", "temperature_data"}, "protocol command keys mismatch")
|
|
|
- set_all = _object(protocol["set_all"], "protocol.set_all")
|
|
|
+ commands = _object(protocol["commands"], "protocol.commands")
|
|
|
_keys(
|
|
|
- set_all,
|
|
|
- {
|
|
|
- "payload_length",
|
|
|
- "fan_offset",
|
|
|
- "chamber_ptc_offset",
|
|
|
- "chamber_ptc_count",
|
|
|
- "z_door_offset",
|
|
|
- "exhaust_x_offset",
|
|
|
- "exhaust_y_offset",
|
|
|
- "legacy_payload_length_rejected",
|
|
|
- "duty_min",
|
|
|
- "duty_max",
|
|
|
- "door_values",
|
|
|
- "response",
|
|
|
- },
|
|
|
- "protocol.set_all",
|
|
|
+ commands,
|
|
|
+ {"set_all", "get_temperature", "get_motor_status", "temperature_data", "motor_status_data"},
|
|
|
+ "protocol.commands",
|
|
|
)
|
|
|
+ _require(commands["set_all"] == 1, "SET_ALL command type mismatch")
|
|
|
+ _require(commands["get_temperature"] == 2, "GET_TEMPERATURE command type mismatch")
|
|
|
+ _require(commands["get_motor_status"] == 3, "GET_MOTOR_STATUS command type mismatch")
|
|
|
+ _require(commands["temperature_data"] == 130, "TEMPERATURE_DATA command type mismatch")
|
|
|
+ _require(commands["motor_status_data"] == 131, "MOTOR_STATUS_DATA command type mismatch")
|
|
|
+ command_values = list(commands.values())
|
|
|
+ _require(len(command_values) == len(set(command_values)), "duplicate protocol command types")
|
|
|
+ _require("door_values" not in protocol.get("set_all", {}), "obsolete set_all.door_values present")
|
|
|
+ set_all = _object(protocol["set_all"], "protocol.set_all")
|
|
|
+ set_all_keys = {
|
|
|
+ "payload_length",
|
|
|
+ "fan_offset",
|
|
|
+ "chamber_ptc_offset",
|
|
|
+ "chamber_ptc_count",
|
|
|
+ "z_door_offset",
|
|
|
+ "exhaust_x_offset",
|
|
|
+ "exhaust_y_offset",
|
|
|
+ "legacy_payload_length_rejected",
|
|
|
+ "duty_min",
|
|
|
+ "duty_max",
|
|
|
+ "door_percent_min",
|
|
|
+ "door_percent_max",
|
|
|
+ "response",
|
|
|
+ }
|
|
|
+ optional_set_all = {"door_percent_rejected_example"}
|
|
|
+ _require(set_all_keys <= set(set_all), "protocol.set_all missing required keys")
|
|
|
+ _require(set(set_all) <= (set_all_keys | optional_set_all), "protocol.set_all keys mismatch")
|
|
|
_require(set_all["fan_offset"] == 0, "SET_ALL FAN offset mismatch")
|
|
|
_require(set_all["chamber_ptc_offset"] == outputs["fan_count"], "SET_ALL chamber PTC offset mismatch")
|
|
|
_require(set_all["chamber_ptc_count"] == outputs["chamber_ptc_count"], "SET_ALL chamber PTC count mismatch")
|
|
|
@@ -476,11 +570,32 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_require(set_all["payload_length"] == set_all["exhaust_y_offset"] + 1, "SET_ALL length mismatch")
|
|
|
_require(set_all["legacy_payload_length_rejected"] == 14, "legacy payload length marker mismatch")
|
|
|
_require(set_all["duty_min"] <= set_all["duty_max"], "SET_ALL duty range mismatch")
|
|
|
- _require(set_all["door_values"] == motors["command_values"], "SET_ALL door values mismatch")
|
|
|
+ _require(set_all["door_percent_min"] == positioning["percent_min"], "SET_ALL door percent min mismatch")
|
|
|
+ _require(set_all["door_percent_max"] == positioning["percent_max"], "SET_ALL door percent max mismatch")
|
|
|
+ _require(set_all["response"] == "none", "SET_ALL response must be none")
|
|
|
+ if "door_percent_rejected_example" in set_all:
|
|
|
+ _integer(set_all["door_percent_rejected_example"], "protocol.set_all.door_percent_rejected_example", minimum=0)
|
|
|
+ _require(
|
|
|
+ set_all["door_percent_rejected_example"] > set_all["door_percent_max"],
|
|
|
+ "door percent rejected example must exceed door_percent_max",
|
|
|
+ )
|
|
|
+ get_motor_status = _object(protocol["get_motor_status"], "protocol.get_motor_status")
|
|
|
+ _keys(get_motor_status, {"payload_length", "response"}, "protocol.get_motor_status")
|
|
|
+ _require(get_motor_status["payload_length"] == 0, "GET_MOTOR_STATUS payload length must be 0")
|
|
|
+ _require(get_motor_status["response"] == "motor_status_data", "GET_MOTOR_STATUS response mismatch")
|
|
|
temperature_data = _object(protocol["temperature_data"], "protocol.temperature_data")
|
|
|
_keys(temperature_data, {"payload_length", "frame_length"}, "protocol.temperature_data")
|
|
|
_require(temperature_data["payload_length"] == temperature["value_count"], "temperature payload length mismatch")
|
|
|
_require(temperature_data["frame_length"] == temperature_data["payload_length"] + 6, "temperature frame length mismatch")
|
|
|
+ motor_status_data = _object(protocol["motor_status_data"], "protocol.motor_status_data")
|
|
|
+ _keys(motor_status_data, {"payload_length", "frame_length", "layout"}, "protocol.motor_status_data")
|
|
|
+ _require(motor_status_data["payload_length"] == 31, "motor status payload length must be 31")
|
|
|
+ _require(motor_status_data["frame_length"] == 37, "motor status frame length must be 37")
|
|
|
+ _require(
|
|
|
+ motor_status_data["frame_length"] == motor_status_data["payload_length"] + 6,
|
|
|
+ "motor status frame length mismatch",
|
|
|
+ )
|
|
|
+ _require(motor_status_data["layout"] == "host-contract", "motor status layout marker mismatch")
|
|
|
|
|
|
timeouts = _object(payload["timeouts"], "timeouts")
|
|
|
_keys(timeouts, {"frame_inter_byte_ms", "host_get_response_ms"}, "timeouts")
|
|
|
@@ -488,16 +603,23 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_integer(timeouts["host_get_response_ms"], "timeouts.host_get_response_ms", minimum=1)
|
|
|
|
|
|
watchdog = _object(payload["watchdog"], "watchdog")
|
|
|
- _keys(watchdog, {"timeout_seconds", "tick_us", "tick_clks", "timeout_ticks", "target"}, "watchdog")
|
|
|
+ _keys(
|
|
|
+ watchdog,
|
|
|
+ {"timeout_seconds", "tick_us", "tick_clks", "timeout_ticks", "enable_after_startup_complete", "target"},
|
|
|
+ "watchdog",
|
|
|
+ )
|
|
|
_integer(watchdog["timeout_seconds"], "watchdog.timeout_seconds", minimum=1)
|
|
|
_integer(watchdog["tick_us"], "watchdog.tick_us", minimum=1)
|
|
|
_integer(watchdog["tick_clks"], "watchdog.tick_clks", minimum=1)
|
|
|
_require(watchdog["tick_clks"] == device["clock_hz"] * watchdog["tick_us"] // 1_000_000, "watchdog tick clock mismatch")
|
|
|
_integer(watchdog["timeout_ticks"], "watchdog.timeout_ticks", minimum=1)
|
|
|
_require(watchdog["timeout_ticks"] == watchdog["timeout_seconds"] * 1_000_000 // watchdog["tick_us"], "watchdog tick count mismatch")
|
|
|
+ _require(watchdog["timeout_seconds"] == 30, "watchdog timeout_seconds must be 30")
|
|
|
+ _require(watchdog["timeout_ticks"] == 60000, "watchdog timeout_ticks must be 60000")
|
|
|
+ _require(watchdog["enable_after_startup_complete"] is True, "watchdog must enable after startup complete")
|
|
|
target = _object(watchdog["target"], "watchdog.target")
|
|
|
_keys(target, {"ptc", "fan"}, "watchdog.target")
|
|
|
- _require(target == {"ptc": 0, "fan": 20}, "watchdog target mismatch")
|
|
|
+ _require(target == {"ptc": 0, "fan": 10}, "watchdog target mismatch")
|
|
|
|
|
|
|
|
|
def load_project(path: Path) -> dict[str, Any]:
|
|
|
@@ -607,20 +729,24 @@ def _frame_hex(frame_type: int, payload: bytes) -> str:
|
|
|
def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
outputs = project["outputs"]
|
|
|
motors = project["motors"]
|
|
|
+ positioning = motors["positioning"]
|
|
|
limits = project["limits"]
|
|
|
startup = limits["startup"]
|
|
|
temperature = project["temperature"]
|
|
|
uart = project["uart"]
|
|
|
watchdog = project["watchdog"]
|
|
|
+ protocol = project["protocol"]
|
|
|
+ commands = protocol["commands"]
|
|
|
axis_count = motors["count"]
|
|
|
_require(motors["dir_setup_cycles"] % watchdog["tick_clks"] == 0, "motor direction setup is not an integral tick count")
|
|
|
motor_dir_setup_ticks = motors["dir_setup_cycles"] // watchdog["tick_clks"]
|
|
|
frame_inter_byte_timeout_cycles = project["device"]["clock_hz"] * project["timeouts"]["frame_inter_byte_ms"] // 1000
|
|
|
- startup_dir_bit = startup["direction_value"]
|
|
|
+ startup_dir_bit = motors["close_dir_value"]
|
|
|
startup_dir_mask = f"{axis_count}'b" + (str(startup_dir_bit) * axis_count)
|
|
|
limit_active_high_mask = _axis_mask_literal(limits["limit_active_high"], axis_count)
|
|
|
dir_close_level_mask = _axis_mask_literal(motors["dir_close_level"], axis_count)
|
|
|
close_limit_is_ls_mask = _axis_mask_literal(limits["close_limit_is_ls"], axis_count)
|
|
|
+ endpoint_guard_max = startup["max_steps"] + positioning["endpoint_guard_extra_steps"]
|
|
|
lines = [
|
|
|
"// Generated from project.json. Do not edit.",
|
|
|
f"`define P4_AXIS_COUNT {axis_count}",
|
|
|
@@ -641,22 +767,35 @@ def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
f"`define P4_PWM_PHASE_COUNT {outputs['pwm_phase_count']}",
|
|
|
f"`define P4_PWM_FREQUENCY_HZ {outputs['pwm_frequency_hz']}",
|
|
|
f"`define P4_PWM_SLOT_CLKS {outputs['pwm_slot_clks']}",
|
|
|
- f"`define P4_SET_ALL_PAYLOAD_LENGTH {project['protocol']['set_all']['payload_length']}",
|
|
|
+ f"`define P4_CMD_SET_ALL 8'h{commands['set_all']:02X}",
|
|
|
+ f"`define P4_CMD_GET_TEMPERATURE 8'h{commands['get_temperature']:02X}",
|
|
|
+ f"`define P4_CMD_GET_MOTOR_STATUS 8'h{commands['get_motor_status']:02X}",
|
|
|
+ f"`define P4_CMD_TEMPERATURE_DATA 8'h{commands['temperature_data']:02X}",
|
|
|
+ f"`define P4_CMD_MOTOR_STATUS_DATA 8'h{commands['motor_status_data']:02X}",
|
|
|
+ f"`define P4_RSP_TEMPERATURE 8'h{commands['temperature_data']:02X}",
|
|
|
+ f"`define P4_RSP_MOTOR_STATUS 8'h{commands['motor_status_data']:02X}",
|
|
|
+ f"`define P4_SET_ALL_PAYLOAD_LENGTH {protocol['set_all']['payload_length']}",
|
|
|
f"`define P4_CHAMBER_PTC_COUNT {outputs['chamber_ptc_count']}",
|
|
|
- f"`define P4_SET_ALL_FAN_OFFSET {project['protocol']['set_all']['fan_offset']}",
|
|
|
- f"`define P4_SET_ALL_CHAMBER_PTC_OFFSET {project['protocol']['set_all']['chamber_ptc_offset']}",
|
|
|
- f"`define P4_SET_ALL_Z_DOOR_OFFSET {project['protocol']['set_all']['z_door_offset']}",
|
|
|
- f"`define P4_SET_ALL_EXHAUST_X_OFFSET {project['protocol']['set_all']['exhaust_x_offset']}",
|
|
|
- f"`define P4_SET_ALL_EXHAUST_Y_OFFSET {project['protocol']['set_all']['exhaust_y_offset']}",
|
|
|
+ f"`define P4_SET_ALL_FAN_OFFSET {protocol['set_all']['fan_offset']}",
|
|
|
+ f"`define P4_SET_ALL_CHAMBER_PTC_OFFSET {protocol['set_all']['chamber_ptc_offset']}",
|
|
|
+ f"`define P4_SET_ALL_Z_DOOR_OFFSET {protocol['set_all']['z_door_offset']}",
|
|
|
+ f"`define P4_SET_ALL_EXHAUST_X_OFFSET {protocol['set_all']['exhaust_x_offset']}",
|
|
|
+ f"`define P4_SET_ALL_EXHAUST_Y_OFFSET {protocol['set_all']['exhaust_y_offset']}",
|
|
|
+ f"`define P4_DOOR_PERCENT_MIN {positioning['percent_min']}",
|
|
|
+ f"`define P4_DOOR_PERCENT_MAX {positioning['percent_max']}",
|
|
|
+ f"`define P4_OPEN_ENDPOINT_PERCENT {positioning['open_endpoint_percent']}",
|
|
|
+ f"`define P4_CLOSE_ENDPOINT_PERCENT {positioning['close_endpoint_percent']}",
|
|
|
+ f"`define P4_MID_PERCENT_MIN {positioning['mid_percent_min']}",
|
|
|
+ f"`define P4_MID_PERCENT_MAX {positioning['mid_percent_max']}",
|
|
|
+ f"`define P4_MOTOR_STATUS_PAYLOAD_LENGTH {protocol['motor_status_data']['payload_length']}",
|
|
|
+ f"`define P4_MOTOR_STATUS_FRAME_LENGTH {protocol['motor_status_data']['frame_length']}",
|
|
|
f"`define P4_MOTOR_OPEN_DIR 1'b{motors['open_dir_value']}",
|
|
|
f"`define P4_MOTOR_CLOSE_DIR 1'b{motors['close_dir_value']}",
|
|
|
f"`define P4_FRAME_INTER_BYTE_TIMEOUT_CYCLES {frame_inter_byte_timeout_cycles}",
|
|
|
- f"`define P4_FIXED_MOTOR_STEPS {motors['fixed_steps']}",
|
|
|
f"`define P4_MOTOR_STEP_RATE_HZ {motors['step_rate_hz']}",
|
|
|
f"`define P4_MOTOR_STEP_HALF_CYCLES {motors['step_half_cycles']}",
|
|
|
f"`define P4_MOTOR_DIR_SETUP_CYCLES {motors['dir_setup_cycles']}",
|
|
|
f"`define P4_MOTOR_DIR_SETUP_TICKS {motor_dir_setup_ticks}",
|
|
|
- f"`define P4_MOTOR_HEARTBEAT_COMMAND 2'd{motors['heartbeat_value']}",
|
|
|
f"`define P4_TEMPERATURE_COUNT {temperature['value_count']}",
|
|
|
f"`define P4_TEMPERATURE_COUNT_BYTE 8'h{temperature['value_count']:02X}",
|
|
|
f"`define P4_TEMPERATURE_FRAME_LENGTH {temperature['value_count'] + 6}",
|
|
|
@@ -669,14 +808,30 @@ def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
f"`define P4_WATCHDOG_TICK_US {watchdog['tick_us']}",
|
|
|
f"`define P4_WATCHDOG_TICK_CLKS {watchdog['tick_clks']}",
|
|
|
f"`define P4_WATCHDOG_TIMEOUT_TICKS {watchdog['timeout_ticks']}",
|
|
|
+ f"`define P4_WATCHDOG_ENABLE_AFTER_STARTUP {1 if watchdog['enable_after_startup_complete'] else 0}",
|
|
|
f"`define P4_WATCHDOG_PTC_TARGET 8'h{watchdog['target']['ptc']:02X}",
|
|
|
f"`define P4_WATCHDOG_FAN_TARGET 8'h{watchdog['target']['fan']:02X}",
|
|
|
f"`define P4_STARTUP_ENABLED {1 if startup['enabled'] else 0}",
|
|
|
f"`define P4_STARTUP_DIR_MASK {startup_dir_mask}",
|
|
|
- f"`define P4_STARTUP_CLOSE_STEPS {startup['close_step_count']}",
|
|
|
- f"`define P4_STARTUP_BACKOFF_STEPS {startup['backoff_step_count']}",
|
|
|
+ f"`define P4_CAL_MAX_STEPS {startup['max_steps']}",
|
|
|
+ f"`define P4_CAL_MIN_TRAVEL {startup['min_travel_steps']}",
|
|
|
+ f"`define P4_ENDPOINT_GUARD_EXTRA {positioning['endpoint_guard_extra_steps']}",
|
|
|
+ f"`define P4_ENDPOINT_GUARD_MAX {endpoint_guard_max}",
|
|
|
f"`define P4_STARTUP_STEP_RATE_HZ {startup['step_rate_hz']}",
|
|
|
f"`define P4_MOTOR_ENABLE_POLICY_PERMANENT_HIGH {1 if motors['enable_n']['policy'] == 'permanent_high' else 0}",
|
|
|
+ "`define P4_STATE_CAL_SEEK_CLOSE 8'd0",
|
|
|
+ "`define P4_STATE_CAL_MEASURE_OPEN 8'd1",
|
|
|
+ "`define P4_STATE_IDLE 8'd2",
|
|
|
+ "`define P4_STATE_MOVE_OPEN 8'd3",
|
|
|
+ "`define P4_STATE_MOVE_CLOSE 8'd4",
|
|
|
+ "`define P4_STATE_WAIT_REPLAN 8'd5",
|
|
|
+ "`define P4_STATE_FAULT 8'd6",
|
|
|
+ "`define P4_FAULT_NONE 8'd0",
|
|
|
+ "`define P4_FAULT_BOTH_LIMITS_ACTIVE 8'd1",
|
|
|
+ "`define P4_FAULT_CAL_CLOSE_TIMEOUT 8'd2",
|
|
|
+ "`define P4_FAULT_CAL_OPEN_TIMEOUT 8'd3",
|
|
|
+ "`define P4_FAULT_INVALID_ZERO_OR_TINY_TRAVEL 8'd4",
|
|
|
+ "`define P4_FAULT_ENDPOINT_TIMEOUT 8'd5",
|
|
|
]
|
|
|
lines.extend(
|
|
|
f"`define P4_TEMP_DEVICE_ADDR_{index} 7'h{address:02X}"
|
|
|
@@ -710,6 +865,53 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
|
|
|
_render_params(project), encoding="ascii", newline="\n"
|
|
|
)
|
|
|
summary = project_summary(project_path)
|
|
|
+ positioning = project["motors"]["positioning"]
|
|
|
+ motor_status_layout = {
|
|
|
+ "byte0_global": {
|
|
|
+ "bit0_2": "calibrated_mask_xyz",
|
|
|
+ "bit3_5": "fault_mask_xyz",
|
|
|
+ "bit6": "startup_complete",
|
|
|
+ "bit7": "watchdog_tripped",
|
|
|
+ },
|
|
|
+ "per_axis_bytes": 10,
|
|
|
+ "axis_order": ["x", "y", "z"],
|
|
|
+ "axis_fields": [
|
|
|
+ "state",
|
|
|
+ "flags",
|
|
|
+ "requested_percent",
|
|
|
+ "current_position_le16",
|
|
|
+ "target_position_le16",
|
|
|
+ "travel_steps_le16",
|
|
|
+ "fault_code",
|
|
|
+ ],
|
|
|
+ "states": {
|
|
|
+ "CAL_SEEK_CLOSE": 0,
|
|
|
+ "CAL_MEASURE_OPEN": 1,
|
|
|
+ "IDLE": 2,
|
|
|
+ "MOVE_OPEN": 3,
|
|
|
+ "MOVE_CLOSE": 4,
|
|
|
+ "WAIT_REPLAN": 5,
|
|
|
+ "FAULT": 6,
|
|
|
+ },
|
|
|
+ "flags": {
|
|
|
+ "open_limit": 0,
|
|
|
+ "close_limit": 1,
|
|
|
+ "calibrated": 2,
|
|
|
+ "moving": 3,
|
|
|
+ "endpoint_mode": 4,
|
|
|
+ "target_valid": 5,
|
|
|
+ "replan_pending": 6,
|
|
|
+ "reserved": 7,
|
|
|
+ },
|
|
|
+ "fault_codes": {
|
|
|
+ "NONE": 0,
|
|
|
+ "BOTH_LIMITS_ACTIVE": 1,
|
|
|
+ "CAL_CLOSE_TIMEOUT": 2,
|
|
|
+ "CAL_OPEN_TIMEOUT": 3,
|
|
|
+ "INVALID_ZERO_OR_TINY_TRAVEL": 4,
|
|
|
+ "ENDPOINT_TIMEOUT": 5,
|
|
|
+ },
|
|
|
+ }
|
|
|
contract = {
|
|
|
"schema": "prod2u-simple-host-contract-v1",
|
|
|
"project_id": project["project_id"],
|
|
|
@@ -725,7 +927,14 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
|
|
|
"payload_length": summary["set_all_payload_len"],
|
|
|
"response": "none",
|
|
|
"duty_range": [0, 100],
|
|
|
- "door_values": [0, 1, 2],
|
|
|
+ "door_percent_range": [positioning["percent_min"], positioning["percent_max"]],
|
|
|
+ "door_percent_semantics": {
|
|
|
+ "0": "full_open_endpoint",
|
|
|
+ "1_to_99": "mid_percent_close",
|
|
|
+ "100": "full_close_endpoint",
|
|
|
+ "all_zero_frame": "fan_ptc_zero_and_all_doors_full_open_not_heartbeat",
|
|
|
+ "0x65": "rejected_out_of_range",
|
|
|
+ },
|
|
|
"field_order": [
|
|
|
"fan_chamber_1",
|
|
|
"fan_chamber_2",
|
|
|
@@ -735,17 +944,24 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
|
|
|
"ptc_chamber_2",
|
|
|
"ptc_chamber_3",
|
|
|
"ptc_chamber_4",
|
|
|
- "door_z",
|
|
|
- "door_x",
|
|
|
- "door_y",
|
|
|
+ "door_z_percent",
|
|
|
+ "door_x_percent",
|
|
|
+ "door_y_percent",
|
|
|
],
|
|
|
},
|
|
|
"get_temperature": {"type": "0x02", "payload_length": 0, "response": "TEMPERATURE_DATA"},
|
|
|
+ "get_motor_status": {"type": "0x03", "payload_length": 0, "response": "MOTOR_STATUS_DATA"},
|
|
|
"temperature_data": {
|
|
|
"type": "0x82",
|
|
|
"payload_length": summary["temperature_payload_len"],
|
|
|
"frame_length": summary["temperature_frame_len"],
|
|
|
},
|
|
|
+ "motor_status_data": {
|
|
|
+ "type": "0x83",
|
|
|
+ "payload_length": project["protocol"]["motor_status_data"]["payload_length"],
|
|
|
+ "frame_length": project["protocol"]["motor_status_data"]["frame_length"],
|
|
|
+ "layout": motor_status_layout,
|
|
|
+ },
|
|
|
},
|
|
|
"outputs": project["outputs"],
|
|
|
"motors": project["motors"],
|
|
|
@@ -755,14 +971,27 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
|
|
|
}
|
|
|
_write_json(output / "host-contract.json", contract)
|
|
|
_write_json(output / "project-summary.json", summary)
|
|
|
+ # Representative status: startup_complete + all calibrated, idle at open, travel=1000.
|
|
|
+ status_axis = bytes((0x02, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x03, 0x00))
|
|
|
+ status_payload = bytes((0x47,)) + status_axis * 3
|
|
|
_write_json(
|
|
|
output / "golden-vectors.json",
|
|
|
{
|
|
|
- "set_all_all_zero": _frame_hex(0x01, bytes(11)),
|
|
|
- "set_all_mixed": _frame_hex(0x01, bytes((10, 20, 30, 40, 0, 25, 50, 100, 1, 2, 0))),
|
|
|
+ "set_all_all_zero_full_open": _frame_hex(0x01, bytes(11)),
|
|
|
+ "set_all_doors_0_percent": _frame_hex(0x01, bytes((10, 20, 30, 40, 0, 25, 50, 100, 0, 0, 0))),
|
|
|
+ "set_all_doors_50_percent": _frame_hex(0x01, bytes((10, 20, 30, 40, 0, 25, 50, 100, 50, 50, 50))),
|
|
|
+ "set_all_doors_100_percent": _frame_hex(0x01, bytes((10, 20, 30, 40, 0, 25, 50, 100, 100, 100, 100))),
|
|
|
+ "set_all_door_0x65_rejected": "65",
|
|
|
"set_all_legacy_14_rejected": "0E",
|
|
|
"get_temperature": _frame_hex(0x02, b""),
|
|
|
+ "get_motor_status": _frame_hex(0x03, b""),
|
|
|
+ "motor_status_data_example": _frame_hex(0x83, status_payload),
|
|
|
"all_invalid_temperature": _frame_hex(0x82, bytes([0xFF] * project["temperature"]["value_count"])),
|
|
|
+ "notes": {
|
|
|
+ "set_all_all_zero_full_open": "Legal SET_ALL: FAN/PTC 0 and doors 0/0/0 = full open; not a jog heartbeat no-op.",
|
|
|
+ "set_all_door_0x65_rejected": "Door percent 0x65 (101) is out of 0..100 and must be rejected.",
|
|
|
+ "get_motor_status": "Exact request frame A55A03005C48.",
|
|
|
+ },
|
|
|
},
|
|
|
)
|
|
|
source_payload = {
|