Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4610|回復: 4
打印 上一主題 下一主題

腦波控制直流馬達 直流馬達會轉不會停

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-10-3 22:29:08 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
小弟不才 最近專題要繳交了 可是東西還是弄不出來 所以想來麻煩板上大大幫忙 拜託了!!

我是想用腦波來控制直流馬達,而我再網路上有找到人家已經打好的程式,不過他是用"伺服馬達"而我想用"直流馬達"

其實我對腦波也不懂,不過這個腦波器會回傳來的值是從0~100,所以我從這裡去控制

而我比較大的問題就是
當我有訊號傳進來的時候,我的直流馬達他是會動的
而沒有訊號的時候,我想讓馬達停止
可是我只要一把它加上馬達的部份,他就會不停止,還是照轉

這是他的原始程式,他有用到蜂鳴器&LED,不過我都刪掉了 我只要用到馬達的部份
ps1.txt (3.18 KB, 下載次數: 1154)



這是他的電路圖





再來這個是腦波器要和Arduino所連結的dongle




程式碼:
int dir1PinA = 13;
int dir2PinA = 12;
int speedPinA = 10;
int speed;
const int tinyLedPin = 13;
int tinyLedState = HIGH;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(tinyLedPin, OUTPUT);

pinMode(dir1PinA, OUTPUT);
pinMode(dir2PinA, OUTPUT);
pinMode(speedPinA, OUTPUT);
int speed = 0;

Serial.begin(115200); // bit/s //dd
connectHeadset(); //
}


void loop()
{
float att = getAttention(); //
if (att > 0) //
{
for (speed=64;speed<128;speed++)           這邊是我自己馬達加進去的地方
analogWrite(speedPinA, speed);
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, HIGH);
}
toggleTinyLed(); //
}

/*** Headset ***/
void connectHeadset()    連結腦波
{
delay(3000);
Serial.write(0xc2); //
}


byte readOneByte()         腦波連結的地方,我沒改
{
while (!Serial.available()) { //
delay(5); // ms
};
return Serial.read();
}


float getAttention()       他要執行的副程式,裡面也有腦波連結的部份,我也都沒改
{ // return attention percent (0.0 to 1.0)
// negative (-1, -2...) for error
byte generatedChecksum = 0; //
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {
0
};
int poorQuality = 0;
float attention = 0;
Serial.flush(); // prevent serial buffer from filling up //




這是他連節的一些資料,也都是不用改的


/* Sync */
if (170 != readOneByte()) return -1; //
if (170 != readOneByte()) return -1;
/* Length */
payloadLength = readOneByte();
if (payloadLength > 169) return -2; //
/* Checksum */
generatedChecksum = 0;
for (int i = 0; i < payloadLength; i++) { //
// Read payload into array:
payloadData = readOneByte();
generatedChecksum += payloadData;
}
generatedChecksum = 255 - generatedChecksum;
checksum = readOneByte();
if (checksum != generatedChecksum) return -3; //
/* Payload */
for (int i = 0; i < payloadLength; i++) { //
switch (payloadData) {
case 0xD0:


case 4: //


i++; //
attention = payloadData; //

//if (  attention > 50 && attention <= 100)
//{return  1;}


break;

case 2:
i++;
poorQuality = payloadData;

if (200 == poorQuality) {

return -4;
}
break;
case 0xD1:
case 0xD2:
case 0xD3:  
case -70:

case 0x80: // skip RAW //
i = i + 3;
break;
case 0x83: // skip ASIC_EEG_POWER
i = i + 25;
break;
} // switch
} // for
return (float)attention/100 ; //
}

2012-10-03 21.35.20.jpg (542.12 KB, 下載次數: 220)

2012-10-03 21.35.20.jpg
2#
發表於 2012-10-4 20:02:50 | 只看該作者
回復 1# williams741

程式裡沒有 digitalWrite(dir2PinA, LOW);
這是讓馬達停止的命令,
所以可以改成:
if (att > 0) //
{
for (speed=64;speed<128;speed++)           這邊是我自己馬達加進去的地方
{
analogWrite(speedPinA, speed);
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, HIGH);
delay(20);
}
digitalWrite(dir2PinA, LOW);
}

加入:
if (att <= 0) //
{
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, LOW);
}
3#
發表於 2012-10-7 19:14:15 | 只看該作者
這個 NeuroSky 的腦波檢測器蠻酷的。可在哪裡買到?
4#
發表於 2012-10-9 06:04:31 | 只看該作者
這個 NeuroSky 的腦波檢測器蠻酷的。可在哪裡買到?
Curtiss 發表於 2012-10-7 19:14

Curtiss大:到露天拍賣打"腦波"關鍵字就可以查到,您要的應該是發展套件~~
5#
發表於 2012-10-10 12:14:28 | 只看該作者
回復 4# marbol


    感謝告知!
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-9-28 07:19 , Processed in 0.148557 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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