|
| 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 | + |
0 commit comments