動作確認


帰省前にギリギリで、Micro 2BBとPicoサーボモータの動作確認が出来ました。
これで、出かけた後でも今まで作ったプログラムの移植が可能です。
(実は一回だけ接続ミスをしましたが)

下記は動作確認のために書いたもの。
すごく簡単なプログラムですが、ま、とりあえず動いたので。

----

#include <stdio.h>
#include
<fnctl.h>
#include <termio.h>

int main(void)
{
int fd;
struct termios tio;
unsigned char buf[1024]={255,3,4,2,1,127,50};
int v;

if ((fd = open("/dev/ttyUSB0", O_WRONLY))
{
fprintf(stderr, "open error\n");
exit(1);
}
bzero(&tio, sizeof(tio));
tio.c_cflag = B9600 | CS8 | CLOCAL | ECHO;
tio.c_iflag = IGNPAR | ICRNL | IGNBRK;
tio.c_lflag = ICANON;
tio.c_cc[VMIN] = 1;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &tio);

printf("Motor On\n");
write(fd,buf,7);
sleep(3);

for(;;) {
scanf("%d",&v);
if(v<0) buf[5]=v;
printf("Motor On\n");
write(fd,buf,7);
}

buf[2]=1;
buf[3]=3;
printf("Motor Off\n");
write(fd,buf,4);
sleep(2);

close(fd);
return 0;

}

----



※追記
プログラム書くのにこのblog向いてませんね…

コメント

人気の投稿