Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 6848|回復: 12

[RoBoME] Smartphone Controller

[複製鏈接]
發表於 2013-7-5 13:00:34 | 顯示全部樓層 |閱讀模式
原文網址: http://roboardgod.blogspot.tw/2013/07/robome-smartphone-controller.html

最近進擊巨人很夯

所以機器人也要進擊一下這樣


以下影片演示給大家看:









這次本魔開發的是RoBoME的控制器喔~

只要將你用RoBoME編寫的動作丟到智慧手機裡就可以做控制了!!

聽起來相當的容易吧~

以下教學

首先智慧手機上的程式我有打包apk供各位下載安裝囉~   LINK

然後RoBoard上必須要有接收端程式     LINK

附註:   接收端程式我預設是接到COM8 所以藍芽設定請設定到COM8

接著   只要在智慧手機根目錄下建置一個資料夾為RoBoME (如下圖)



然後將檔案放入即可喔!

無feedback的機器人記得要放入homeframe文件

或有聲音也要放入喔



開啟應用程式後   會看到兩個欄位

第一個欄位用來選rbm檔案

第二個欄位為選擇藍芽通道


完成後按下Start


出現此介面後

先按下Start   再開啟Power   它就會給馬達電了

下面中文字的部分是我們已經編輯好的動作   它會自動生成按鈕來做整套的動作

相信眼睛很利的大家都有看到voice的按鈕

沒錯   這按鈕就是用來做聲控的

你只要念出下面按鈕的名稱   它就會做對應的動作囉!!

P.S.介面相當的陽春   不過別太介意啦=D   有時間的話再來認真的設計界面吧
發表於 2013-7-27 21:24:09 | 顯示全部樓層
please source code apk !!!!
發表於 2013-7-30 12:21:49 | 顯示全部樓層
help help help

please source code apk !!!!
 樓主| 發表於 2013-7-30 17:37:10 | 顯示全部樓層
can you let me know what you want to do?
like bluetooth, servo control or something else?
發表於 2013-7-31 12:19:45 | 顯示全部樓層
can you let me know what you want to do?
like bluetooth, servo control or something else?
roboardgod 發表於 2013-7-30 17:37



    I want my bluetooth to connect and control the servo.
 樓主| 發表於 2013-7-31 16:41:41 | 顯示全部樓層
Then...? what's the problem?
Here is my process:
(Android) read file -> create buttons -> button onclick event -> send motion data
(Robot) waiting data -> get data -> servo control

Are you using RoBoard on your robot?
發表於 2013-7-31 21:34:44 | 顯示全部樓層
本帖最後由 goldpower 於 2013-7-31 21:58 編輯
Then...? what's the problem?
Here is my process:
(Android) read file -> create buttons -> button o ...
roboardgod 發表於 2013-7-31 16:41


  I'm using the rb110 .
  I'm using the mono android in visual studio 2012  :   http://xamarin.com/

How do I send a  string from android phone to computer?

I need source code for Rb110 and Android phone ( sony xperia tipo).
 樓主| 發表於 2013-8-1 11:37:36 | 顯示全部樓層
本帖最後由 roboardgod 於 2013-8-1 11:42 編輯

回復 7# goldpower

okay..first, you need to install bluetooth driver on roboard
then, pair your devices
then, set com port for your device




