00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
#include <simion/remote.h>
00014
00015
#include <iostream>
00016
#include <cmath>
00017
00018 inline double my_min(
double a,
double b) {
return a < b ? a : b;}
00019 inline double my_max(
double a,
double b) {
return a < b ? a : b;}
00020
00021
using namespace std;
00022
using namespace simion;
00023
00024 double buncher_voltage = 900;
00025 double switch_time = 1.7;
00026
00027 bool update_flag =
true;
00028
00029 void time_step(
00030
double ion_time_of_flight,
double ion_time_step,
00031
double& ion_time_step_out)
00032 {
00033 ion_time_step_out = ion_time_step;
00034
00035
if(ion_time_of_flight <
switch_time)
00036 ion_time_step_out =
my_min(ion_time_step,
switch_time-ion_time_of_flight);
00037
00038
00039
00040 }
00041
00042 void buncher_voltage_control(
00043
double ion_time_of_flight,
00044
double& adj_elect01_out)
00045 {
00046 adj_elect01_out =
00047 ion_time_of_flight <
switch_time ?
buncher_voltage : 0;
00048
00049
00050
00051 }
00052
00053 void other_stuff(
00054
double ion_time_of_flight,
double ion_color,
00055
double& update_pe_surface_out,
double& ion_color_out,
double& do_mark)
00056 {
00057 update_pe_surface_out = 0;
00058 ion_color_out = ion_color;
00059 do_mark = 0;
00060
00061
if(fabs(ion_time_of_flight -
switch_time) < 1E-12) {
00062 ion_color_out = 3;
00063 do_mark = 1;
00064
update_flag =
true;
00065 }
00066
else if(
update_flag) {
00067
update_flag =
false;
00068 update_pe_surface_out = 1;
00069 }
00070
00071
00072
00073
00074 }
00075
00076
00077 int main()
00078 {
00079 cout <<
"Running buncher server in background...\n";
00080
00081
00082
SLRemote remote;
00083
00084
00085
00086 remote.
handler(1,
slremote_handler(
time_step));
00087 remote.
handler(2,
slremote_handler(
buncher_voltage_control));
00088 remote.
handler(3,
slremote_handler(
other_stuff));
00089
00090
00091 remote.
run();
00092
00093
00094 remote.
wait_for_run_complete();
00095
00096
return 0;
00097 }
00098
00099