HWP PID Agent
usage: python3 agent.py [-h] [--ip IP] [--port PORT] [--verbose] [--mode MODE]
Agent Options
- --ip
- --port
- --verbose, -v
PID Controller verbosity level.
Default: 0
- --mode
Configuration File Examples
Below are configuration examples for the ocs config file and for running the Agent in a docker container.
OCS Site Config
An example site-config-file block:
{'agent-class': 'HWPPIDAgent',
'instance-id': 'hwp-pid',
'arguments': [['--ip', '10.10.10.101'],
['--port', '2000']]},
Docker Compose
An example docker compose configuration:
ocs-hwp-pid:
image: simonsobs/socs:latest
hostname: ocs-docker
network_mode: "host"
environment:
- INSTANCE_ID=hwp-pid
- SITE_HUB=ws://127.0.0.1:8001/ws
- SITE_HTTP=http://127.0.0.1:8001/call
volumes:
- ${OCS_CONFIG_DIR}:/config:ro
Note
Since the Agent container needs network_mode: "host", it must be
configured to connect to the crossbar server as if it was on the host
system. In this example the crossbar server is running on localhost,
127.0.0.1, but on your network this may be different.
Agent API
- class socs.agents.hwp_pid.agent.HWPPIDAgent(agent, ip, port, verbosity)[source]
Agent to PID control the rotation speed of the CHWP
- Parameters:
ip (str) – IP address for the PID controller
port (str) – Port for the PID controller
verbosity (str) – Verbosity of PID controller output
- main()[source]
- Process - Main Process for PID agent. Periodically queries PID
controller for data, and executes requested actions.
Notes
The most recent data collected is stored in the session data in the structure:
>>> response.session['data'] {'current_freq': 0, 'target_freq': 0, 'direction': 1, 'last_updated': 1649085992.719602}
- tune_stop()[source]
Task - Reverse the drive direction of the PID controller and optimize the PID parameters for deceleration.
- tune_freq()[source]
Task - Tune the PID controller setpoint to the rotation frequency and optimize the PID parameters for rotation.
- declare_freq(freq=0)[source]
Task - Store the entered frequency as the PID setpoint when
tune_freq()is next called.- Parameters:
freq (float) – Desired HWP rotation frequency
Notes
Session data is structured as follows:
>>> response.session['data'] {'declared_freq': 2.0}
- set_pid(p=0.2, i=63, d=0.)[source]
Task - Set the PID parameters. Note these changes are for the current session only and will change whenever the agent container is reloaded.
- Parameters:
p (float) – Proportional PID value
i (int) – Integral PID value
d (float) – Derivative PID value
- set_direction(direction='0')[source]
Task - Set the HWP rotation direction.
- Parameters:
direction (str) – ‘0’ for forward and ‘1’ for reverse.
- set_scale(slope=1, offset=0.1)[source]
Task - Set the PID’s internal conversion from input voltage to rotation frequency.
- Parameters:
slope (float) – Slope of the “rotation frequency vs input voltage” relationship
offset (float) – y-intercept of the “rotation frequency vs input voltage” relationship