RoBoard魔人的機器人日誌

2013/12/6

[機械六足] 智慧手機控制器

上次發了一篇近況文

也告訴了大家我下一步想要做的東西

那魔人就來一步一步的製作&分享給大家吧

今天要分享的是智慧手機控制器的搖桿控制

還記得上次我的介紹吧

我要用遙感的方式控制六足的前進方向

而遙桿在網路上的範例已經有很多了

實做的方法是這樣的

用canvas畫圖 & 用Thread讀取螢幕觸碰的事件

讀取後去計算 & 重新畫圖   就可以做到搖桿的效果了

以下影片範例



這個範例是控制小android在螢幕上移動




接著是程式碼囉

MainActivity.java

package com.example.joystick;

import android.os.Bundle;
import android.app.Activity;
import android.view.WindowManager;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(new GameSurface(this));
 }
}

GameControl.java
package com.example.joystick;

import android.graphics.Point;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class GameControls implements OnTouchListener{

 public float initx = 0;
 public float inity = 0;
 public Point _touchingPoint = new Point(0,0);
 public Point _pointerPosition = new Point(220,150);
 private Boolean _dragging = false;
 private double degree = 0;
 @Override
 public boolean onTouch(View v, MotionEvent event) {

  update(event);
  return true;
 }

 private MotionEvent lastEvent;
 public void update(MotionEvent event){

  if (event == null && lastEvent == null)
  {
   return;
  }else if(event == null && lastEvent != null){
   event = lastEvent;
  }else{
   lastEvent = event;
  }
  if ( event.getAction() == MotionEvent.ACTION_DOWN ){
   _dragging = true;
  }else if ( event.getAction() == MotionEvent.ACTION_UP){
   _dragging = false;
  }
  

  if ( _dragging ){
   _touchingPoint.x = (int)event.getX();
   _touchingPoint.y = (int)event.getY();
   
   _touchingPoint.x -= 250;
   _touchingPoint.y -= 250;
   if(_touchingPoint.x == 0 && _touchingPoint.y > 0)
    degree = Math.PI / 2;
   else if(_touchingPoint.x == 0 && _touchingPoint.y < 0)
    degree = Math.PI / 2 * 3;
   else if(_touchingPoint.x > 0)
    degree = Math.atan((double)_touchingPoint.y/_touchingPoint.x);
   else if(_touchingPoint.x < 0)
    degree = Math.PI + Math.atan((double)_touchingPoint.y/_touchingPoint.x);
   
   if(Math.sqrt(Math.pow(_touchingPoint.x,2) + Math.pow(_touchingPoint.y,2)) > 150){

    _touchingPoint.x = (int) (150.0 * Math.cos(degree));
    _touchingPoint.y = (int) (150.0 * Math.sin(degree));
    
   }
   
   _pointerPosition.x += ((double)_touchingPoint.x/30);
   _pointerPosition.y += ((double)_touchingPoint.y/30);
   if ( _pointerPosition.x > 480)
   {
    _pointerPosition.x= 0;
   }

   if ( _pointerPosition.x < 0){
    _pointerPosition.x = 480;
   }

   if (_pointerPosition.y > 840 ){
    _pointerPosition.y = 0;
   }
   if (_pointerPosition.y < 0){
    _pointerPosition.y = 840;
   }

  }else if (!_dragging)
  {
   if(Math.sqrt(Math.pow(_touchingPoint.x,2) + Math.pow(_touchingPoint.y,2)) <= 10){
    _touchingPoint.x = (int) initx;
    _touchingPoint.y = (int) inity;
   }else{
    _touchingPoint.x = (int) ((Math.sqrt(Math.pow(_touchingPoint.x,2) + Math.pow(_touchingPoint.y,2)) - 10)* Math.cos(degree));
    _touchingPoint.y = (int) ((Math.sqrt(Math.pow(_touchingPoint.x,2) + Math.pow(_touchingPoint.y,2)) - 10)* Math.sin(degree));
   }
   _pointerPosition.x += ((double)_touchingPoint.x/30);
   _pointerPosition.y += ((double)_touchingPoint.y/30);
   if (_pointerPosition.x > 480)
    _pointerPosition.x= 0;
   if (_pointerPosition.x < 0)
    _pointerPosition.x = 480;
   if (_pointerPosition.y > 840)
    _pointerPosition.y = 0;
   if (_pointerPosition.y < 0)
    _pointerPosition.y = 840;
  }
 }
}


