Go to the documentation of this file.00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include <unistd.h>
00005 #include <sys/ioctl.h>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 #include <fcntl.h>
00009
00010 #include <signal.h>
00011
00012 #include "driver/urbtc.h"
00013 #include "driver/urobotc.h"
00014
00015 void exit_program();
00016
00017 int quit_flag = 1;
00018 int fd;
00019
00020 int main(int argc, char **argv)
00021 {
00022 struct uin ibuf;
00023 struct uout obuf;
00024 struct ccmd cmd;
00025 int i;
00026
00027 char *dev = "/dev/urbtc0";
00028
00029 signal(SIGINT, exit_program);
00030
00031 if (argc>1)
00032 dev = argv[1];
00033
00034 if ((fd = open(dev, O_RDWR)) == -1) {
00035 fprintf(stderr, "%s: Open error\n", dev);
00036 exit(1);
00037 }
00038 cmd.retval = 0 ;
00039 cmd.setoffset = CH0 | CH1 | CH2 | CH3;
00040 cmd.setcounter = CH0 | CH1 | CH2 | CH3;
00041 cmd.resetint = CH0 | CH1 | CH2 | CH3;
00042
00043 cmd.selin = CH0 | CH1 | CH2 | CH3 | SET_SELECT;
00044
00045 #if 0
00046 cmd.dout = DOUT0 | DOUT1 | DOUT2 | DOUT3;
00047 #endif
00048 cmd.dout = 0;
00049
00050 cmd.selout = SET_SELECT | CH0 | CH1 | CH2 | CH3;
00051
00052
00053 #if __BYTE_ORDER == __LITTLE_ENDIAN
00054 cmd.offset[0] = cmd.offset[1] = cmd.offset[2] = cmd.offset[3] = 0x7fff;
00055 cmd.counter[0] = cmd.counter[1] = cmd.counter[2] = cmd.counter[3] = 0;
00056 cmd.magicno = 0x00;
00057 #else
00058 cmd.offset[0] = cmd.offset[1] = cmd.offset[2] = cmd.offset[3] = 0xff7f;
00059 cmd.counter[0] = cmd.counter[1] = cmd.counter[2] = cmd.counter[3] = 0;
00060 cmd.magicno = 0x00;
00061 #endif
00062
00063 cmd.posneg = SET_POSNEG | CH0 | CH1 | CH2 | CH3;
00064 cmd.breaks = SET_BREAKS | CH0 | CH1 | CH2 | CH3;
00065
00066 cmd.wrrom = 0;
00067
00068
00069
00070 if (ioctl(fd, URBTC_COUNTER_SET) < 0){
00071 fprintf(stderr, "ioctl: URBTC_COUNTER_SET error\n");
00072 exit(1);
00073 }
00074
00075
00076
00077 if (write(fd, &cmd, sizeof(cmd)) < 0) {
00078 fprintf(stderr, "write error\n");
00079 exit(1);
00080 }
00081
00082 #if 0
00083
00084 if (ioctl(fd, URBTC_DESIRE_SET) < 0){
00085 fprintf(stderr, "ioctl: URBTC_DESIRE_SET error\n");
00086 exit(1);
00087 }
00088 #endif
00089
00090 for (i=0; i<4; i++) {
00091 #if __BYTE_ORDER == __LITTLE_ENDIAN
00092 obuf.ch[i].x = 0;
00093 obuf.ch[i].d = 0;
00094 obuf.ch[i].kp = 0;
00095 obuf.ch[i].kpx = 1;
00096 obuf.ch[i].kd = 0;
00097 obuf.ch[i].kdx = 1;
00098 obuf.ch[i].ki = 0;
00099 obuf.ch[i].kix = 1;
00100 #else
00101 obuf.ch[i].x = 0;
00102 obuf.ch[i].d = 0;
00103 obuf.ch[i].kp = 0;
00104 obuf.ch[i].kpx = 0x0100;
00105 obuf.ch[i].kd = 0;
00106 obuf.ch[i].kdx = 0x0100;
00107 obuf.ch[i].ki = 0;
00108 obuf.ch[i].kix = 0x0100;
00109 #endif
00110 }
00111
00112 i = 0;
00113 while(quit_flag) {
00114 unsigned short a = 300.0*sin(i*3.14/655.360) + 512.0;
00115 a <<= 5;
00116
00117
00118 cmd.offset[0] = cmd.offset[1] = cmd.offset[2] = cmd.offset[3] = a;
00119
00120 if (ioctl(fd, URBTC_COUNTER_SET) < 0){
00121 fprintf(stderr, "ioctl: URBTC_COUNTER_SET error\n");
00122 exit(1);
00123 }
00124
00125
00126 if (write(fd, &cmd, sizeof(cmd)) > 0) {
00127 i += 1;
00128 } else {
00129 fprintf(stderr, "write cmd error\n");
00130 exit(1);
00131 }
00132
00133 }
00134
00135
00136 close(fd);
00137
00138 return 0;
00139 }
00140
00141 void exit_program(sig, code, scp, addr)
00142 int sig;
00143 int code;
00144 struct sigcontext *scp;
00145 char *addr;
00146 {
00147 quit_flag = 0;
00148 fprintf(stderr, "kill signal is received\n");
00149 }
00150
00151
00152
00153
00154