Control.cc

00001 /*
00002  * control.cc
00003  *
00004  *  Created on: Feb 26, 2010
00005  *      Author: uscr
00006  */
00007 
00008 
00009 #include "Control.h"
00010 
00011 #include <cstring>
00012 #include <cstdlib>
00013 #include <cmath>
00014 #include <termio.h>
00015 #include <sys/fcntl.h>
00016 #include <sys/file.h>
00017 #include <unistd.h>
00018 
00019 int propSerialCon;
00020 
00021 bool initializeController () {
00022 
00023         //=========================================================================
00024         //Initialize the serial conn to the Propeller
00025         //=========================================================================
00026         if ((propSerialCon = open (PROP_SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
00027                 return false;
00028 
00029         struct termios attr;
00030 
00031         if (tcgetattr(propSerialCon, &attr) < 0)
00032                 return false;
00033 
00034         /* 8 bits + baud rate + local control */
00035         attr.c_cflag = PROP_SERIAL_BAUD|CLOCAL|CREAD;
00036         attr.c_cflag &= ~CRTSCTS;
00037 
00038     attr.c_iflag = IXOFF;
00039     attr.c_iflag |= ~( IGNBRK | BRKINT | ISTRIP | IGNCR | ICRNL | IXON | INLCR | PARMRK);
00040         attr.c_oflag = 0;
00041         attr.c_lflag = 0;
00042         /* set output and input baud rates */
00043         cfsetospeed(&attr, PROP_SERIAL_BAUD);
00044         cfsetispeed(&attr, PROP_SERIAL_BAUD);
00045         if (tcsetattr(propSerialCon, TCSANOW, &attr) < 0)
00046                 return false;
00047 
00048         return true;
00049 }
00050 
00051 void setMotors (unsigned char front, unsigned char rear, unsigned char left, unsigned char right) {
00052         char buf[6] = {'A', front, rear, left, right, 'Z'};
00053         write(propSerialCon, buf, 6);
00054 }
00055 
00056 void shutdownController() {
00057         close(propSerialCon);
00058 
00059 }
Generated on Sun May 8 08:05:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3