Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vefb Changes #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions virtac/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ used by convention at Diamond for simulations) to avoid conflict with the same
PVs on the live machine.


Start the virtual accelerator
-----------------------------
Starting the virtual accelerator:
---------------------------------

Run the virtac under the development EPICS port::

Expand Down Expand Up @@ -49,6 +49,30 @@ Leave the server running and in a new terminal update the EPICS port::
In this new terminal you are then free to address the simulator as you would
the live machine, either through Pytac or by directly accessing the PVs.

Command Line Options:
---------------------

Usage::

virtac [-h] [--disable-emittance] [--enable-tfb] [--verbose] [ring_mode]

Positional arguments::

ring_mode The ring mode to be used, e.g., IO4 or DIAD

Optional arguments::

-h, --help show this help message and exit
-d, --disable-emittance
Disable the simulator's time-consuming emittance
calculation
-t, --enable-tfb Simulate extra dummy hardware to be used by the Tune
Feedback system
-v, --verbose Increase output and logging verbosity

N.B. The relatively slow emittance calculation is enabled by default, if the
virtac isn't as performant as your would like try disabling it using ``-d``.

Feedback Records:
-----------------

Expand Down
22 changes: 15 additions & 7 deletions virtac/atip_ioc_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@

def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("ring_mode", nargs="?", type=str, help="Ring mode name")
parser.add_argument(
"--disable-emittance",
"ring_mode",
nargs="?",
type=str,
help="The ring mode to be used, e.g., IO4 or DIAD",
)
parser.add_argument(
"-d",
help="disable the simulator's time-consuming emittance calculation",
"--disable-emittance",
help="Disable the simulator's time-consuming emittance calculation",
action="store_true",
)
parser.add_argument(
"--enable-tfb",
"-t",
help="simulate extra dummy hardware to be used by the Tune Feedback system",
"--enable-tfb",
help="Simulate extra dummy hardware to be used by the Tune Feedback system",
action="store_true",
)
parser.add_argument(
"--verbose", "-v", help="increase output verbosity", action="store_true"
"-v",
"--verbose",
help="Increase output and logging verbosity",
action="store_true",
)
return parser.parse_args()

Expand Down Expand Up @@ -63,7 +71,7 @@ def main():
DATADIR / ring_mode / "feedback.csv",
DATADIR / ring_mode / "mirrored.csv",
DATADIR / ring_mode / "tunefb.csv",
not args.disable_emittance,
args.disable_emittance,
)

