読者です 読者をやめる 読者になる 読者になる

12/6/2016

ロボ実験について考える。

ロボットを手動で目的地まで連れてく。

ボタンを押すとロボットアームが動き、対象物を挟んでいく。

力覚センサで物体を検知し、アーム挟む動作停止。

停止すると同時に、両アーム運転開始。

一定の高さになったら両アーム停止。
ここで、高さを目標値に設定して、フィードバックで実現したい。

⭐︎ 落とさないようにセンサで検知し値が小さくなってきたら、モーター出力させるようにするべきか?
実際ここでフィードバックの方が現実味あったりして!

プログラム(予想)

int hlefta = 2;
int hrighta = 3;
int hleftb = 4;
int hrightb = 5;
int hleftc = 6;
int hrightc = 7;

int lefta = 8;
int righta = 9;
int leftb = 10;
int rightb = 11;
int leftc = 12;
int rightc =13;

void setup() {
Serial.begin(9600);    
pinMode(hlefta, OUTPUT);
pinMode(hrighta, OUTPUT);
pinMode(hleftb, OUTPUT);
pinMode(hrightb, OUTPUT);
pinMode(hleftc, OUTPUT);
pinMode(hrightc,OUTPUT);

pinMode(lefta, OUTPUT);
pinMode(righta, OUTPUT);
pinMode(leftb, OUTPUT);
pinMode(rightb, OUTPUT);
pinMode(leftc, OUTPUT);
pinMode(rightc,OUTPUT);



}
void loop() {
  if(Serial.available()){
  char cmd = Serial.read();
    
switch (cmd){  
case 'w':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb, 200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
Serial.print(F("a\n"));
break;

case 's':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'd':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'a':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'z':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'u': //掴んで持ち上げ
analogWrite(hrighta, 200);
analogWrite(hlefta, 0);

if (vol_value <400){
analogWrite(hrighta, 0);
analogWrite(hlefta, 0);

analogWrite(hrightb, 200);
analogWrite(hleftb,0);
analogWrite(hrightc, 200);
analogWrite(hleftc, 0);
delay(2000);
analogWrite(hrightb, 0);
analogWrite(hleftb,0);
analogWrite(hrightc, 0);
analogWrite(hleftc, 0);
}
delay(2000);
break;//これだと持ち上げた後に、analogWrite(hrighta, 200);
analogWrite(hlefta, 0);がまた処理されて動く。

case 'p'://降ろす離す
analogWrite(hrightb,0 );
analogWrite(hleftb,200);
analogWrite(hrightc, 0);
analogWrite(hleftc, 200);
delay(2000);
analogWrite(hrightb,0 );
analogWrite(hleftb,0);
analogWrite(hrightc, 0);
analogWrite(hleftc, 0);
analogWrite(hrighta, 0);
analogWrite(hlefta, 200);

if (vol_value <400){
analogWrite(hrighta, 0);
analogWrite(hlefta, 0);
}
delay(2000);
break;

default://case'o':
analogWrite(righta, 0);
analogWrite(lefta, 0);
analogWrite(rightb, 0);
analogWrite(leftb, 0);
analogWrite(rightc,0);
analogWrite(leftc, 0);
break;
}
   }


Serial.print("righta = ");
Serial.print(digitalRead(righta));
Serial.print("   lefta = ");
Serial.println(digitalRead(lefta));
}