Here's a simple sample code:
roboard (VC2008):
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. int main () {
  5.         int i;
  6.         DWORD dwBytesRead = 0;
  7.     unsigned char Read_Packet1[2] = {0};
  8.         HANDLE Serial = CreateFile(TEXT("\\\\.\\COM10"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, NULL);  //to COM10
  9.         if (Serial == INVALID_HANDLE_VALUE){
  10.                 printf("serial error");
  11.                 getchar();
  12.                 return 1;
  13.         }
  14.         DCB dcbSerialParams = {0};
  15.         dcbSerialParams.BaudRate=115200;
  16.         dcbSerialParams.ByteSize=8;
  17.         dcbSerialParams.StopBits=ONESTOPBIT;
  18.         dcbSerialParams.Parity=NOPARITY;
  19.         if(!SetCommState(Serial, &dcbSerialParams)){
  20.                 printf("com setting error!!\n");
  21.                 goto End;
  22.         }

  23.         COMMTIMEOUTS timeouts={0};        
  24.         timeouts.ReadIntervalTimeout = MAXDWORD;
  25.         timeouts.ReadTotalTimeoutConstant = 500;
  26.         timeouts.ReadTotalTimeoutMultiplier = 20;
  27.         timeouts.WriteTotalTimeoutConstant = 20;
  28.         timeouts.WriteTotalTimeoutMultiplier = 20;

  29.         if (!SetCommTimeouts(Serial, &timeouts)){
  30.                 printf("timeout error!\n");
  31.                 goto End;
  32.         }
  33.         while(!kbhit()){   //loop until keyboard click
  34.                 ReadFile(Serial, Read_Packet1, 1, &dwBytesRead, NULL);
  35.                 Read_Packet1[1] = '\0';
  36.                 if(Read_Packet1[0])
  37.                         printf("%s", Read_Packet1);
  38.                 Read_Packet1[0] = 0;
  39.         }
  40. End:
  41.         CloseHandle(Serial);
  42.         getchar();
  43.         return 0;
  44. }
複製代碼

   


Android phone(eclipse):
layout: one Button and one EditText

  1. package com.example.bluetooth_client;

  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.util.Set;
  5. import java.util.UUID;

  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12. import android.app.Activity;
  13. import android.bluetooth.*;
  14. import android.content.Intent;

  15. public class MainActivity extends Activity {
  16.          private static final String TAG = "DEBUG";
  17.          private static final boolean D = true;
  18.          private BluetoothAdapter mBluetoothAdapter = null;
  19.          private BluetoothSocket btSocket = null;
  20.          private OutputStream outStream = null;
  21.          private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  22.          private static String address = "00:00:00:00:00:00";        //roboard's bluetooth device address
  23.      
  24.      @Override
  25.      public void onCreate(Bundle savedInstanceState) {
  26.                super.onCreate(savedInstanceState);
  27.                setContentView(R.layout.activity_main);
  28.                Button sendButton = (Button) findViewById(R.id.button);
  29.                sendButton.setOnClickListener(new Button.OnClickListener(){
  30.                     public void onClick(View arg0){
  31.                        TextView enteredText = (TextView)findViewById(R.id.entertext);
  32.                                  String message = enteredText.getText().toString();
  33.                                  byte[] msgBuffer = message.getBytes();
  34.                                  try {
  35.                                       outStream.write(msgBuffer);
  36.                                  } catch (IOException e) {
  37.                                       Log.e(TAG, "ON RESUME: Exception during write.", e);
  38.                              }
  39.                     }
  40.                 });
  41.                if (D)
  42.                     Log.e(TAG, "+++ ON CREATE +++");
  43.                        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  44.             
  45.                if (mBluetoothAdapter == null) {
  46.                     Toast.makeText(this,"Bluetooth is not available.", Toast.LENGTH_LONG).show();
  47.                     finish();
  48.                     return;
  49.                }
  50.                if (!mBluetoothAdapter.isEnabled()) {
  51.                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  52.                    startActivityForResult(enableBtIntent, 1);
  53.                }
  54.                if (!mBluetoothAdapter.isEnabled()) {
  55.                     Toast.makeText(this, "Please enable your BT and re-run this program.", Toast.LENGTH_LONG).show();
  56.                     finish();
  57.                     return;
  58.                }
  59.                Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
  60.                     if (pairedDevices.size() > 0) {
  61.                         for (BluetoothDevice device : pairedDevices) {
  62.                                 Log.e(TAG,device.getName() + "\n" + device.getAddress());
  63.                         }
  64.                     }
  65.           }
  66.           @Override
  67.           public void onResume() {
  68.                super.onResume();
  69.                BluetoothDevice device = null;
  70.                if (D) {
  71.                     Log.e(TAG, "+ ON RESUME +");
  72.                     Log.e(TAG, "+ ABOUT TO ATTEMPT CLIENT CONNECT +");
  73.                    }
  74.                if(BluetoothAdapter.checkBluetoothAddress(address))
  75.                        device = mBluetoothAdapter.getRemoteDevice(address);
  76.                else{
  77.                      Log.e(TAG, "+++ address fail +++");
  78.                }
  79.                   
  80.                    try {
  81.                         btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
  82.                    } catch (IOException e) {
  83.                         Log.e(TAG, "ON RESUME: Socket creation failed.", e);
  84.                    }
  85.                
  86.                    mBluetoothAdapter.cancelDiscovery();
  87.                    try {
  88.                         btSocket.connect();
  89.                         Log.e(TAG, "ON RESUME: BT connection established, data transfer link open.");
  90.                    } catch (IOException e) {
  91.                         try {
  92.                              btSocket.close();
  93.                         } catch (IOException e2) {
  94.                              Log.e(TAG,"ON RESUME: Unable to close socket during connection failure", e2);
  95.                         }
  96.                    }
  97.                
  98.                    if (D)
  99.                         Log.e(TAG, "+ ABOUT TO SAY SOMETHING TO SERVER +");
  100.                
  101.                    try {
  102.                         outStream = btSocket.getOutputStream();
  103.                    } catch (IOException e) {
  104.                         Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
  105.                    }
  106.                
  107.                   
  108.           }
  109.         
  110.           @Override
  111.           public void onPause() {
  112.                super.onPause();
  113.         
  114.                if (D)
  115.                     Log.e(TAG, "- ON PAUSE -");
  116.         
  117.                    if (outStream != null) {
  118.                         try {
  119.                              outStream.flush();
  120.                         } catch (IOException e) {
  121.                              Log.e(TAG, "ON PAUSE: Couldn't flush output stream.", e);
  122.                         }
  123.                    }
  124.                    try  {
  125.                         btSocket.close();
  126.                    } catch (IOException e2) {
  127.                 Log.e(TAG, "ON PAUSE: Unable to close socket.", e2);
  128.                }
  129.           }
  130. }
複製代碼



and don't forget permission:
  1. <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />        
  2. <uses-permission android:name="android.permission.BLUETOOTH" />
複製代碼
發表於 2013-8-1 17:34:28 | 顯示全部樓層
Hi
Please attach the project eclipse.
 樓主| 發表於 2013-8-2 14:13:00 | 顯示全部樓層
I'm already gave you a sample code
please try it yourself, thx
發表於 2013-8-2 15:06:18 | 顯示全部樓層
cannot import android.os.   ????

 樓主| 發表於 2013-8-2 15:43:17 | 顯示全部樓層
本帖最後由 roboardgod 於 2013-8-2 16:03 編輯

Have you installed android SDK?
發表於 2013-8-2 19:05:19 | 顯示全部樓層
本帖最後由 goldpower 於 2013-8-6 00:00 編輯

All problems were solved.

Thank you

您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-3-29 22:55 , Processed in 0.161197 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表