RobocupSSLのメイン基板白mbedのプログラム
Rootsロボット mainプログラム
~ Robocup SSL(小型車輪リーグ)ロボット ~
Robocup SSLとは
●試合構成
Robocup小型ロボットリーグ(Small Size League)は,直径180[mm],高さ150[mm]以内のサイズのロボット6台が1チームとなり,オレンジ色のゴルフボールを使ってサッカー競技を行う自立型ロボットコンテストである.
フィールドの上には2台のWebカメラが設置され,フィールド上のロボットとボールを撮影する.Visionサーバは,フィールドの画像データよりロボットとボールの座標データを算出し,LANを用い各チームのAI用PCに送信する.Webカメラの撮影速度は,60[fps]である.レフリーボックスは,ファウルやフリーキック,スローインなどの審判の判定を入力し,LANを通じて各チームのAI用PCに送信する.それぞれのチームのAI用PCは,ロボットとボールの座標,審判の判定を元にロボットの移動,キックなどの作戦を決定し,無線によってロボットに指令を送信する.
ロボット機能紹介
●オムニホイールによる方向転換不要の全方位移動
オムニホイールは,自由に回転可能なローラをホイールの外周上に配置した車輪である.ローラの回転により,車輪の回転と垂直の方向に駆動力を発することはできないが移動は可能となる.各車輪の角速度を調整することによって全方向への移動を可能にする.
●ドリブルバーのバックスピンによるボール保持
●電磁力を利用したキッカー
●キッカーの電磁力エネルギーを充電する充電回路
●ロボット情報が一目でわかるLCD
interface/i2c/i2c_roots.cpp@2:ba11cc8540d3, 2017-04-18 (annotated)
- Committer:
- alt0710
- Date:
- Tue Apr 18 16:09:06 2017 +0000
- Revision:
- 2:ba11cc8540d3
- Parent:
- 1:c359b1fcfb5a
- Child:
- 24:37a074e767c8
CAN???????MD???????OK;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alt0710 | 1:c359b1fcfb5a | 1 | |
alt0710 | 1:c359b1fcfb5a | 2 | #include "mbed.h" |
alt0710 | 1:c359b1fcfb5a | 3 | #include "comm.h" |
alt0710 | 1:c359b1fcfb5a | 4 | #include "interface_manager.h" |
alt0710 | 1:c359b1fcfb5a | 5 | #include "i2c_roots.h" |
alt0710 | 1:c359b1fcfb5a | 6 | |
alt0710 | 1:c359b1fcfb5a | 7 | /* **mbedクラス** */ |
alt0710 | 1:c359b1fcfb5a | 8 | #ifdef LPC4088 |
alt0710 | 1:c359b1fcfb5a | 9 | |
alt0710 | 1:c359b1fcfb5a | 10 | #elif STM32 |
alt0710 | 1:c359b1fcfb5a | 11 | I2C i2cMBED(PB_7, PB_6); // sda, scl |
alt0710 | 1:c359b1fcfb5a | 12 | #endif |
alt0710 | 1:c359b1fcfb5a | 13 | |
alt0710 | 1:c359b1fcfb5a | 14 | Ticker i2c_Timer; |
alt0710 | 1:c359b1fcfb5a | 15 | |
alt0710 | 1:c359b1fcfb5a | 16 | /* **ローカル関数定義** */ |
alt0710 | 1:c359b1fcfb5a | 17 | static void initLCD(void); |
alt0710 | 1:c359b1fcfb5a | 18 | |
alt0710 | 1:c359b1fcfb5a | 19 | static void sendCommand(unsigned char command); |
alt0710 | 1:c359b1fcfb5a | 20 | static void sendCharacter(unsigned char a); |
alt0710 | 1:c359b1fcfb5a | 21 | static void clearDisp(void); |
alt0710 | 1:c359b1fcfb5a | 22 | static void moveCursor(unsigned char address); |
alt0710 | 1:c359b1fcfb5a | 23 | static void initialiseCursorPosition(void); |
alt0710 | 2:ba11cc8540d3 | 24 | /* **ローカル変数** */ |
alt0710 | 1:c359b1fcfb5a | 25 | |
alt0710 | 1:c359b1fcfb5a | 26 | |
alt0710 | 1:c359b1fcfb5a | 27 | |
alt0710 | 1:c359b1fcfb5a | 28 | /* **ローカル関数** */ |
alt0710 | 1:c359b1fcfb5a | 29 | void i2c_send(void) |
alt0710 | 1:c359b1fcfb5a | 30 | { |
alt0710 | 2:ba11cc8540d3 | 31 | //500msec周期で送信 |
alt0710 | 1:c359b1fcfb5a | 32 | //送信記述はここに書く |
alt0710 | 1:c359b1fcfb5a | 33 | printfLCD(InterfaceManager::i2c.LCDMsg); |
alt0710 | 1:c359b1fcfb5a | 34 | |
alt0710 | 1:c359b1fcfb5a | 35 | |
alt0710 | 1:c359b1fcfb5a | 36 | |
alt0710 | 1:c359b1fcfb5a | 37 | } |
alt0710 | 1:c359b1fcfb5a | 38 | |
alt0710 | 1:c359b1fcfb5a | 39 | static void initLCD(void) |
alt0710 | 1:c359b1fcfb5a | 40 | { |
alt0710 | 1:c359b1fcfb5a | 41 | xdev_out(sendCharacter); |
alt0710 | 1:c359b1fcfb5a | 42 | |
alt0710 | 1:c359b1fcfb5a | 43 | sendCommand(0x38); |
alt0710 | 1:c359b1fcfb5a | 44 | sendCommand(0x39); |
alt0710 | 1:c359b1fcfb5a | 45 | sendCommand(0x14); |
alt0710 | 1:c359b1fcfb5a | 46 | sendCommand(0x70); |
alt0710 | 1:c359b1fcfb5a | 47 | sendCommand(0x56); |
alt0710 | 1:c359b1fcfb5a | 48 | sendCommand(0x6C); |
alt0710 | 1:c359b1fcfb5a | 49 | wait_ms(200); |
alt0710 | 1:c359b1fcfb5a | 50 | sendCommand(0x38); |
alt0710 | 1:c359b1fcfb5a | 51 | sendCommand(0x0C); |
alt0710 | 1:c359b1fcfb5a | 52 | sendCommand(0x01); |
alt0710 | 1:c359b1fcfb5a | 53 | wait_ms(2); |
alt0710 | 1:c359b1fcfb5a | 54 | |
alt0710 | 1:c359b1fcfb5a | 55 | initialiseCursorPosition(); |
alt0710 | 1:c359b1fcfb5a | 56 | } |
alt0710 | 1:c359b1fcfb5a | 57 | extern void printfLCD(const char* fmt, ...) |
alt0710 | 1:c359b1fcfb5a | 58 | { |
alt0710 | 1:c359b1fcfb5a | 59 | va_list arp; |
alt0710 | 1:c359b1fcfb5a | 60 | |
alt0710 | 1:c359b1fcfb5a | 61 | clearDisp(); |
alt0710 | 1:c359b1fcfb5a | 62 | |
alt0710 | 1:c359b1fcfb5a | 63 | va_start(arp, fmt); |
alt0710 | 1:c359b1fcfb5a | 64 | xvprintf(fmt,arp); |
alt0710 | 1:c359b1fcfb5a | 65 | va_end(arp); |
alt0710 | 1:c359b1fcfb5a | 66 | |
alt0710 | 1:c359b1fcfb5a | 67 | initialiseCursorPosition(); |
alt0710 | 1:c359b1fcfb5a | 68 | } |
alt0710 | 1:c359b1fcfb5a | 69 | |
alt0710 | 1:c359b1fcfb5a | 70 | static void sendCommand(unsigned char command) |
alt0710 | 1:c359b1fcfb5a | 71 | { |
alt0710 | 1:c359b1fcfb5a | 72 | char data[2]; |
alt0710 | 1:c359b1fcfb5a | 73 | data[0]= 0x80; |
alt0710 | 1:c359b1fcfb5a | 74 | data[1]= command; |
alt0710 | 1:c359b1fcfb5a | 75 | i2cMBED.write(ADDRESS_LCD, data, 2); |
alt0710 | 1:c359b1fcfb5a | 76 | wait_us(27); |
alt0710 | 1:c359b1fcfb5a | 77 | } |
alt0710 | 1:c359b1fcfb5a | 78 | |
alt0710 | 1:c359b1fcfb5a | 79 | static void sendCharacter(unsigned char a) |
alt0710 | 1:c359b1fcfb5a | 80 | { |
alt0710 | 1:c359b1fcfb5a | 81 | if(a == '\n') { //改行コードのときは改行する |
alt0710 | 1:c359b1fcfb5a | 82 | moveCursor(0x40); |
alt0710 | 1:c359b1fcfb5a | 83 | return; |
alt0710 | 1:c359b1fcfb5a | 84 | } |
alt0710 | 1:c359b1fcfb5a | 85 | char data[2]; |
alt0710 | 1:c359b1fcfb5a | 86 | data[0]= 0xC0; |
alt0710 | 1:c359b1fcfb5a | 87 | data[1]= a; |
alt0710 | 1:c359b1fcfb5a | 88 | i2cMBED.write(ADDRESS_LCD, data, 2); |
alt0710 | 1:c359b1fcfb5a | 89 | wait_us(27); |
alt0710 | 1:c359b1fcfb5a | 90 | } |
alt0710 | 1:c359b1fcfb5a | 91 | |
alt0710 | 1:c359b1fcfb5a | 92 | static void initialiseCursorPosition(void) |
alt0710 | 1:c359b1fcfb5a | 93 | { |
alt0710 | 1:c359b1fcfb5a | 94 | /* 通信終了時にカーソルを頭に戻す */ |
alt0710 | 1:c359b1fcfb5a | 95 | char data[2]; |
alt0710 | 1:c359b1fcfb5a | 96 | data[0]= 0x00; |
alt0710 | 1:c359b1fcfb5a | 97 | data[1]= 0x80; |
alt0710 | 1:c359b1fcfb5a | 98 | i2cMBED.write(ADDRESS_LCD, data, 2); |
alt0710 | 1:c359b1fcfb5a | 99 | |
alt0710 | 1:c359b1fcfb5a | 100 | } |
alt0710 | 1:c359b1fcfb5a | 101 | |
alt0710 | 1:c359b1fcfb5a | 102 | |
alt0710 | 1:c359b1fcfb5a | 103 | static void clearDisp(void) |
alt0710 | 1:c359b1fcfb5a | 104 | { |
alt0710 | 1:c359b1fcfb5a | 105 | sendCommand(0x01); |
alt0710 | 1:c359b1fcfb5a | 106 | wait_ms(1); |
alt0710 | 1:c359b1fcfb5a | 107 | } |
alt0710 | 1:c359b1fcfb5a | 108 | |
alt0710 | 1:c359b1fcfb5a | 109 | |
alt0710 | 1:c359b1fcfb5a | 110 | static void moveCursor(unsigned char address) |
alt0710 | 1:c359b1fcfb5a | 111 | { |
alt0710 | 1:c359b1fcfb5a | 112 | sendCommand(0x80 | address); |
alt0710 | 1:c359b1fcfb5a | 113 | } |
alt0710 | 1:c359b1fcfb5a | 114 | |
alt0710 | 1:c359b1fcfb5a | 115 | |
alt0710 | 1:c359b1fcfb5a | 116 | /* **グルーバル関数** */ |
alt0710 | 1:c359b1fcfb5a | 117 | extern void initI2C(void) |
alt0710 | 1:c359b1fcfb5a | 118 | { |
alt0710 | 1:c359b1fcfb5a | 119 | i2cMBED.frequency(400000); |
alt0710 | 1:c359b1fcfb5a | 120 | initLCD(); |
alt0710 | 2:ba11cc8540d3 | 121 | i2c_Timer.attach(i2c_send, I2C_SEND_CYCLE_TIME); |
alt0710 | 1:c359b1fcfb5a | 122 | } |
alt0710 | 1:c359b1fcfb5a | 123 | |
alt0710 | 1:c359b1fcfb5a | 124 | /* **クラス** */ |
alt0710 | 1:c359b1fcfb5a | 125 | I2C_Roots::I2C_Roots() |
alt0710 | 1:c359b1fcfb5a | 126 | { |
alt0710 | 1:c359b1fcfb5a | 127 | |
alt0710 | 1:c359b1fcfb5a | 128 | |
alt0710 | 1:c359b1fcfb5a | 129 | } |
alt0710 | 1:c359b1fcfb5a | 130 | |
alt0710 | 1:c359b1fcfb5a | 131 | void I2C_Roots::setLCDMsg(char* msg,char msg_num) |
alt0710 | 1:c359b1fcfb5a | 132 | { |
alt0710 | 1:c359b1fcfb5a | 133 | for(char i = 0; i <= msg_num ; i++) |
alt0710 | 1:c359b1fcfb5a | 134 | { |
alt0710 | 1:c359b1fcfb5a | 135 | LCDMsg[i] = *(msg + i); |
alt0710 | 1:c359b1fcfb5a | 136 | } |
alt0710 | 1:c359b1fcfb5a | 137 | |
alt0710 | 1:c359b1fcfb5a | 138 | |
alt0710 | 1:c359b1fcfb5a | 139 | } |