Skip to content

update wiregrid_tiltsensor to implement a new type tilt sensor. - #1120

Open
sadachi5 wants to merge 6 commits into
mainfrom
sadachi5_wiregrid_tiltsensor_upgrade
Open

sadachi5 wants to merge 6 commits into
mainfrom
sadachi5_wiregrid_tiltsensor_upgrade

Conversation

@sadachi5

Copy link
Copy Markdown
Contributor

Description

Add support for the Pacico SLP2 inclinometer to the Wiregrid Tilt Sensor Agent, and fix several existing error-handling bugs in the agent.

New SLP2 support

  • New driver socs/agents/wiregrid_tiltsensor/drivers/slp2.py (class SLP2), communicating over the serial-to-ethernet converter with ASCII commands:
    • On connection: stpcasc (stop continuous output) and setoasc (ASCII output mode).
    • get_angle(): get-x&y, returns (X, Y) in degrees.
    • get_temp(): gettemp, returns one temperature in degC. ADC bytes may precede the value in the reply, so the reply is read until a CR that follows a number, and the last number is used.
    • Zero-point commands (setzcur / setzfac) are intentionally not implemented, since they change the sensor's stored state.
  • New --sensor-type slp2 option.
  • For slp2, the agent records one temperature field in the wgtiltsensor feed and session.data, because the SLP2 has a single temperature sensor common to both axes. For DWL / sherborne, the feed is unchanged (temperatureX / temperatureY).

Bug fixes in the existing agent

  • connect() raised a string (raise ('Invalid tiltsensor type')), which itself fails with TypeError. It now raises ValueError. --sensor-type also has choices=['DWL', 'sherborne', 'slp2'], so typos are rejected at startup.
  • acq only logged a warning when the lock could not be acquired and then kept running. It now returns False. The log message also now includes the lock holder (it used to print a literal {}).
  • acq stopped on network errors (OSError, e.g. connection refused or broken pipe), and also stopped if reconnecting failed. Now OSError is caught, the connection is closed, and the agent reconnects at the start of the next loop, retrying until it succeeds.
  • reset returned a bare False when the lock could not be acquired. It now returns (False, msg). It also returns False if the sensor is currently disconnected.

Docs

  • Updated docs/agents/wiregrid_tiltsensor.rst: SLP2 description, temperature field, reconnection behaviour, an SLP2 site-config example, and some typo fixes.
  • Changed the badge to AI-assisted, and added # Code developed with AI assistance. to the modified and new source files, per CONTRIBUTING.rst.

Motivation and Context

We are upgrading the wire-grid tilt sensor to a Pacico SLP2, which the agent did not support. The error-handling bugs above were found while reviewing the agent for this change. The OSError fix in particular matters for unattended operation, because a dropped connection to the converter used to stop data acquisition.

How Has This Been Tested?

  • AI check has been passed.
  • Not yet tested with real SLP2 hardware.

Checklist:

  • My code follows the code style of this project.
  • I have updated related documentation or an update to the documentation is not required.

AI Usage Disclosure

Claude Code (Claude Opus 5.5) was used to write the SLP2 driver, the agent changes, the bug fixes and the documentation updates, based on a standalone SLP2 test script I wrote. I reviewed the changes. The files are marked with # Code developed with AI assistance. and the docs page has the AI-assisted badge.

@sadachi5 sadachi5 self-assigned this Oct 28, 2026
@sadachi5
sadachi5 requested a review from YutaroKASAI October 28, 2026 14:37
@BrianJKoopman BrianJKoopman added enhancement New feature or request. ai assisted AI tools, like Claude Code, were used in the creation of this PR. labels Oct 28, 2026
@sadachi5

sadachi5 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@BrianJKoopman or @YutaroKASAI, please review my update. We cannot read the angles if this PR was deployed to the site software.

@BrianJKoopman BrianJKoopman left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, some minor comments below. Do you have plans to test against the real hardware before we merge?

I'm also wondering about the state of the sherborne sensors. It seems like the temperature readout doesn't really work as is, and it was noted that we'd likely drop support for them. Should we do that now? Or are they still in use?

EDIT: Also, please merge in the latest from the main branch. That will fix the checks.

Comment thread docs/agents/wiregrid_tiltsensor.rst Outdated
The tilt sensor data is sent via serial-to-ethernet converter.
The converter is linked to the tilt sensor
via RS-422(DWL) or RS-485(sherborne), D-sub 9-pin cable.
via RS-422(DWL), RS-485(sherborne) or RS-232 (SLP2).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still a 9-pin D-sub cable? The RS-232/RS-422/RS-485 just defines the serial standard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of cable is different depending on tilt sensor.
So, I removed the words.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the added info. Let's move the more detailed info starting from "There are three types of tilt sensors..." down to a "Description" section below the "Docker Compose" section/above the "Agent API" section at the ------- level. (See this example for location reference.)

'Could not start acq because {} is already running'
)
msg = f'Could not start acq because {self.lock.job} is already running'
self.log.warn(msg)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this at the 'error' level, since it stops the process:

Suggested change
self.log.warn(msg)
self.log.error(msg)

Comment on lines +107 to +108
tiltsensor_data['data']['temperatureX'] = -999
tiltsensor_data['data']['temperatureY'] = -999

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example session data says these temperature fields are only available on the 'sherborne' sensors. Does this mean 'DWL' has no temperature reading? Should we also have a check here for elif self.sensor_type == 'sherborne'?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, below it looks like 'temperatureX' and 'temperatureY' can't be updated -- all the 'sherbone' code is commented out. Why initialize this at all?

return False
msg = ("Lock could not be acquired because it "
+ f"is held by {self.lock.job}")
self.log.warn(msg)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:

Suggested change
self.log.warn(msg)
self.log.error(msg)

tcp_port (int): TCP port
"""
if tcp_ip is None or tcp_port is None:
raise Exception(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be more specific. I'd recommend using TypeError instead of the general Exception.

Comment on lines +103 to +104
"Aborted SLP2._conn() due to no "
"TCP port specified")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message says no port was specified, but it can also trigger if no IP was provided.

Comment on lines +119 to +121
else:
raise Exception(
"Aborted SLP2._conn() due to unknown error")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this ever evaluates. You could simplify the conditionals here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai assisted AI tools, like Claude Code, were used in the creation of this PR. enhancement New feature or request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants