Skip to content

Commit b6be1f6

Browse files
committed
tango control libs
1 parent 6065435 commit b6be1f6

File tree

23 files changed

+1506
-9
lines changed

23 files changed

+1506
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ wheels/
4545
*.pyo
4646
__pycache__/
4747

48+
.DS_Store
49+
50+
4851
venv*/

src/dt4acc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
mongodb_ = _mongodb_(__name__)
44

5-
__all__ = ["mongodb_"]
5+
__all__ = ["mongodb_"]

src/dt4acc/core/accelerators/element_proxies.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ async def update(self, property_id: str, value, element_data):
104104
105105
Raises:
106106
ValueError: If an unknown property is specified.
107-
108-
Todo: is that Liasion management?
109-
the inverse way
110107
"""
111108
if value is not None:
112109
assert np.isfinite(value), "Value must be finite"
@@ -167,7 +164,7 @@ class KickAngleCorrectorProxy(AddOnElementProxy):
167164

168165
def __init__(self, obj, *, correction_plane, **kwargs):
169166
assert correction_plane in ["horizontal", "vertical"], "Invalid correction plane"
170-
self.correction_plane = correction_plane
167+
self.correction_planes = correction_plane
171168
super().__init__(*obj, **kwargs)
172169

173170
async def update_kick(self, *, kick_x=None, kick_y=None, element_data):
@@ -179,7 +176,7 @@ async def update_kick(self, *, kick_x=None, kick_y=None, element_data):
179176
kick_y: Vertical kick angle.
180177
element_data: Element-specific conversion data.
181178
"""
182-
element = self._obj
179+
element, = self._obj
183180
kick_angles = self._obj.KickAngle.copy()
184181
if kick_x is not None:
185182
kick_angles[0] = kick_x * element_data.hw2phys

src/dt4acc/custom_epics/data/querries.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import sys
12
import os
23

4+
# sys.path.append('/Volumes/MyDrive/Bessy/dt4acc/dt4acc/src')
35
import pymongo
46

57
from dt4acc import mongodb_

src/dt4acc/custom_epics/ioc/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ def get_property_id(pv_name):
9292
elif ':rdbk' in pv_name:
9393
return 'rdbk'
9494
else:
95-
return None
95+
return None

src/dt4acc/custom_epics/utils/bpm_mimicry.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import functools
22
import os
3+
import sys
4+
# sys.path.append('/Volumes/MyDrive/Bessy/dt4acc/dt4acc/src')
35

46
import numpy as np
57
import pandas as pd
68
import pymongo
79
from bact_device_models.devices.bpm_elem_libera import BPMElement, BPMElementPosition, BPMElementList
810
from bact_device_models.filters.bpm_calibration import BPMCalibrationPlane
911

10-
from ...core.model.orbit import Orbit
11-
from ...core.utils.logger import get_logger
12+
13+
from dt4acc.core.model.orbit import Orbit
14+
from dt4acc.core.utils.logger import get_logger
1215

1316
MONGO_URI = os.environ.get("MONGODB_URL", "mongodb://localhost:27017")
1417
DB_NAME = os.environ.get("MONGODB_DB", "bessyii")