# Warn if set to default EPICS port(s) as this will likely cause PV conflicts.
Expand Down
22 changes: 14 additions & 8 deletions virtac/atip_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def _create_records(self, limits_csv, disable_emittance):
float(line["upper"]),
float(line["lower"]),
int(line["precision"]),
float(line["drive high"]),
float(line["drive low"]),
)
bend_in_record = None
for element in self.lattice:
Expand All @@ -172,8 +174,8 @@ def _create_records(self, limits_csv, disable_emittance):
"b0", units=pytac.ENG, data_source=pytac.SIM
)
get_pv = element.get_pv_name("b0", pytac.RB)
upper, lower, precision = limits_dict.get(
get_pv, (None, None, None)
upper, lower, precision, drive_high, drive_low = limits_dict.get(
get_pv, (None, None, None, None, None)
)
builder.SetDeviceName(get_pv.split(":", 1)[0])
in_record = builder.aIn(
Expand All @@ -185,12 +187,14 @@ def _create_records(self, limits_csv, disable_emittance):
initial_value=value,
)
set_pv = element.get_pv_name("b0", pytac.SP)
upper, lower, precision = limits_dict.get(
set_pv, (None, None, None)
upper, lower, precision, drive_high, drive_low = limits_dict.get(
set_pv, (None, None, None, None, None)
)
builder.SetDeviceName(set_pv.split(":", 1)[0])
out_record = builder.aOut(
set_pv.split(":", 1)[1],
DRVH=drive_high,
DRVL=drive_low,
LOPR=lower,
HOPR=upper,
PREC=precision,
Expand All @@ -210,8 +214,8 @@ def _create_records(self, limits_csv, disable_emittance):
field, units=pytac.ENG, data_source=pytac.SIM
)
get_pv = element.get_pv_name(field, pytac.RB)
upper, lower, precision = limits_dict.get(
get_pv, (None, None, None)
upper, lower, precision, drive_high, drive_low = limits_dict.get(
get_pv, (None, None, None, None, None)
)
builder.SetDeviceName(get_pv.split(":", 1)[0])
in_record = builder.aIn(
Expand All @@ -228,12 +232,14 @@ def _create_records(self, limits_csv, disable_emittance):
except HandleException:
self._rb_only_records.append(in_record)
else:
upper, lower, precision = limits_dict.get(
set_pv, (None, None, None)
upper, lower, precision, drive_high, drive_low = limits_dict.get(
set_pv, (None, None, None, None, None)
)
builder.SetDeviceName(set_pv.split(":", 1)[0])
out_record = builder.aOut(
set_pv.split(":", 1)[1],
DRVH=drive_high,
DRVL=drive_low,
LOPR=lower,
HOPR=upper,
PREC=precision,
Expand Down
26 changes: 22 additions & 4 deletions virtac/create_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ def generate_pv_limits(lattice):
"""Get the control limits and precision values from the live machine for
all normal PVS.
"""
data = [("pv", "upper", "lower", "precision")]
data = [("pv", "upper", "lower", "precision", "drive high", "drive low")]
for element in lattice:
for field in element.get_fields()[pytac.SIM]:
pv = element.get_pv_name(field, pytac.RB)
ctrl = caget(pv, format=FORMAT_CTRL)
data.append(
(pv, ctrl.upper_ctrl_limit, ctrl.lower_ctrl_limit, ctrl.precision)
(
pv,
ctrl.upper_ctrl_limit,
ctrl.lower_ctrl_limit,
ctrl.precision,
ctrl.upper_disp_limit,
ctrl.lower_disp_limit,
)
)
try:
pv = element.get_pv_name(field, pytac.SP)
Expand All @@ -91,7 +98,14 @@ def generate_pv_limits(lattice):
else:
ctrl = caget(pv, format=FORMAT_CTRL)
data.append(
(pv, ctrl.upper_ctrl_limit, ctrl.lower_ctrl_limit, ctrl.precision)
(
pv,
ctrl.upper_ctrl_limit,
ctrl.lower_ctrl_limit,
ctrl.precision,
ctrl.upper_disp_limit,
ctrl.lower_disp_limit,
)
)
return data

Expand Down Expand Up @@ -254,7 +268,7 @@ def write_data_to_file(data, filename, ring_mode):
)
with open(filepath, "w", newline="") as file:
csv_writer = csv.writer(file)
csv_writer.writerows(data)
csv_writer.writerows([data[0]] + sorted(data[1:]))


def parse_arguments():
Expand Down Expand Up @@ -296,12 +310,16 @@ def parse_arguments():
args = parse_arguments()
lattice = atip.utils.loader(args.ring_mode)
all_elements = atip.utils.preload(lattice)
print("Creating feedback PVs CSV file.")
data = generate_feedback_pvs(all_elements)
data.extend(generate_bba_pvs(all_elements)[1:])
write_data_to_file(data, args.feedback, args.ring_mode)
print("Creating limits PVs CSV file.")
data = generate_pv_limits(lattice)
write_data_to_file(data, args.limits, args.ring_mode)
print("Creating mirrored PVs CSV file.")
data = generate_mirrored_pvs(lattice)
write_data_to_file(data, args.mirrored, args.ring_mode)
print("Creating tune PVs CSV file.")
data = generate_tune_pvs(lattice)
write_data_to_file(data, args.tune, args.ring_mode)
Loading
Loading