GameJoystick.java
package com.example.joystick;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class GameJoystick {
 
 private Bitmap _joystick;
 private Bitmap _joystickBg;
 private Bitmap _trigger;
 private Bitmap _triggerDown;
 
 public Bitmap get_triggerDown() {
  return _triggerDown;
 }

 public void set_triggerDown(Bitmap triggerDown) {
  _triggerDown = triggerDown;
 }

 public GameJoystick(Resources res){
  
  _joystick = (Bitmap)BitmapFactory.decodeResource(res, com.example.joystick.R.drawable.joystick2);
  _joystickBg = (Bitmap)BitmapFactory.decodeResource(res, com.example.joystick.R.drawable.joystick_bg2);

 }

 public Bitmap get_joystick() {
  return _joystick;
 }

 public void set_joystick(Bitmap joystick) {
  _joystick = joystick;
 }

 public Bitmap get_joystickBg() {
  return _joystickBg;
 }

 public void set_joystickBg(Bitmap joystickBg) {
  _joystickBg = joystickBg;
 }
 
 public Bitmap get_trigger() {
  return _trigger;
 }

 public void set_trigger(Bitmap trigger) {
  _trigger = trigger;
 }
}


GameSurface.java
package com.example.joystick;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Handler;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class GameSurface extends SurfaceView implements SurfaceHolder.Callback {

 private Context _context;
 private GameThread _thread;
 private GameControls _controls;

 private GameJoystick _joystick;
 private Bitmap _pointer;

 public GameSurface(Context context) {
  super(context);
  _context = context;
  init();
 }

 private void init(){
  SurfaceHolder holder = getHolder();
  holder.addCallback( this);

  _thread = new GameThread(holder, _context, new Handler(),this);
  setFocusable(true);


  _joystick = new GameJoystick(getContext().getResources());
  _pointer = (Bitmap)BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
  _controls = new GameControls();
  setOnTouchListener(_controls);
 }


 public void doDraw(Canvas canvas){

  _controls.update(null);
  
  canvas.drawBitmap(_joystick.get_joystickBg(), 100,100, null);

  canvas.drawBitmap(_joystick.get_joystick(),_controls._touchingPoint.x + 200, _controls._touchingPoint.y + 200, null);

  canvas.drawBitmap(_pointer, _controls._pointerPosition.x, _controls._pointerPosition.y, null);

 }

 @Override
 public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {}
 private boolean retry;
 @Override
 public void surfaceDestroyed(SurfaceHolder arg0) {
  retry = true;
  _thread.state = GameThread.STOPED;
  while (retry) {
   try {
    _thread.join();
    retry = false;
   } catch (InterruptedException e) {
   }
  }

 }

 @Override
 public void surfaceCreated(SurfaceHolder arg0) {
  if(_thread.state==GameThread.PAUSED){
   _thread = new GameThread(getHolder(), _context, new Handler(),this);
   _thread.start();
  }else{
   _thread.start();
  }
 }

 public void Update() {

 }

}



GameThread.java
package com.example.joystick;

import java.util.logging.Level;
import java.util.logging.Logger;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.view.SurfaceHolder;

public class GameThread extends Thread {

 private SurfaceHolder mSurfaceHolder;
 private Handler mHandler;
 private Context mContext;
 private Paint mLinePaint;
 private Paint blackPaint;

 private long sleepTime;
 private long delay=70;
 int state = 1;
 public final static int RUNNING = 1;
 public final static int PAUSED = 2;
 public final static int STOPED = 3;

 GameSurface gEngine;

 public GameThread(SurfaceHolder surfaceHolder, Context context, Handler handler,GameSurface gEngineS){
  mSurfaceHolder = surfaceHolder;
  mHandler = handler;
  mContext = context;
  gEngine=gEngineS;
 }