src/dt4acc/custom_tango/README.md

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# Tango Device Server Setup
2+
3+
This repository contains a Tango Device Server implementation for controlling various accelerator devices such as magnets, power converters, BPMs, and orbit devices.
4+
5+
## Prerequisites
6+
7+
Ensure you have the following dependencies installed before running the Tango server:
8+
9+
- **Python** (>=3.7)
10+
- **PyTango** (Tango Controls Python API)
11+
- **MariaDB** (for the Tango Database)
12+
- **NumPy** (for numerical computations)
13+
14+
Install the required Python dependencies:
15+
```bash
16+
pip install pytango numpy
17+
```
18+
19+
Alternatively, you can install `PyTango` using Conda:
20+
```bash
21+
conda create --channel conda-forge --name pytango-env python=3.11 pytango
22+
conda activate pytango-env
23+
```
24+
25+
### Cloning and Running the Tango Database Repository
26+
To use the official Tango Database, clone the repository with submodules:
27+
```bash
28+
git clone --recursive https://gitlab.com/tango-controls/TangoDatabase.git
29+
```
30+
Then navigate into the cloned repository:
31+
```bash
32+
cd TangoDatabase
33+
```
34+
Follow the repository instructions to set up and run the Tango Database.
35+
36+
### Testing the PyTango Installation
37+
To verify that `PyTango` is installed correctly, run the following command:
38+
```bash
39+
python -c "import tango; print(tango.Release.version)"
40+
```
41+
If the installation is successful, this will print the installed Tango version.
42+
43+
### Starting the Tango Database Server
44+
Before running the Tango device server, you need to start the Tango Database:
45+
46+
```bash
47+
sudo DataBaseds 2 -ORBendPoint giop:tcp::10000
48+
```
49+
This command starts the Tango Database Service on port `10000`. Ensure it is running before proceeding.
50+
51+
To install additional Tango tools such as `tango-test`, `jive`, and `tango-database` from Conda:
52+
```bash
53+
conda install -c conda-forge tango-test jive tango-database
54+
```
55+
56+
## Setting Up the Tango Database
57+
58+
Before running the server, initialize the Tango Database:
59+
60+
```python
61+
from dt4acc.custom_tango.utils.tango_util import initialize_tango_database
62+
63+
# Initialize Tango Database
64+
initialize_tango_database()
65+
```
66+
67+
## Running the Tango Server
68+
69+
To start the Tango device server, navigate to the project directory and run the following command:
70+
71+
```bash
72+
python tango_server.py test
73+
```
74+
75+
### What Happens When You Start the Server?
76+
1. The server initializes the Tango database.
77+
2. Registers the device classes: `MagnetDevice`, `PowerConverterDevice`, `BPMDevice`, `OrbitDevice`, `TwissDevice`, `OtherDevice`.
78+
3. Starts the Tango device server to manage and interact with these devices.
79+
80+
## Available Tango Devices
81+
82+
### Magnet Device
83+
Handles magnet attributes like:
84+
- `Cm_set` (magnetic field strength)
85+
- `im_I` (read-only measured current)
86+
- `x_set` & `y_set` (position setpoints)
87+
88+
### Power Converter Device
89+
Manages power converters with attributes:
90+
- `set` (setpoint value)
91+
- `rdbk` (readback value)
92+
93+
### Orbit Device
94+
Monitors beam orbits with attributes:
95+
- `orbit_x`, `orbit_y` (orbit coordinates)
96+
- `beam_data` (2048-sample beam data array)
97+
98+
### Twiss Device
99+
Handles Twiss parameters like:
100+
- `x_alpha`, `x_beta`, `x_nu`
101+
- `y_alpha`, `y_beta`, `y_nu`
102+
103+
### Other Device
104+
Handles miscellaneous parameters including:
105+
- `master_clock_freq` (clock frequency)
106+
- `current` (current measurement)
107+
108+
### BPM Device
109+
Handles Beam Position Monitor (BPM) data with attributes:
110+
- `bpm_bdata` (beam data array)
111+
- `bpm_count` (BPM count)
112+
113+
## Pushing Data to Tango Devices
114+
115+
### Pushing Orbit Data
116+
To push beam orbit data to the Tango Device:
117+
118+
```bash
119+
python push_orbit.py
120+
```
121+
This script:
122+
- Generates random orbit data.
123+
- Pushes it to the Tango server.
124+
- Reads the updated orbit data back from the Tango server.
125+
126+
### Pushing BPM Data
127+
To push BPM (Beam Position Monitor) data:
128+
129+
```bash
130+
python push_bpm.py
131+
```
132+
This script:
133+
- Mimics BPM behavior.
134+
- Pushes BPM readings to Tango.
135+
- Reads back BPM data from the server.
136+
137+
### Pushing Twiss Parameters
138+
To update Twiss parameters:
139+
140+
```bash
141+
python push_twiss.py
142+
```
143+
This script:
144+
- Simulates Twiss parameter values.
145+
- Pushes them to the Tango server.
146+
- Reads the updated values from the server.
147+
148+
## Monitoring the Heartbeat
149+
To ensure the server is running correctly, start the heartbeat monitor:
150+
151+
```bash
152+
python heartbeat.py
153+
```
154+
This script:
155+
- Calls `heart_beat()` every second to check server status.
156+
- Logs any errors encountered.
157+
- Can be stopped with `CTRL + C`.
158+
159+
## Interacting with Devices
160+
Once the server is running, you can interact with devices using `Jive` (Tango graphical interface) or `TangoTest` CLI:
161+
162+
To read attributes:
163+
```bash
164+
tango_read tango://localhost:10000/test/MagnetDevice_1/Cm_set
165+
```
166+
167+
To write attributes:
168+
```bash
169+
tango_write tango://localhost:10000/test/MagnetDevice_1/Cm_set 5.0
170+
```
171+
172+
## Stopping the Server
173+
To stop the running Tango server, use:
174+
```bash
175+
CTRL + C
176+
```
177+
178+
## Troubleshooting
179+
- Ensure that the Tango database is running (`TangoDB` service must be active).
180+
- Use `Jive` to check registered devices and their statuses.
181+
- Verify that `sys.path.append()` correctly points to the required modules.
182+
183+
---
184+
185+
This setup allows you to run and interact with the Tango device server seamlessly. Let me know if you need any modifications!
186+

src/dt4acc/custom_tango/__init__.py

Whitespace-only changes.

src/dt4acc/custom_tango/check.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from tango import DeviceProxy, DevFailed
2+
3+
device_name = "tango_server/test/MagnetDevice_VS3M2T8R"
4+
5+
try:
6+
magnet = DeviceProxy(device_name)
7+
print(f"{device_name} exists and is reachable!")
8+
print("Ping response:", magnet.ping(), "ms")
9+
except DevFailed as e:
10+
print(f"Device {device_name} is NOT found or not running.")
11+
print(e)

0 commit comments

Comments
 (0)