うおーるぼっと用プログラム Wiiリモコンからのダイレクト操作モードのみ BlueUSBをベースに使用しています。

Dependencies:   BD6211F mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 Copyright (c) 2011 JKSOFT
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 #include "mbed.h"
00024 #include "USBHost.h"
00025 #include "Utils.h"
00026 #include "BD6211F.h"
00027 #include "Wiimote.h"
00028 
00029 
00030 // ----- Wallbot I/O Setting ----- 
00031 // Motor
00032 BD6211F      RightMotor(p21,p22);
00033 BD6211F      LeftMotor(p23,p24);
00034 
00035 // Direct control mode
00036 int DirectMode( Wiimote* wii, int stat )
00037 {
00038     int ret = stat;
00039     
00040     if( wii->left )
00041     {
00042         RightMotor = 1.0;
00043         LeftMotor = -1.0;
00044     }
00045     else if( wii->right )
00046     {
00047         RightMotor = -1.0;
00048         LeftMotor = 1.0;
00049     }    
00050     else if( wii->up )
00051     {
00052         RightMotor = 1.0;
00053         LeftMotor = 1.0;
00054     }
00055     else if( wii->down )
00056     {
00057         RightMotor = -1.0;
00058         LeftMotor = -1.0;
00059     }
00060     else
00061     {
00062         RightMotor = 0.0;
00063         LeftMotor = 0.0;
00064     }
00065 
00066     float factor = wii->wheel / 150.0f; 
00067     
00068     float left_factor = (factor >= 0.0) ? 1.0 : 1.0 - (-factor);
00069     float right_factor = (factor <= 0.0) ? 1.0 : 1.0 - factor;
00070     
00071     if( wii->one )
00072     {
00073         RightMotor = right_factor;
00074         LeftMotor = left_factor;
00075     }
00076     if( wii->two )
00077     {
00078         RightMotor = -left_factor;
00079         LeftMotor = -right_factor;
00080     }
00081     
00082     return(ret);
00083 }
00084 
00085 // Processing when receiving it from Wiiremote
00086 int wall_bot_remote(char *c,int stat)
00087 {
00088     Wiimote wii;
00089     int ret = stat;
00090     
00091     wii.decode(c);
00092     
00093     ret = DirectMode( &wii ,ret );
00094     
00095     return(ret);
00096 }
00097 
00098 int GetConsoleChar()
00099 {
00100     return(0);
00101 }
00102 
00103 int OnDiskInsert(int device)
00104 {
00105     return(0);
00106 }
00107 
00108 int main()
00109 {
00110     // USB Init is done for Bluetooth
00111     USBInit();
00112     
00113     while(1)
00114     {
00115        // USB Processing is done for Bluetooth
00116        USBLoop();
00117     }
00118 }