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

Functions

void setup ()
 
int loop ()
 
void parseCommandLine (int argc, char **argv)
 
int main (int argc, char *argv[])
 

Variables

int count
 
int i
 
int iretn
 
FILE * fp
 
char cmds [15][50]
 
char buf [128]
 
char arg1str [100] = ""
 
char arg2str [100] = ""
 
int arg2int = 0
 

Function Documentation

void setup ( )

dev/ttyOS1

120  {
121  i = rw_connect("/dev/tty.usbserial-A800fcAa");
122  if (i != 0)
123  {
124  printf("Could not connect to reaction wheel in port (%s)", RW_DEVICE);
125  printf("\n");
126  exit(1);
127  } else {
128  printf("Sucessfully connected to %s\n",RW_DEVICE);
129  }
130 
131  strcpy(cmds[0], "$IMU,GET,ALL*34A\n");
132  strcpy(cmds[1], "$IMU,GET,YAW*362\n");
133  strcpy(cmds[2], "$IMU,STREAM,START*4EB\n");
134  strcpy(cmds[3], "$IMU,STREAM,STOP*4A3\n");
135  strcpy(cmds[4], "$IMU,GET,ALL*34A\n");
136  strcpy(cmds[5], "$IMU,GET,YAW*362\n");
137  strcpy(cmds[6], "$IMU,STREAM,START*4EB\n");
138  strcpy(cmds[7], "$SET,RW,SPD,-17.0*441\n");
139  strcpy(cmds[8], "$SET,RW,SPD,-17.0*441\n");
140  strcpy(cmds[9], "$SET,RW,ACC,10.0*3ED\n");
141  strcpy(cmds[10], "$SET,RW,ACC,10.0*3ED\n");
142  strcpy(cmds[11], "$SET,RW,SPD,0.0*3DC\n");
143  strcpy(cmds[12], "$SET,RW,SPD,-17.0*441\n");
144  strcpy(cmds[13], "$SET,RW,SPD,-17.0*441\n");
145  strcpy(cmds[14], "$SET,RW,ACC,10.0*3ED\n");
146  strcpy(cmds[15], "$IMU,STREAM,START*4EB\n");
147  strcpy(cmds[16], "$SET,RW,ACC,10.0*3ED\n");
148  strcpy(cmds[17], "$SET,RW,ACC,10.0*3ED\n");
149  strcpy(cmds[18], "$SET,RW,SPD,0.0*3DC\n");
150  strcpy(cmds[19], "$SET,RW,SPD,-17.0*441\n");
151  strcpy(cmds[20], "$SET,RW,SPD,-17.0*441\n");
152  strcpy(cmds[21], "$SET,RW,ACC,10.0*3ED\n");
153  strcpy(cmds[22], "$SET,RW,ACC,10.0*3ED\n");
154  strcpy(cmds[23], "$SET,RW,ACC,10.0*3ED\n");
155  strcpy(cmds[24], "$SET,RW,ACC,10.0*3ED\n");
156  strcpy(cmds[25], "$SET,RW,ACC,10,SPD,16*535\n");
157  strcpy(cmds[26], "$SET,RW,ACC,-10,SPD,0*52B\n");
158  strcpy(cmds[27], "$SET,RW,SPD,0.0*3DC\n");
159  strcpy(cmds[28], "$IMU,STREAM,START*4EB\n");
160  strcpy(cmds[29], "$SET,RW,ACC,10.0*3ED\n");
161  strcpy(cmds[30], "$SET,RW,ACC,10.0*3ED\n");
162  strcpy(cmds[31], "$SET,RW,SPD,0.0*3DC\n");
163  strcpy(cmds[32], "$IMU,STREAM,STOP*4A3\n");
164 
165  printf("Table of commands: set\n");
166 }
int i
Definition: rw_test.cpp:37
char cmds[15][50]
Definition: rw_test.cpp:39
int loop ( )
168  {
169 
170  char cmdString[100] = "";
171  long int chksum = 0;
172 
173  if (strcmp (arg1str,"SETSPD") == 0) {
174 
175  sprintf(cmdString,"$SET,RW,SPD,%s*",arg2str);
176 
177  chksum = doChecksum(cmdString);
178  printf("Checksum: %x\n",chksum); // return 441
179 
180  sprintf(cmdString,"$SET,RW,SPD,%s*%X\n",arg2str,chksum);
181  printf("Setting speed of RW to %d\n",arg2int);
182 
183  //min -18.3 max 18.3
184 
185  rw_send(cmdString,1);
186  printf("Command sucessfully sent: %s\n",cmdString);
187  }
188 
189  /*
190  while(count < 28) {
191  for(int i = 0; i < 128; i++) {
192  buf[i] = '\0';
193  }
194  rw_send(cmds[count], 1);
195  rw_getdata(buf, 128);
196  printf("Issuing command: ");
197  printf(cmds[count]);
198  printf("\n");
199  printf("Looking for data...");
200  iretn = rw_getdata(buf, 128);
201  if(iretn > 0) {
202  printf("Got output: ");
203  printf(buf);
204  }
205  if(iretn == RW_ERROR_FAILED)
206  printf("Did not get anything within a second.");
207  count++;
208  sleep(3);
209  }
210  */
211  return(0);
212 }
char arg2str[100]
Definition: rw_test.cpp:46
char arg1str[100]
Definition: rw_test.cpp:45
long int doChecksum(char *string)
Definition: razor_imu.cpp:59
int arg2int
Definition: rw_test.cpp:47
void parseCommandLine ( int  argc,
char **  argv 
)
51 {
52 
53  int argi, cmdLineParameterStringSize;
54  char cmdLineParameter[100] = "";
55 
56 
57 
58  // right number of arguments
59  if (argc == 3) {
60  //puts(argv[1]);
61 
62  // its a global variable
63  //hostPORT = atoi(argv[1]); //read port number from the command line
64 
65  cmdLineParameterStringSize = strlen(argv[0]);
66  strcpy (cmdLineParameter,argv[0]);
67 
68  strcpy (arg1str,argv[1]);
69  strcpy (arg2str,argv[2]);
70 
71  puts(arg1str);
72  puts(arg2str);
73 
74  arg2int = atoi(arg2str);
75 
76  } else {
77  puts(">> ERROR: This programs needs two arguments to run. Ex: ./rw_test SETSPD 10");
78  exit(0);
79 
80  }
81 
82 
83 }
char arg2str[100]
Definition: rw_test.cpp:46
char arg1str[100]
Definition: rw_test.cpp:45
int arg2int
Definition: rw_test.cpp:47
int main ( int  argc,
char *  argv[] 
)

doChecksum(char * string, int stringSize, char * chksum) Calculates the checksum.

Returns
the checksum
110  {
111  //fp = fopen("output.txt", "a+");
112 
113  parseCommandLine(argc,argv);
114 
115  setup();
116  loop();
117  return 0;
118 }
void setup()
Definition: rw_test.cpp:120
void parseCommandLine(int argc, char **argv)
Definition: rw_test.cpp:50
int loop()
Definition: rw_test.cpp:168

Variable Documentation

int count
int i
int iretn
FILE* fp
char cmds[15][50]
char buf[128]
char arg1str[100] = ""
char arg2str[100] = ""
int arg2int = 0