 private long beforeTime;
 @Override
 public void run() {

  //UPDATE
  while (state==RUNNING) {
   try {
    this.sleep(50);
   } catch (InterruptedException e1) {
    e1.printStackTrace();
   }
   beforeTime = System.nanoTime();
   gEngine.Update();

   Canvas c = null;
   try {
    c = mSurfaceHolder.lockCanvas(null);
    synchronized (mSurfaceHolder) {
     c.drawColor(0x66000000);
     gEngine.doDraw(c);
    }
   } finally {
    if (c != null) {
     mSurfaceHolder.unlockCanvasAndPost(c);
    }
   }


   this.sleepTime = delay-((System.nanoTime()-beforeTime)/1000000L);

   try {
    if(sleepTime>0){
     this.sleep(sleepTime);
    }
   } catch (InterruptedException ex) {
    Logger.getLogger(GameThread.class.getName()).log(Level.SEVERE, null, ex);
   }
   
   while (state==PAUSED){
    try {
     this.sleep(1000);
    } catch (InterruptedException e) {
     e.printStackTrace();
    }
   }
  }
 }}

Share:

2013/11/29

[RB魔人] 用小型區網建立良好的開發環境(五)

最近魔人拿到了一塊好東西


沒錯   它就是無線wifi啦

大家可能會好奇   現在這個時代   wifi有什麼好稀奇的

各位還記得魔人之前有發了四篇的系列文章也是介紹網路的嘛?

這次要介紹的就是   如何用wifi建立良好的開發環境

剩(線)勝有(線)嘛

而且之前本魔是使用藍芽做控制的

現在也不用這麼麻煩了

用網路就好啦~

檔案傳輸也沒問題

如此方便   就快點來教學吧

首先要有一顆USB的無線AP

裝上RoBoard



之後安裝驅動程式




安裝完之後便可找到裝置

之後設定wifi的名稱等




之後選橋接器連結   將無線網路與區網連結在一起


之後進入剛剛設定的網路就可以囉




再來是PC端

選擇連線後輸入密碼

之後就是一個小型的區域網路囉 

你也可以直接遠端到另一台電腦





















這讓本魔想到了

在某些地方連wifi時不是會有登入的頁面跑出來嘛?

如果我把機器人的手機控制程式丟在登入的網頁

那麼不就能夠用任何一台的手機裝置去控制了?


所以我最近會順便研究看看wifi登入頁面那如何實做

如果有神人知道方法    也敬請指教喔^^
Share:

2013/11/3

[機械六足] 近期新計畫

兩個月沒有更新文章了

大家有沒有想魔人阿XD

其實這一兩個月真的是由於學校的事務所以有些忙碌

然而這一兩個月魔人也不是閒著的喔!

這次要進行機械六足的新計畫了

之前各位都有看到我與實習生們合力製作的[RoBoard x League of Legends] 史加納Skarnar

