helidemo_simple.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  helicontrol - c/c++ control api for silverlit helicopters/quadcopters  *
00003  *  Copyright (C) 2008 by                                                  *
00004  *  Joint Robotics Lab                                                     *
00005  *  Goethe-University Frankfurt, Germany                                   *
00006  *  http://www.jrl.cs.uni-frankfurt.de                                     *
00007  *                                                                         *
00008  *  This library is free software; you can redistribute it and/or          *
00009  *  modify it under the terms of the GNU General Public                    *
00010  *  License as published by the Free Software Foundation                   *
00011  *  version 2 of the License.                                              *
00012  *                                                                         *
00013  *  This program is distributed in the hope that it will be useful,        *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
00016  *  General Public License for more details.                               *
00017  *                                                                         *
00018  *  You should have received a copy of the GNU General Public              *
00019  *  License along with this library; if not, write to the Free Software    *
00020  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301 USA*
00021  ***************************************************************************/
00022 
00023 /* $Id: helidemo_simple.c 268 2008-12-17 21:52:22Z holgerf $ */
00024 
00035 #include <stdio.h>
00036 #include <errno.h>
00037 #include <helicontrol.h>
00038 
00039 #define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
00040 
00041 
00042 
00043 struct usb_dev_handle *handle;
00044 
00045 static void send_frame(char protocol, char channel, char throttle,
00046                        char trim, char yaw, char  pitch, char special)
00047 {
00048     int error;
00049 
00050     switch (protocol)
00051     {
00052         case PROTO_PICOOZ:
00053             error = HC_Send_Picooz(handle, bound(0, channel-'a', 2), throttle, trim, yaw);
00054             break;
00055         case PROTO_CHALLENGER:
00056             error = HC_Send_Challenger(handle, bound(1, channel-'a'+1, 2), throttle, trim, yaw, special);
00057             break;
00058         case PROTO_URANUS:
00059             error = HC_Send_Uranus(handle, bound(0, channel-'a', 2), throttle, trim, yaw, pitch, special);
00060             break;
00061         case PROTO_TANDEMZ:
00062             error = HC_Send_Tandemz(handle, bound(0, channel-'a', 2), special, throttle, pitch, trim, yaw);
00063             break;
00064         case PROTO_SAUCER:
00065             error = HC_Send_Saucer(handle, special, pitch, throttle, yaw);
00066             break;
00067         default:
00068             error = -1;
00069     }
00070     if (error < 0)
00071     {
00072         puts("USB_control_msg error!");
00073         exit(EXIT_FAILURE);
00074     }
00075 }
00076 
00077 int main(void)
00078 {
00079     char t, channel, throttle, trim, yaw, pitch, special, protocol = PROTO_CHALLENGER;
00080     int i;
00081 
00082     handle = HC_Init();
00083     if (handle == NULL)
00084     {
00085         puts("USB device handle not found!");
00086         exit(EXIT_FAILURE);
00087     }
00088 
00089     protocol = PROTO_PICOOZ;
00090     channel = 'a';
00091     throttle = 5;
00092     trim = 0;
00093     yaw = 0;
00094     pitch = 0;
00095     special = 0;
00096     for (i = 170; i>0; --i)
00097     {
00098         t = (i/3) % 28 + 1;
00099         if (t>14) t = 30 - t;
00100         if (1 == i) t = 0;
00101         /* printf("%d %d\n",i,t); */
00102         send_frame(protocol, channel, t , trim, yaw, pitch, special);
00103 #ifdef WIN32
00104         Sleep(150);
00105 #else
00106         usleep(150000);
00107 #endif
00108     }
00109 
00110     HC_Close(handle);
00111 
00112     exit(EXIT_SUCCESS);
00113 }
00114 /* EOF */

Generated on Thu Dec 18 00:02:52 2008 for libhelicontrol by  doxygen 1.5.3