COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
vmt35_test_enable.cpp File Reference
#include <stdio.h>
#include <unistd.h>
#include "vmt35_lib.h"
#include "microstrain_lib.h"
Include dependency graph for vmt35_test_enable.cpp:

Functions

void getVoltageDac (int channel)
 
void parseCommandLine (int argc, char **argv)
 
void reset ()
 
int main (int argc, char *argv[])
 

Variables

char arg1str [100] = ""
 
char arg2str [100] = ""
 
char arg3str [100] = ""
 
float arg2num = 0
 
float arg3num = 0
 
float miliamps = 0
 

Function Documentation

void getVoltageDac ( int  channel)
293  {
294  uint16_t voltagedacrx = 0;
295  float volts = 0;
296 
297  vmt35_get_voltage(channel,&voltagedacrx);
298  volts = voltagedacrx/4095.0*29.0;
299  printf(">> Voltage from DAC: %d, %f V\n",voltagedacrx,volts);
300 }
void parseCommandLine ( int  argc,
char **  argv 
)
304 {
305 
306  int cmdLineParameterStringSize; //argi,
307  char cmdLineParameter[100] = "";
308 
309 
310 
311  switch ( argc ) {
312  //case 1: // Note the colon, not a semicolon
313  //playgame();
314  // break;
315  case 2: // Note the colon, not a semicolon
316  //loadgame();
317  strcpy (arg1str,argv[1]);
318  break;
319  case 3: // Note the colon, not a semicolon
320 
321  // ./vmt35_test_enable RUN 0.1
322  strcpy (arg1str,argv[1]);
323  strcpy (arg2str,argv[2]);
324  arg2num = atof(arg2str);
325  break;
326  case 4: // Note the colon, not a semicolon
327  //puts(argv[1]);
328 
329  // ./vmt35_test_enable SETCH 0 0.1
330 
331  // its a global variable
332  //hostPORT = atoi(argv[1]); //read port number from the command line
333 
334  cmdLineParameterStringSize = strlen(argv[0]);
335  strcpy (cmdLineParameter,argv[0]);
336 
337  strcpy (arg1str,argv[1]);
338  strcpy (arg2str,argv[2]);
339  strcpy (arg3str,argv[3]);
340 
341  //puts(arg1str);
342  //puts(arg2str);
343 
344  arg2num = atof(arg2str);
345  arg3num = atof(arg3str);
346  break;
347  default: // Note the colon, not a semicolon
348  //cout<<"Error, bad input, quitting\n";
349  puts(">> ERROR: This programs needs two arguments to run. Ex: ./vmt35_test_enable SETCH 0 0.1");
350  exit(0);
351 
352  break;
353  }
354 
355 }
char arg1str[100]
Definition: vmt35_test_enable.cpp:35
char arg3str[100]
Definition: vmt35_test_enable.cpp:37
float arg3num
Definition: vmt35_test_enable.cpp:39
float arg2num
Definition: vmt35_test_enable.cpp:38
char arg2str[100]
Definition: vmt35_test_enable.cpp:36
void reset ( )
285  {
286  printf(">> Reseting ... ");
287  if (vmt35_reset()==0)
288  printf("Done!\n");
289 
290  sleep(2);
291 }
int main ( int  argc,
char *  argv[] 
)
48 {
49 
50  int iretn; //, handle;
51  //int16_t icurrent;
52  //uint16_t ivoltage;
53  float current;
54  int channel;
55  uint16_t voltagedac,voltagedacrx;
56  //rvector magfield, mtrvec;
57  //vmt35_telemetry telem;
58  //int volts = 0;
59 
60 
61  parseCommandLine(argc,argv);
62 
63 // iretn = vmt35_connect((char *)"dev_vmt35");
64  iretn = vmt35_connect((char *)"/dev/ttyUSB4");
65  //0403:e4ea
66 
67  if (iretn < 0)
68  {
69  printf("Error: vmt35_connect() %d\n",iretn);
70  exit (iretn);
71  }
72 
73 
74  //A2 01 00 00 5C
75 
76 
77  //printf(">> Get ready ...\n");
78  //sleep(2);
79 
80 
81 
82  if (strcmp (arg1str,"RESET") == 0) {
83  reset();
84  }
85 
86 
87 
88  // set Set Torquer Supply Voltage is not really working
89  // sets input voltage (29V) from system to Torque Rod
90  // as long as this command is activated!!!
91  //vmt35_set_percent_voltage(0,0);
92  //vmt35_set_percent_voltage(1,0);
93  //vmt35_set_percent_voltage(2,0);
94  //vmt35_set_percent_voltage(2,25);
95  //vmt35_set_percent_voltage(2,50);
96 
97 
98  if (strcmp (arg1str,"SETVOLTAGE") == 0) {
99  vmt35_set_percent_voltage(0,99);
100  vmt35_set_percent_voltage(1,99);
101  vmt35_set_percent_voltage(2,99);
102  }
103 
104 
105 
106 
107  //vmt35_set_percent_voltage(0,100);
108  //vmt35_set_percent_voltage(1,100);
109 
110  if (strcmp (arg1str,"RUN") == 0) {
111 
112  current = arg2num ;
113  printf(">> Enabling Supply Voltage ... ");
114  if (vmt35_enable()==0)
115  printf("Done\n");
116 
117  //sleep(1);
118 
119  vmt35_set_percent_voltage(0,99);
120  vmt35_set_percent_voltage(1,99);
121  vmt35_set_percent_voltage(2,99);
122 
123  printf(">> Setting Supply Current to Ch 0, %f A ... ",current);
124  vmt35_set_amps(0,current);
125  printf("Done\n");
126 
127  //sleep(1);
128 
129  printf(">> Setting Supply Current to Ch 1, %f A ... ",current);
130  vmt35_set_amps(1,current);
131  printf("Done\n");
132 
133  //sleep(1);
134 
135  printf(">> Setting Supply Current to Ch 2, %f A ... ",current);
136  vmt35_set_amps(2,current);
137  printf("Done\n");
138 
139  //sleep(5);
140 
141 
142  }
143 
144 
145  if (strcmp (arg1str,"SETCH") == 0) {
146 
147  channel = arg2num;
148  current = ceilf(arg3num * 1000000) / 1000000;
149 
150 
151  printf(">> Enabling Supply Voltage ... ");
152  if (vmt35_enable()==0)
153  printf("Done\n");
154 
155  //sleep(1);
156 
157  vmt35_set_percent_voltage(channel,99);
158 
159  printf(">> Setting Supply Current to Ch %d, %f A ... ",(int)channel, current);
160  vmt35_set_amps(channel,current);
161  //vmt35_set_miliamps(channel,miliamps);
162  printf("Done\n");
163 
164  }
165 
166  if (strcmp (arg1str,"SETCDAC") == 0) {
167 
168  channel = arg2num;
169  current = (uint16_t)arg3num;
170 
171  printf(">> Enabling Supply Voltage ... ");
172  if (vmt35_enable()==0)
173  printf("Done\n");
174 
175  //sleep(1);
176 
177  vmt35_set_percent_voltage(channel,99);
178 
179  printf(">> Setting Supply Current to Ch %d, %d DAC ... ",(int)channel, (int)current);
180  vmt35_set_current_dac(channel,current);
181  //vmt35_set_miliamps(channel,miliamps);
182  printf("Done\n");
183 
184  }
185 
186 
187  if (strcmp (arg1str,"GETV") == 0) {
188 
189  channel = arg2num;
190  getVoltageDac(channel);
191 
192 
193  }
194 
195  if (strcmp (arg1str,"GETAMP") == 0) {
196 
197  int16_t amps = 0;
198 
199  channel = arg2num;
200  vmt35_get_current(channel,&amps);
201  current = amps;
202  printf(">> Got current: %d (raw) %f (A)\n",amps,current);
203 
204 
205  }
206 
207 
208  if (strcmp (arg1str,"SETVDAC") == 0) {
209 
210  voltagedacrx = 0;
211  channel = arg2num;
212  voltagedac = (uint16_t)arg3num;
213 
214  printf(">> Enabling Supply Voltage ... ");
215  if (vmt35_enable()==0)
216  printf("Done\n");
217 
218  printf(">> Setting Supply Voltage to Ch %d, %d DAC ... ",(int)channel, (int)voltagedac);
219  //vmt35_set_current_dac(channel,current);
220  //vmt35_set_miliamps(channel,miliamps);
221  vmt35_set_voltage(channel,voltagedac);
222  printf("Done\n");
223 
224  vmt35_get_voltage(channel,&voltagedacrx);
225  printf(">> Voltage from DAC: %d\n",voltagedacrx);
226 
227 
228 
229  }
230 
231 
232  if (strcmp (arg1str,"SETAMP") == 0) {
233  printf(">> Setting Supply Current ... ");
234  current = arg3num;
235  vmt35_set_amps((int)arg2num,current);
236  printf("Done\n");
237 
238  }
239 
240  if (strcmp (arg1str,"DISABLE") == 0) {
241  printf(">> Disabling Supply Voltage ... ");
242  vmt35_disable();
243  printf("Done\n");
244  }
245 
246  if (strcmp (arg1str,"ENABLE") == 0) {
247  printf(">> Enabling Supply Voltage ... ");
248  if (vmt35_enable()==0)
249  printf("Done\n");
250  }
251 
252 exit (0);
253  while (0)
254  {
255  vmt35_set_amps(0,current);
256  vmt35_set_amps(1,current);
257  vmt35_set_amps(2,current);
258 
259 
260 
261  /*
262  vmt35_get_telemetry(&telem);
263  printf("%hu %hu %hu %d %d %d %hu %hu\n",telem.status,telem.count,telem.invalidcount,telem.daca,telem.dacb,telem.dacc,telem.temp,telem.voltage);
264 
265  sleep(2);
266  vmt35_disable();
267 */
268  /*
269  current = 0.;
270  vmt35_set_amps(0,current);
271  vmt35_set_amps(1,current);
272  vmt35_set_amps(2,current);
273  */
274  // vmt35_get_telemetry(&telem);
275  // printf("%hu %hu %hu %d %d %d %hu %hu\n",telem.status,telem.count,telem.invalidcount,telem.daca,telem.dacb,telem.dacc,telem.temp,telem.voltage);
276 
277  }
278 
279  //vmt35_get_current(0,&icurrent);
280 
281 }
char arg1str[100]
Definition: vmt35_test_enable.cpp:35
int iretn
Definition: rw_test.cpp:37
void getVoltageDac(int channel)
Definition: vmt35_test_enable.cpp:293
static antstruc current
Definition: agent_antenna.cpp:161
float arg3num
Definition: vmt35_test_enable.cpp:39
void parseCommandLine(int argc, char **argv)
Definition: vmt35_test_enable.cpp:303
float arg2num
Definition: vmt35_test_enable.cpp:38
void reset()
Definition: vmt35_test_enable.cpp:285

Variable Documentation

char arg1str[100] = ""
char arg2str[100] = ""
char arg3str[100] = ""
float arg2num = 0
float arg3num = 0
float miliamps = 0