買書捐殘盟

顯示具有 nxc 標籤的文章。 顯示所有文章
顯示具有 nxc 標籤的文章。 顯示所有文章

2013年4月14日 星期日

UltraSonicSensor應用-保護眼睛的守護神


NXT ,保護眼睛的守護神!
當超音波偵測到前方人體離電視太近的時候,系統發出Light光線及聲音警告。
   
[機構]

[程式]
 #define sonic_sensor IN_1
#define touch_sensor IN_2
#define light_sensor IN_3
#define touch SENSOR_2
#define MotorOut OUT_B
#define length 150

long tick;


void WaitSEC3()
{
   tick=CurrentTick();
   while(CurrentTick()<(tick+3000))
   {
       PlayTone(880,50);
       Wait(950);
   }
   Wait(1000);
}




task main()
{
    SetSensorTouch(touch_sensor);
    ResetTachoCount(MotorOut);
    SetVolume(4);
    SetSensorLight(light_sensor,false);
    SetSensorLowspeed(sonic_sensor);
    WaitSEC3();
}


task MotorRotateFn()
{
   Follows(main);
   while(touch==0)
   {
      RotateMotorPID(MotorOut,10,90,40,40,90);    //右轉
      Wait(100);
      RotateMotorPID(MotorOut,10,-170,40,40,90);  //左轉
      Wait(100);
      RotateMotorPID(MotorOut,10,80,40,40,90);    //右轉
   }
   Off(MotorOut);
   StopAllTasks();
}

task DetectFn()
{
   Follows(main);
   while(true)
   {
     if(SensorUS(sonic_sensor) <length{
       PlayTone(500,50);
       SetSensorLight(light_sensor,true);
       Wait(50);
       SetSensorLight(light_sensor,false);
       Wait(50);
     }
   }
}
[影片]                                  

2013年4月5日 星期五

齒輪機構-玩玩

感謝探奇邱老師給予的資料(如參考資料)。
齒輪機構,有趣的地方在於透過齒輪之間的串合,可以有非常多的變化,因此被應用在馬達速度(差速)的變化。

齒輪比,藉由兩個齒輪串合,我們從經驗得知,大齒輪轉一圈,小齒輪轉動n圈,便可以做到差速的轉換。例如圖中:
與馬達串合在一起(同軸)的是8齒的小齒輪,8齒的小齒輪又與40齒的大齒輪咬合在一起。如此共構的齒輪組。我們知道:40齒的大齒輪轉動1圈,同時8齒的小齒輪已跑了5圈。

是以,馬達以150轉/分運轉,假設小齒輪轉150圈,那麼40齒的大齒輪,就是轉了30圈。所以以倍數的關係可知~大齒輪的轉速是30轉/分。

圖中另外一組是8齒小齒輪與24齒小齒輪,該8齒小齒輪與40齒同軸。
 8齒小齒輪與24齒小齒輪的齒輪比=1:3,所以可知8齒小輪轉3圈,24 齒中齒輪轉1圈。

所以整個齒輪組的組合,從馬達的輸入端傳動到24齒輸出端的葉片轉動,呈現轉動比為:
 (1/5)x(1/3)=1/15

換句話說,馬達轉15圈,輸出端的葉片僅轉動1圈,藉此達到轉速的變化!!!!

另外,齒輪組改成Worm Gear也很有趣:


參考資料:
1.http://www.education.rec.ri.cmu.edu/roboticscurriculum/curriculum/introductiontogears.htm
2.http://www.education.rec.ri.cmu.edu/roboticscurriculum/curriculum/gearsspeedtorque.htm

2011年11月19日 星期六

Hitechnic Color Sensor 測試

一、硬體方面
color sensor 接在nxt主機上的IN_4。
二、軟體方面
根據[Third-party sensors: a review of some Hitechnic’s sensors]一文提到:
The new and totally redesigned HiTechnic Color Sensor Version 2 (V2) operates by using a single white LED (light emitting diode) to illuminate the target and analyses the color components of the light reflected by the target’s surface and calculates a Color Number that is returned to the NXT program.

Sensor Register Layout

AdressTypeContents
42HbyteColor number
43HbyteRed reading
44HbyteGreen reading
45HbyteBlue reading

Procedures are already available in Bricxcc to use the sensor:

  • SetSensorLowspeed() initializes the I2C communication with the sensor.
  • SensorHTColorNum(port) returns the value of Color number.
  • ReadSensorHTRawColor(port, rouge, vert, bleu) returns the RGB readings.
  • ReadSensorHTColor(port, index, rouge, vert, bleu) returns the value of Color number, and the RGB readings. See the code example at the end of the article ...
所以在NXC的程式基本採用的指令,包含二個:
1. SetSensorLowspeed(IN_4)
2. ReadSensorHTColor(IN_4,colorvalue,r,g,b)
其中,IN_4是彩色感應器接向IN_4,而colorvalue是經由color sensor回應的讀值,r,g,b分別為red,green,blue三原色的數值。

三、程式碼
#define ColorSensorPort IN_4

task main()
{

byte r,g,b;
byte colorvalue;
SetSensorLowspeed(ColorSensorPort);

while(true)
{
ReadSensorHTColor(ColorSensorPort, colorvalue,r,g,b);
NumOut(0,LCD_LINE3,colorvalue);
if (colorvalue==0) PlayTone(880,25);
Wait(25);
ClearScreen();
}
}

上述程式是說:
當color sensor讀值(colorvalue)=0,則PlayTone一個短音。
colorvalue=0-->黑色

2011年9月4日 星期日

手機藍芽遙控挖土機



這個遙控的原理承襲前述藍芽遙控的方式,技術上大同小異。
bot裝置參考[Lego.com Mindstorms]部分的接法。
機身略有修改。

2011年8月15日 星期一

segway-改裝後的猴子騎兩輪車



brick結構概念參考NXT Segway with Rider

今早想採用上述的結構,但因為該組裝結構沿用我前面寫的bot balance程式,似乎會一面傾倒,懶得修改程式,畢竟修改程式調整參數,耗費的工夫相較於改裝,當然是改裝比較簡單,因此動了一下腦筋,以原來的NXT Segway with Rider的概念,以及原有的兩輪平衡車子為基礎,簡單的說就是原來的兩輪平衡車上頭,加上一隻猴子。

這一隻猴子有另一個用途,猴子身體加裝一馬達,可以調整猴子身體前傾或後仰,來改變機身的重心位置,後續的設計將朝此製作。

2011年8月10日 星期三

實現Segway 兩輪平衡車

Segway是一個非常不穩定的非線性模型,很多研究多半會選擇​segway作為鑑定其控制器設計的良窳。

Segway是一台兩輪式、自由度高、且易於往兩側傾倒的極不平​衡車子,為了維持車子能立直中立,而不易傾倒,則便是研究者致力​研究的終極目的。

現階段研究,能使機身維持筆直站立且穩定,下階段想透過手機藍芽​裝置,來遠端遙控Segway。

[執行結果]




卡丁車與segway對決