Go to the documentation of this file.00001 #include <fcntl.h>
00002 #include <stdio.h>
00003 #include <unistd.h>
00004 #include <sys/ioctl.h>
00005 #include <sys/types.h>
00006 #include <sys/stat.h>
00007
00008 #include <signal.h>
00009
00010 #include "driver/urbtc.h"
00011 #include "driver/urobotc.h"
00012
00013 #undef __BIG_ENDIAN
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 buf;
00023 struct uout obuf;
00024 struct ccmd cmd;
00025 int i,j=0;
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
00039 cmd.retval = 0 ;
00040 cmd.setoffset = CH0 | CH1 | CH2 | CH3;
00041 cmd.setcounter = CH0 | CH1 | CH2 | CH3;
00042 cmd.resetint = CH0 | CH1 | CH2 | CH3;
00043
00044
00045 cmd.selin = SET_SELECT | SET_CH2_HIN;
00046 cmd.dout = 0;
00047
00048
00049 cmd.selout = SET_SELECT | CH2;
00050
00051 cmd.offset[0] = cmd.offset[1] = cmd.offset[2] = cmd.offset[3] = 32768;
00052 cmd.counter[0] = cmd.counter[1] = cmd.counter[2] = cmd.counter[3] = 0;
00053 cmd.posneg = SET_POSNEG | CH0| CH1 | CH2 | CH3;
00054 cmd.breaks = SET_BREAKS | CH0 | CH1 | CH2 | CH3;
00055 cmd.magicno = 0x00;
00056
00057 cmd.wrrom = 0;
00058
00059 if (ioctl(fd, URBTC_COUNTER_SET) < 0){
00060 fprintf(stderr, "ioctl: URBTC_COUNTER_SET error\n");
00061 exit(1);
00062 }
00063
00064 if (write(fd, &cmd, sizeof(cmd)) < 0) {
00065 fprintf(stderr, "write error\n");
00066 exit(1);
00067 }
00068
00069 for (i=0; i<4; i++) {
00070 obuf.ch[i].x = 0;
00071 obuf.ch[i].d = 0;
00072 obuf.ch[i].kp = 10;
00073 obuf.ch[i].kpx = 1;
00074 obuf.ch[i].kd = 0;
00075 obuf.ch[i].kdx = 1;
00076 obuf.ch[i].ki = 0;
00077 obuf.ch[i].kix = 1;
00078 }
00079
00080
00081 if (ioctl(fd, URBTC_DESIRE_SET) < 0){
00082 fprintf(stderr, "ioctl: URBTC_DESIRE_SET error\n");
00083 exit(1);
00084 }
00085
00086 if (ioctl(fd, URBTC_CONTINUOUS_READ) < 0){
00087 fprintf(stderr, "ioctl: URBTC_CONTINUOUS_READ error\n");
00088 exit(1);
00089 }
00090
00091 if (ioctl(fd, URBTC_BUFREAD) < 0){
00092 fprintf(stderr, "ioctl: URBTC_CONTINUOUS_READ error\n");
00093 exit(1);
00094 }
00095
00096 while(quit_flag) {
00097
00098 unsigned short x_d= 100 * sin(j*3.14/655.360);
00099 x_d <<= 5;
00100
00101
00102 obuf.ch[2].x = x_d;
00103
00104 if (write(fd, &obuf, sizeof(obuf)) > 0) {
00105 j++;
00106
00107 } else {
00108 printf("write err\n");
00109 break;
00110 }
00111 }
00112
00113 close(fd);
00114
00115 return 0;
00116 }
00117
00118 void exit_program(sig, code, scp, addr)
00119 int sig;
00120 int code;
00121 struct sigcontext *scp;
00122 char *addr;
00123 {
00124 quit_flag = 0;
00125 fprintf(stderr, "kill signal is received\n");
00126 }