而當時推出的影片也受到了大家的肯定及迴響   ((在此說聲謝謝

而現在魔人要一個人繼續製作這台機械六足

將步態變得更加的完整

之前的步態   如果各位有看過source code   或是認真看過影片的話

就會發現其實我的移動方式只有6種

包括前後左右平移,加上左右轉彎

而魔人我是不會就此滿足的!

所以現在魔人我有一個新的想法

用智慧手機控制機械六足!

以下為設計草圖


























看不懂沒關係!

魔人來為您解釋

首先就是手機上會有搖桿的圖示

在上面推移就會決定機械六足的前進方向以及步距or速度

而智慧手機上的陀螺儀感測器可以決定六足身體的平衡


那各位說不定會想問這樣到底有幾種步態

答案是1~2種   一種是轉彎的步態  一種是平移的步態

大家別急!

雖然是只有兩種步態   但是移動的方向是由搖桿決定的

而那排列組合   就可以請各位去計算看看了

而或許也會想加入一些對話的功能

這方面還在思考要怎麼做當中











別認為魔人我是光說不練的

魔人我其實有開始在動工了喔!

近期會有個小成果上來給各位看看的!
Share:

2013/9/5

[RoBoard x League of Legends] 史加納Skarnar

相信各位都知道現在相當火紅的遊戲英雄聯盟

本魔此次與第六屆的實習生們一起合作做了一隻英雄聯盟裡的角色

而此次的作品也是完全open source的

但我們必須要在2個月內趕出成果,所以我們很快的開始了這個開源計畫



最一開始

我們有想過製作烏爾加特或布里茲

烏爾加特

布里茲
但是我們最後決定選擇了史加納

史加納


六隻腳走起來比較霸氣!對吧?

所以大家開始著手製作,基本上本魔負責最後的程式控制

而機構設計以及電路與造型則是交由實習生們來做

於是找到了一款較適合機器人的模組讓我們參考


在大家的努力下,首先做出了Solidworks的機構圖


相當帥氣對吧?

基本上頭部與外殼要用3D printer印出來,這樣也可以做出我們要的樣子

既然畫好圖了,那麼大家就開始動手實做出來

而本魔也沒閒著

六足機器人如果還用編動作的不是就low掉了嗎!?

沒錯!

這次本魔要用反運動學來算!

所以要了機構的長度,以方便計算



第一次拿到實體機器時,本魔相當興奮


立刻用RoBoME簡單的編了一個走路

立刻來看看由於是貼在facebook上面,所以要請各位移駕一下

==========>影片連結video link<==========

可以很明顯的感受到機械式的走法

但本魔是不會安於現狀的!

約過了一周,首先史加納的頭印好了,而本魔的反運動學步行也有了個雛形



以下影片


看起來順暢許多吧?

沒錯,而且加上了手的動作,實在霸氣許多

最後,完整版出來了

眼睛加上了紅色的LED

外殼也加了上去

甚至加了噴漆做顏色裝飾

還有最霸氣的超大聲喇叭

先來看看圖片吧!


帥吧!?

別急

後面還有影片!






最後來個maker的合影



既然是open source的計畫

那當然要opne code與design了

以下連結

Github Robot-Skarnar

RoBoard粉絲專頁



Maker list:
朱酉致 / Chu Ue Chih
李智皓 / Li Chih Hao
鄒秉翰 / Tsou Ping Han
RB魔人 / RoBoardGod


如果你喜歡,請幫我們到facebook按【讚】,謝謝。
If you like this, please click the【Like!】on our facebook comment, thank you.


Share:

2013/8/9

[教學] 如何使用C#存取MySQL資料庫

今天本魔要講講如何使用C#存取MySQL資料庫

MySQL是一個open source的關聯性資料庫管理系統

可能會有人有疑問說:「資料庫和機器人怎麼有會關聯呢?」

本魔在此告訴你!一定有關聯的!

因為關聯這種東西就是讓我們扯出來的!

在網路上的資料庫可以隨時供電腦做存取

這樣一來,我們就可以很方便的管理一些資料了

也有可能可以把動作資料建立在資料庫上供機器人使用(好像很久以前有人就有給過我這個建議了)

這樣除了較不用擔心資料會隨著機器人損壞

更增加了許多的擴充性




那麼本魔在此就不教學如何安裝MySQL了

各位自己上網Google應該很好找到

那麼就開始我們的教學!

首先各位需要安裝MySQL官方所提供的Connector

安裝好了之後就可以開啟我們的Visual Studio建一個C#的專案囉!

首先要加入參考    [Project] ->[Add Reference]->[瀏覽]

選擇安裝路徑下的MySql.Data.dll



路徑通常在C:\Program Files\MySQL\MySQL Connector Net 6.6.5\Assemblies\v2.0

加入參考了之後會看到方案總管內的Reference有加入了MySql.Data囉


接了我們就可以開始撰寫程式囉

以下給各位新增、刪除、修改、查詢的範例

其實相當簡單

基本上就是與MySQL一樣   丟一串指令給他   他會回傳一些資料給你

首先假設我們的資料表的內容是這樣子的而資料表名稱為member


那我們先來新增10筆會員資料


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace MySQLtest
{
    class Program
    {
        static void Main(string[] args)
        {
            string dbHost = "";//資料庫位址
            string dbUser = "";//資料庫使用者帳號
            string dbPass = "";//資料庫使用者密碼
            string dbName = "";//資料庫名稱

            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            String account;
            String password;
            int level;
            for(int i = 0; i < 10; i++){
                account = "account" + i.ToString();
                password = "password" + i.ToString();
                level = i * 10;
                command.CommandText = "Insert into member(account,password,level) values('"+ account +"','"+ password +"',"+ level +")";
                command.ExecuteNonQuery();
            }
            Console.ReadLine();
            conn.Close();
        }
    }
}


這樣執行後我們就可以看到資料表內增加了十筆資料囉
接著是刪除

假如我想刪除id為15的用戶

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace MySQLtest
{
    class Program
    {
        static void Main(string[] args)
        {            string dbHost = "";//資料庫位址
            string dbUser = "";//資料庫使用者帳號
            string dbPass = "";//資料庫使用者密碼
            string dbName = "";//資料庫名稱

            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();


            command.CommandText = "Delete FROM member WHERE id=15";
            int n  = command.ExecuteNonQuery();

            Console.WriteLine("共刪除 {0} 筆資料", n);
            Console.ReadLine();
            conn.Close();
        }
    }
}



那麼執行後就可以發現id為15的資料不見囉

接著是修改

這裡把account6的password改為1234

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace MySQLtest
{
    class Program
    {
        static void Main(string[] args)
        {            string dbHost = "";//資料庫位址
            string dbUser = "";//資料庫使用者帳號
            string dbPass = "";//資料庫使用者密碼
            string dbName = "";//資料庫名稱
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();


            command.CommandText = "Update member SET password='1234' WHERE account='account6'";
            command.ExecuteNonQuery();


            Console.ReadLine();
            conn.Close();
        }
    }
}



再來看看資料表   沒錯   正確的改過去了


最後就是查詢啦

那我們來查詢看看level小於50的所有用戶

然後顯示在電腦上吧

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace MySQLtest
{
    class Program
    {
        static void Main(string[] args)
        {   string dbHost = "";//資料庫位址
            string dbUser = "";//資料庫使用者帳號
            string dbPass = "";//資料庫使用者密碼
            string dbName = "";//資料庫名稱
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            String cmdText = "SELECT * FROM member WHERE level < 50";
            MySqlCommand cmd = new MySqlCommand(cmdText, conn);
            MySqlDataReader reader = cmd.ExecuteReader(); //execure the reader
            while (reader.Read())
            {
                for (int i = 0; i < 4; i++)
                {
                    String s = reader.GetString(i);
                    Console.Write(s + "\t");
                }
                Console.Write("\n");
            }


            Console.ReadLine();
            conn.Close();
        }
    }
}





最後結果是

正確!
Share:

2013/7/5

[RoBoME] Smartphone Controller

最近進擊巨人很夯

所以機器人也要進擊一下這樣
以下影片演示給大家看:







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

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

聽起來相當的容易吧~

以下教學

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

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

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

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

然後將檔案放入即可喔!

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

或有聲音也要放入喔

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

第一個欄位用來選rbm檔案

第二個欄位為選擇藍芽通道
 完成後按下Start
出現此介面後

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

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

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

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

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



P.S.介面相當的陽春   不過別太介意啦=D   有時間的話再來認真的設計界面吧
Share:

2013/6/7

[練習] AX-12輪胎 簡易控制程式

在很久之前本魔有介紹過AX-12轉動的方法

而今天我要介紹的是AX-12的全轉模式

基本上在官方的文件中有提到喔!

Address 0x20,0x21 
Moving Speed. Sets the angular velocity of the output moving to the Goal Position. Setting this value to its maximum value of 0x3ff moves the output with an angular velocity of 114 RPM, provided that there is enough power supplied (The lowest velocity is when this value is set to 1. When set to 0, the velocity is the largest possible for the supplied voltage, e.g. no velocity control is applied.)

沒錯的   所以我們只要將Operating Angle Limit設定為0    它就會進入全轉模式

而官方文件中也有寫到Operating Angle Limit 的Address為0x06,0x07,0x08,0x09

在這之後我們只要控制轉動速度    就可以讓馬達旋轉囉!!

那就讓我們來看看程式碼吧!!

首先看看介面的設計 在此本魔是使用C#來做的


應該是不會很難理解的

下面的上下左右button是可以讓輪胎轉動   直到按下stop button

上面的 speed則是可以調整轉速

keyboard mode則是可以讓我們使用WSAD來控制輪胎

那我們來看看本魔實做的辦法吧   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RoBoIO_DotNet;
namespace controller_AX12
{
    public partial class Form1 : Form
    {
        public byte[] ax01 = new byte[11]{ 0xff, 0xff, 0x0f, 0x07, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00 };
        public byte[] ax02 = new byte[11]{ 0xff, 0xff, 0x12, 0x07, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00 };
        public byte[] read = new byte[6];
        public int run;
        public Form1()
        {
            InitializeComponent();
            groupBox1.Enabled = false;
            checkBox1.Enabled = false;
            run = 0;
            
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //RoBoIO.com3_DisableTurboMode();
            RoBoIO.com3_Close();
        }
        private void Start_Click(object sender, EventArgs e)
        {
            if (!groupBox1.Enabled){
                if (!RoBoIO.roboio_SetRBVer(RoBoIO.RB_100RD))
                    MessageBox.Show("roboio_SetRBVer fail");
                if (!RoBoIO.com3_Init(RoBoIO.COM_HDUPLEX))
                    MessageBox.Show("com3_Init fail");
                if (!RoBoIO.com3_SetFormat(RoBoIO.COM_BYTESIZE8, RoBoIO.COM_STOPBIT1, RoBoIO.COM_NOPARITY))
                    MessageBox.Show("com3_SetFormat fail");
                if (!RoBoIO.com3_SetBaud(RoBoIO.COMBAUD_115200BPS))
                    MessageBox.Show("com3_SetBaud fail");
                //RoBoIO.com3_EnableTurboMode();
                groupBox1.Enabled = true;
                checkBox1.Enabled = true;
                Start.Enabled = false;
                ax02[10] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7] + ax02[8] + ax02[9]))[0];
                ax01[10] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7] + ax01[8] + ax01[9]))[0];
                if (!RoBoIO.com3_ServoTRX(ax01, 11, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                if (!RoBoIO.com3_ServoTRX(ax02, 11, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                ax01[3] = 0x05;
                ax01[5] = 0x20;
                ax02[3] = 0x05;
                ax02[5] = 0x20;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            xUp();
        }
        private void xUp() {
            int speed = 10;
            if (run != 0)
            {
                Stop(5);
                speed = 5;
            }
            int v = speedbar.Value;
            run = 1;
            for (int i = 0; i < v % 0x3ff; i = i + v / speed)
            {
                ax01[6] = BitConverter.GetBytes(0x00ff & (i + 0x400))[0];
                ax01[7] = BitConverter.GetBytes((0xff00 & (i + 0x400)) / 0xff)[0];
                ax02[6] = BitConverter.GetBytes(0x00ff & i)[0];
                ax02[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                RoBoIO.delay_ms(25);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            xdown();
        }
        private void xdown() {
            int speed = 10;
            if (run != 0)
            {
                Stop(5);
                speed = 5;
            }
            int v = speedbar.Value;
            run = 2;
            for (int i = 0; i < v % 0x3ff; i = i + v / speed)
            {
                ax01[6] = BitConverter.GetBytes(0x00ff & i)[0];
                ax01[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                ax02[6] = BitConverter.GetBytes(0x00ff & (i + 0x400))[0];
                ax02[7] = BitConverter.GetBytes((0xff00 & (i + 0x400)) / 0xff)[0];
                ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                RoBoIO.delay_ms(25);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            xleft();
        }
        private void xleft() {
            int speed = 10;
            if (run != 0)
            {
                Stop(5);
                speed = 5;
            }
            int v = speedbar.Value;
            run = 3;
            for (int i = 0; i < v % 0x3ff; i = i + v / speed)
            {
                ax01[6] = BitConverter.GetBytes(0x00ff & (i + 0x400))[0];
                ax01[7] = BitConverter.GetBytes((0xff00 & (i + 0x400)) / 0xff)[0];
                ax02[6] = BitConverter.GetBytes(0x00ff & (i + 0x400))[0];
                ax02[7] = BitConverter.GetBytes((0xff00 & (i + 0x400)) / 0xff)[0];
                ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                RoBoIO.delay_ms(25);
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            xright();
        }
        private void xright() {
            int speed = 10;
            if (run != 0)
            {
                Stop(5);
                speed = 5;
            }
            int v = speedbar.Value;
            run = 4;
            for (int i = 0; i < v % 0x3ff; i = i + v / speed)
            {
                ax01[6] = BitConverter.GetBytes(0x00ff & i)[0];
                ax01[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                ax02[6] = BitConverter.GetBytes(0x00ff & i)[0];
                ax02[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                    MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                RoBoIO.delay_ms(25);
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            Stop(10);
        }
        private void Stop(int speed)
        {
            if (run != 0)
            {
                int v = speedbar.Value;
                switch (run)
                {
                    case 1:
                        for (int i = v % 0x3ff; i > 0; i = i - v / speed)
                        {
                            ax01[6] = BitConverter.GetBytes(0x00ff & (i + 0x3ff))[0];
                            ax01[7] = BitConverter.GetBytes((0xff00 & (i + 0x3ff)) / 0xff)[0];
                            ax02[6] = BitConverter.GetBytes(0x00ff & i)[0];
                            ax02[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                            ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                            ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                            if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            RoBoIO.delay_ms(25);
                        }
                        break;
                    case 2:
                        for (int i = v % 0x3ff; i > 0; i = i - v / speed)
                        {
                            ax01[6] = BitConverter.GetBytes(0x00ff & i)[0];
                            ax01[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                            ax02[6] = BitConverter.GetBytes(0x00ff & (i + 0x3ff))[0];
                            ax02[7] = BitConverter.GetBytes((0xff00 & (i + 0x3ff)) / 0xff)[0];
                            ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                            ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                            if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            RoBoIO.delay_ms(25);
                        }
                        break;
                    case 3:
                        for (int i = v % 0x3ff; i > 0; i = i - v / speed)
                        {
                            ax01[6] = BitConverter.GetBytes(0x00ff & (i + 0x3ff))[0];
                            ax01[7] = BitConverter.GetBytes((0xff00 & (i + 0x3ff)) / 0xff)[0];
                            ax02[6] = BitConverter.GetBytes(0x00ff & (i + 0x3ff))[0];
                            ax02[7] = BitConverter.GetBytes((0xff00 & (i + 0x3ff)) / 0xff)[0];
                            ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                            ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                            if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            RoBoIO.delay_ms(25);
                        }
                        break;
                    case 4:
                        for (int i = v % 0x3ff; i > 0; i = i - v / speed)
                        {
                            ax01[6] = BitConverter.GetBytes(0x00ff & i)[0];
                            ax01[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                            ax02[6] = BitConverter.GetBytes(0x00ff & i)[0];
                            ax02[7] = BitConverter.GetBytes((0xff00 & i) / 0xff)[0];
                            ax02[8] = BitConverter.GetBytes(~(ax02[2] + ax02[3] + ax02[4] + ax02[5] + ax02[6] + ax02[7]))[0];
                            ax01[8] = BitConverter.GetBytes(~(ax01[2] + ax01[3] + ax01[4] + ax01[5] + ax01[6] + ax01[7]))[0];
                            if (!RoBoIO.com3_ServoTRX(ax01, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            if (!RoBoIO.com3_ServoTRX(ax02, 9, read, 6))
                                MessageBox.Show("com3_ServoTRX fail read back = " + read[0] + " " + read[1] + " " + read[2] + " " + read[3] + " " + read[4] + " " + read[5]);
                            RoBoIO.delay_ms(25);
                        }
                        break;
                }
                run = 0;
            }
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                groupBox1.Enabled = false;
            }
            else {
                groupBox1.Enabled = true;
            }
        }
        private void checkBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (checkBox1.Checked)
            {
                if (e.KeyCode == Keys.W && run != 1)
                    xUp();
                else if (e.KeyCode == Keys.S && run != 2)
                    xdown();
                else if (e.KeyCode == Keys.A && run != 3)
                    xleft();
                else if (e.KeyCode == Keys.D && run != 4)
                    xright();
            }
        }
        private void checkBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if(checkBox1.Checked){
                if (run != 0)
                Stop(10);
            }
        }
    }
}

Share:

2013/6/6

[RoBoard魔人] DMP秘密機器人-Zero上半身 輪胎測試

各位大家好

如果大家有在關注這台機器人的話就會知道

他現在有分上下半身

下半身之前已經給各位看過他的走路了

雖然目前還是有點弱弱的走路

但我相信 近期內我會將他改得較順暢
 DMP秘密機器人-Zero下半身
 DMP秘密機器人-Zero下半身
加上了殼  變得更安全


而今天的主角呢   就是上半身啦!
 DMP秘密機器人-Zero上半身

沒錯

加上了輪子依然霸氣十足

這輪子是使用AX-12來驅動的

而AX-12也是可以使用360度旋轉的喔!!

這樣就可以用輪子來移動了

來看看影片吧!!




至於這小程式的code    我會再做介紹的!
Share:
技術提供:Blogger.

追蹤者