RobocupSSLのメイン基板白mbedのプログラム

Dependencies:   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は,ロボットとボールの座標,審判の判定を元にロボットの移動,キックなどの作戦を決定し,無線によってロボットに指令を送信する. 700


ロボット機能紹介


●オムニホイールによる方向転換不要の全方位移動

オムニホイールは,自由に回転可能なローラをホイールの外周上に配置した車輪である.ローラの回転により,車輪の回転と垂直の方向に駆動力を発することはできないが移動は可能となる.各車輪の角速度を調整することによって全方向への移動を可能にする.
400

●ドリブルバーのバックスピンによるボール保持

●電磁力を利用したキッカー

●キッカーの電磁力エネルギーを充電する充電回路

●ロボット情報が一目でわかるLCD

Committer:
alt0710
Date:
Tue Apr 18 13:21:12 2017 +0000
Revision:
1:c359b1fcfb5a
Child:
2:ba11cc8540d3
i2c???????Timer??????????????????

Who changed what in which revision?

UserRevisionLine numberNew 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 1:c359b1fcfb5a 24
alt0710 1:c359b1fcfb5a 25
alt0710 1:c359b1fcfb5a 26
alt0710 1:c359b1fcfb5a 27 /* **ローカル関数** */
alt0710 1:c359b1fcfb5a 28 void i2c_send(void)
alt0710 1:c359b1fcfb5a 29 {
alt0710 1:c359b1fcfb5a 30 //4msec周期で送信
alt0710 1:c359b1fcfb5a 31 //送信記述はここに書く
alt0710 1:c359b1fcfb5a 32 printfLCD(InterfaceManager::i2c.LCDMsg);
alt0710 1:c359b1fcfb5a 33
alt0710 1:c359b1fcfb5a 34
alt0710 1:c359b1fcfb5a 35
alt0710 1:c359b1fcfb5a 36 }
alt0710 1:c359b1fcfb5a 37
alt0710 1:c359b1fcfb5a 38 static void initLCD(void)
alt0710 1:c359b1fcfb5a 39 {
alt0710 1:c359b1fcfb5a 40 xdev_out(sendCharacter);
alt0710 1:c359b1fcfb5a 41
alt0710 1:c359b1fcfb5a 42 sendCommand(0x38);
alt0710 1:c359b1fcfb5a 43 sendCommand(0x39);
alt0710 1:c359b1fcfb5a 44 sendCommand(0x14);
alt0710 1:c359b1fcfb5a 45 sendCommand(0x70);
alt0710 1:c359b1fcfb5a 46 sendCommand(0x56);
alt0710 1:c359b1fcfb5a 47 sendCommand(0x6C);
alt0710 1:c359b1fcfb5a 48 wait_ms(200);
alt0710 1:c359b1fcfb5a 49 sendCommand(0x38);
alt0710 1:c359b1fcfb5a 50 sendCommand(0x0C);
alt0710 1:c359b1fcfb5a 51 sendCommand(0x01);
alt0710 1:c359b1fcfb5a 52 wait_ms(2);
alt0710 1:c359b1fcfb5a 53
alt0710 1:c359b1fcfb5a 54 initialiseCursorPosition();
alt0710 1:c359b1fcfb5a 55 }
alt0710 1:c359b1fcfb5a 56 extern void printfLCD(const char* fmt, ...)
alt0710 1:c359b1fcfb5a 57 {
alt0710 1:c359b1fcfb5a 58 va_list arp;
alt0710 1:c359b1fcfb5a 59
alt0710 1:c359b1fcfb5a 60 clearDisp();
alt0710 1:c359b1fcfb5a 61
alt0710 1:c359b1fcfb5a 62 va_start(arp, fmt);
alt0710 1:c359b1fcfb5a 63 xvprintf(fmt,arp);
alt0710 1:c359b1fcfb5a 64 va_end(arp);
alt0710 1:c359b1fcfb5a 65
alt0710 1:c359b1fcfb5a 66 initialiseCursorPosition();
alt0710 1:c359b1fcfb5a 67 }
alt0710 1:c359b1fcfb5a 68
alt0710 1:c359b1fcfb5a 69 static void sendCommand(unsigned char command)
alt0710 1:c359b1fcfb5a 70 {
alt0710 1:c359b1fcfb5a 71 char data[2];
alt0710 1:c359b1fcfb5a 72 data[0]= 0x80;
alt0710 1:c359b1fcfb5a 73 data[1]= command;
alt0710 1:c359b1fcfb5a 74 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 75 wait_us(27);
alt0710 1:c359b1fcfb5a 76 }
alt0710 1:c359b1fcfb5a 77
alt0710 1:c359b1fcfb5a 78 static void sendCharacter(unsigned char a)
alt0710 1:c359b1fcfb5a 79 {
alt0710 1:c359b1fcfb5a 80 if(a == '\n') { //改行コードのときは改行する
alt0710 1:c359b1fcfb5a 81 moveCursor(0x40);
alt0710 1:c359b1fcfb5a 82 return;
alt0710 1:c359b1fcfb5a 83 }
alt0710 1:c359b1fcfb5a 84 char data[2];
alt0710 1:c359b1fcfb5a 85 data[0]= 0xC0;
alt0710 1:c359b1fcfb5a 86 data[1]= a;
alt0710 1:c359b1fcfb5a 87 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 88 wait_us(27);
alt0710 1:c359b1fcfb5a 89 }
alt0710 1:c359b1fcfb5a 90
alt0710 1:c359b1fcfb5a 91 static void initialiseCursorPosition(void)
alt0710 1:c359b1fcfb5a 92 {
alt0710 1:c359b1fcfb5a 93 /* 通信終了時にカーソルを頭に戻す */
alt0710 1:c359b1fcfb5a 94 char data[2];
alt0710 1:c359b1fcfb5a 95 data[0]= 0x00;
alt0710 1:c359b1fcfb5a 96 data[1]= 0x80;
alt0710 1:c359b1fcfb5a 97 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 98
alt0710 1:c359b1fcfb5a 99 }
alt0710 1:c359b1fcfb5a 100
alt0710 1:c359b1fcfb5a 101
alt0710 1:c359b1fcfb5a 102 static void clearDisp(void)
alt0710 1:c359b1fcfb5a 103 {
alt0710 1:c359b1fcfb5a 104 sendCommand(0x01);
alt0710 1:c359b1fcfb5a 105 wait_ms(1);
alt0710 1:c359b1fcfb5a 106 }
alt0710 1:c359b1fcfb5a 107
alt0710 1:c359b1fcfb5a 108
alt0710 1:c359b1fcfb5a 109 static void moveCursor(unsigned char address)
alt0710 1:c359b1fcfb5a 110 {
alt0710 1:c359b1fcfb5a 111 sendCommand(0x80 | address);
alt0710 1:c359b1fcfb5a 112 }
alt0710 1:c359b1fcfb5a 113
alt0710 1:c359b1fcfb5a 114
alt0710 1:c359b1fcfb5a 115 /* **グルーバル関数** */
alt0710 1:c359b1fcfb5a 116 extern void initI2C(void)
alt0710 1:c359b1fcfb5a 117 {
alt0710 1:c359b1fcfb5a 118 i2cMBED.frequency(400000);
alt0710 1:c359b1fcfb5a 119 initLCD();
alt0710 1:c359b1fcfb5a 120 i2c_Timer.attach(i2c_send, 0.5);
alt0710 1:c359b1fcfb5a 121 }
alt0710 1:c359b1fcfb5a 122
alt0710 1:c359b1fcfb5a 123 /* **クラス** */
alt0710 1:c359b1fcfb5a 124 I2C_Roots::I2C_Roots()
alt0710 1:c359b1fcfb5a 125 {
alt0710 1:c359b1fcfb5a 126
alt0710 1:c359b1fcfb5a 127
alt0710 1:c359b1fcfb5a 128 }
alt0710 1:c359b1fcfb5a 129
alt0710 1:c359b1fcfb5a 130 void I2C_Roots::setLCDMsg(char* msg,char msg_num)
alt0710 1:c359b1fcfb5a 131 {
alt0710 1:c359b1fcfb5a 132 for(char i = 0; i <= msg_num ; i++)
alt0710 1:c359b1fcfb5a 133 {
alt0710 1:c359b1fcfb5a 134 LCDMsg[i] = *(msg + i);
alt0710 1:c359b1fcfb5a 135 }
alt0710 1:c359b1fcfb5a 136
alt0710 1:c359b1fcfb5a 137
alt0710 1:c359b1fcfb5a 138 }