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:
Sat Apr 28 19:47:31 2018 +0000
Revision:
24:37a074e767c8
Parent:
2:ba11cc8540d3
Child:
27:c7d8f514209a
ID??????????????????Ticker??????????????????????????????????????main??????????main?????????????;

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 24:37a074e767c8 5 #include "status_manager.h"
alt0710 24:37a074e767c8 6 #include "parameter_manager.h"
alt0710 1:c359b1fcfb5a 7 #include "i2c_roots.h"
alt0710 1:c359b1fcfb5a 8
alt0710 1:c359b1fcfb5a 9 /* **mbedクラス** */
alt0710 1:c359b1fcfb5a 10 #ifdef LPC4088
alt0710 1:c359b1fcfb5a 11
alt0710 1:c359b1fcfb5a 12 #elif STM32
alt0710 1:c359b1fcfb5a 13 I2C i2cMBED(PB_7, PB_6); // sda, scl
alt0710 1:c359b1fcfb5a 14 #endif
alt0710 1:c359b1fcfb5a 15
alt0710 1:c359b1fcfb5a 16 Ticker i2c_Timer;
alt0710 1:c359b1fcfb5a 17
alt0710 1:c359b1fcfb5a 18 /* **ローカル関数定義** */
alt0710 1:c359b1fcfb5a 19 static void initLCD(void);
alt0710 1:c359b1fcfb5a 20
alt0710 1:c359b1fcfb5a 21 static void sendCommand(unsigned char command);
alt0710 1:c359b1fcfb5a 22 static void sendCharacter(unsigned char a);
alt0710 1:c359b1fcfb5a 23 static void clearDisp(void);
alt0710 1:c359b1fcfb5a 24 static void moveCursor(unsigned char address);
alt0710 1:c359b1fcfb5a 25 static void initialiseCursorPosition(void);
alt0710 2:ba11cc8540d3 26 /* **ローカル変数** */
alt0710 1:c359b1fcfb5a 27
alt0710 1:c359b1fcfb5a 28
alt0710 1:c359b1fcfb5a 29
alt0710 1:c359b1fcfb5a 30 /* **ローカル関数** */
alt0710 1:c359b1fcfb5a 31 void i2c_send(void)
alt0710 1:c359b1fcfb5a 32 {
alt0710 2:ba11cc8540d3 33 //500msec周期で送信
alt0710 1:c359b1fcfb5a 34 //送信記述はここに書く
alt0710 1:c359b1fcfb5a 35 printfLCD(InterfaceManager::i2c.LCDMsg);
alt0710 1:c359b1fcfb5a 36
alt0710 1:c359b1fcfb5a 37
alt0710 1:c359b1fcfb5a 38
alt0710 1:c359b1fcfb5a 39 }
alt0710 1:c359b1fcfb5a 40
alt0710 1:c359b1fcfb5a 41 static void initLCD(void)
alt0710 1:c359b1fcfb5a 42 {
alt0710 1:c359b1fcfb5a 43 xdev_out(sendCharacter);
alt0710 1:c359b1fcfb5a 44
alt0710 1:c359b1fcfb5a 45 sendCommand(0x38);
alt0710 1:c359b1fcfb5a 46 sendCommand(0x39);
alt0710 1:c359b1fcfb5a 47 sendCommand(0x14);
alt0710 1:c359b1fcfb5a 48 sendCommand(0x70);
alt0710 1:c359b1fcfb5a 49 sendCommand(0x56);
alt0710 1:c359b1fcfb5a 50 sendCommand(0x6C);
alt0710 1:c359b1fcfb5a 51 wait_ms(200);
alt0710 1:c359b1fcfb5a 52 sendCommand(0x38);
alt0710 1:c359b1fcfb5a 53 sendCommand(0x0C);
alt0710 1:c359b1fcfb5a 54 sendCommand(0x01);
alt0710 1:c359b1fcfb5a 55 wait_ms(2);
alt0710 1:c359b1fcfb5a 56
alt0710 1:c359b1fcfb5a 57 initialiseCursorPosition();
alt0710 1:c359b1fcfb5a 58 }
alt0710 1:c359b1fcfb5a 59 extern void printfLCD(const char* fmt, ...)
alt0710 1:c359b1fcfb5a 60 {
alt0710 1:c359b1fcfb5a 61 va_list arp;
alt0710 1:c359b1fcfb5a 62
alt0710 1:c359b1fcfb5a 63 clearDisp();
alt0710 1:c359b1fcfb5a 64
alt0710 1:c359b1fcfb5a 65 va_start(arp, fmt);
alt0710 1:c359b1fcfb5a 66 xvprintf(fmt,arp);
alt0710 1:c359b1fcfb5a 67 va_end(arp);
alt0710 1:c359b1fcfb5a 68
alt0710 1:c359b1fcfb5a 69 initialiseCursorPosition();
alt0710 1:c359b1fcfb5a 70 }
alt0710 1:c359b1fcfb5a 71
alt0710 1:c359b1fcfb5a 72 static void sendCommand(unsigned char command)
alt0710 1:c359b1fcfb5a 73 {
alt0710 1:c359b1fcfb5a 74 char data[2];
alt0710 1:c359b1fcfb5a 75 data[0]= 0x80;
alt0710 1:c359b1fcfb5a 76 data[1]= command;
alt0710 1:c359b1fcfb5a 77 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 78 wait_us(27);
alt0710 1:c359b1fcfb5a 79 }
alt0710 1:c359b1fcfb5a 80
alt0710 1:c359b1fcfb5a 81 static void sendCharacter(unsigned char a)
alt0710 1:c359b1fcfb5a 82 {
alt0710 1:c359b1fcfb5a 83 if(a == '\n') { //改行コードのときは改行する
alt0710 1:c359b1fcfb5a 84 moveCursor(0x40);
alt0710 1:c359b1fcfb5a 85 return;
alt0710 1:c359b1fcfb5a 86 }
alt0710 1:c359b1fcfb5a 87 char data[2];
alt0710 1:c359b1fcfb5a 88 data[0]= 0xC0;
alt0710 1:c359b1fcfb5a 89 data[1]= a;
alt0710 1:c359b1fcfb5a 90 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 91 wait_us(27);
alt0710 1:c359b1fcfb5a 92 }
alt0710 1:c359b1fcfb5a 93
alt0710 1:c359b1fcfb5a 94 static void initialiseCursorPosition(void)
alt0710 1:c359b1fcfb5a 95 {
alt0710 1:c359b1fcfb5a 96 /* 通信終了時にカーソルを頭に戻す */
alt0710 1:c359b1fcfb5a 97 char data[2];
alt0710 1:c359b1fcfb5a 98 data[0]= 0x00;
alt0710 1:c359b1fcfb5a 99 data[1]= 0x80;
alt0710 1:c359b1fcfb5a 100 i2cMBED.write(ADDRESS_LCD, data, 2);
alt0710 1:c359b1fcfb5a 101
alt0710 1:c359b1fcfb5a 102 }
alt0710 1:c359b1fcfb5a 103
alt0710 1:c359b1fcfb5a 104
alt0710 1:c359b1fcfb5a 105 static void clearDisp(void)
alt0710 1:c359b1fcfb5a 106 {
alt0710 1:c359b1fcfb5a 107 sendCommand(0x01);
alt0710 1:c359b1fcfb5a 108 wait_ms(1);
alt0710 1:c359b1fcfb5a 109 }
alt0710 1:c359b1fcfb5a 110
alt0710 1:c359b1fcfb5a 111
alt0710 1:c359b1fcfb5a 112 static void moveCursor(unsigned char address)
alt0710 1:c359b1fcfb5a 113 {
alt0710 1:c359b1fcfb5a 114 sendCommand(0x80 | address);
alt0710 1:c359b1fcfb5a 115 }
alt0710 1:c359b1fcfb5a 116
alt0710 1:c359b1fcfb5a 117
alt0710 1:c359b1fcfb5a 118 /* **グルーバル関数** */
alt0710 1:c359b1fcfb5a 119 extern void initI2C(void)
alt0710 1:c359b1fcfb5a 120 {
alt0710 1:c359b1fcfb5a 121 i2cMBED.frequency(400000);
alt0710 1:c359b1fcfb5a 122 initLCD();
alt0710 2:ba11cc8540d3 123 i2c_Timer.attach(i2c_send, I2C_SEND_CYCLE_TIME);
alt0710 1:c359b1fcfb5a 124 }
alt0710 1:c359b1fcfb5a 125
alt0710 1:c359b1fcfb5a 126 /* **クラス** */
alt0710 1:c359b1fcfb5a 127 I2C_Roots::I2C_Roots()
alt0710 1:c359b1fcfb5a 128 {
alt0710 1:c359b1fcfb5a 129
alt0710 1:c359b1fcfb5a 130
alt0710 1:c359b1fcfb5a 131 }
alt0710 1:c359b1fcfb5a 132
alt0710 1:c359b1fcfb5a 133 void I2C_Roots::setLCDMsg(char* msg,char msg_num)
alt0710 1:c359b1fcfb5a 134 {
alt0710 1:c359b1fcfb5a 135 for(char i = 0; i <= msg_num ; i++)
alt0710 1:c359b1fcfb5a 136 {
alt0710 1:c359b1fcfb5a 137 LCDMsg[i] = *(msg + i);
alt0710 1:c359b1fcfb5a 138 }
alt0710 1:c359b1fcfb5a 139
alt0710 1:c359b1fcfb5a 140
alt0710 24:37a074e767c8 141 }
alt0710 24:37a074e767c8 142
alt0710 24:37a074e767c8 143 void I2C_Roots::setIndicateMsg(char* msg,char msg_num)
alt0710 24:37a074e767c8 144 {
alt0710 24:37a074e767c8 145 for(char i = 0; i <= msg_num ; i++)
alt0710 24:37a074e767c8 146 {
alt0710 24:37a074e767c8 147 IndicateMsg[i] = *(msg + i);
alt0710 24:37a074e767c8 148 }
alt0710 24:37a074e767c8 149
alt0710 24:37a074e767c8 150 i2cMBED.write(ADDRESS_INDICATE, IndicateMsg, msg_num);
alt0710 24:37a074e767c8 151 }
alt0710 24:37a074e767c8 152
alt0710 24:37a074e767c8 153 void I2C_Roots::setIDMsg(char* msg,char msg_num)
alt0710 24:37a074e767c8 154 {
alt0710 24:37a074e767c8 155 for(char i = 0; i <= msg_num ; i++)
alt0710 24:37a074e767c8 156 {
alt0710 24:37a074e767c8 157 IDMsg[i] = *(msg + i);
alt0710 24:37a074e767c8 158 }
alt0710 24:37a074e767c8 159 i2cMBED.write(ADDRESS_EEPROM, IDMsg, msg_num);
alt0710 24:37a074e767c8 160 }
alt0710 24:37a074e767c8 161
alt0710 24:37a074e767c8 162 void I2C_Roots::readIDMsg(void)
alt0710 24:37a074e767c8 163 {
alt0710 24:37a074e767c8 164 char msg_num = 2;
alt0710 24:37a074e767c8 165 for(char i = 0; i <= msg_num ; i++)
alt0710 24:37a074e767c8 166 {
alt0710 24:37a074e767c8 167 IDMsg[i] = 0;
alt0710 24:37a074e767c8 168 }
alt0710 24:37a074e767c8 169 msg_num = 2;
alt0710 24:37a074e767c8 170 i2cMBED.write(ADDRESS_EEPROM, IDMsg, msg_num, 1);
alt0710 24:37a074e767c8 171
alt0710 24:37a074e767c8 172 msg_num = 1;
alt0710 24:37a074e767c8 173 i2cMBED.read(ADDRESS_EEPROM, IDMsg, msg_num, 1);
alt0710 24:37a074e767c8 174 ParameterManager::machine_id = IDMsg[0];
alt0710 24:37a074e767c8 175
alt0710 1:c359b1fcfb5a 176 }