top of page

 

 

ฝึกงาน FIBO

1/06/2018

 

         

         กลุ่ม Robot Arm  ต่อจากเมื่อวานที่ได้ไปซื้ออุปกรณ์ที่บ้านม้อ พี่ปูกับพี่เชาจ์ ได้ซื้อ DC MOTOR และลองให้หัดเล่นดู เพื่อจะเอามาเปลี่ยนแทน stepping  motor  และได้ทดลองเล่น หาข้อมูล ทดสอบการควบคุม DC motor 

sku_91627_1.jpg

 

  1. /*

  2. Adafruit Arduino - Lesson 13. DC Motor

  3. */

  4.  

  5.  

  6. int motorPin = 3;

  7. void setup()

  8. {

  9. pinMode(motorPin, OUTPUT);

  10. Serial.begin(9600);

  11. while (! Serial);

  12. Serial.println("Speed 0 to 255");

  13. }

  14. void loop()

  15. {

  16. if (Serial.available())

  17. {

  18. int speed = Serial.parseInt();

  19. if (speed >= 0 && speed <= 255)

  20. {

  21. analogWrite(motorPin, speed);

  22. }

  23. }

  24. }

 

นาย บัญชา   ทองแดง

 

VR TREADMILL 

หลังไปซื้อของจากบ้านหม้อ ก็ Proximity IR sensor มาจึงได้ทำงาน ทดลองใช้การอ่านค่าของ sensor ที่ต่อเข้ากับ บอร์ด Arduino uno โดยใช้ Code digitalRead 

 

/*
  DigitalReadSerial

  Reads a digital input on pin 2, prints the result to the Serial Monitor

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/DigitalReadSerial
 */

 // digital pin 2 has a pushbutton attached to it. Give it a name:
 int pushButton = 2;

 // the setup routine runs once when you press reset:
 void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}

34511267_1445724558904836_42210530520245

 

จากนั้นก็ได้ลองสร้างเขื่อนไขการ เบื่องต้นขึ้น โดยการใช้ปุ่มกดแทน sensor

 

Code 

   

int switch 1 = 2;
int switch 2 = 3; 
int switch 3= 4;
unsigned long timePosition1=0;
unsigned long timePosition2=0;
unsigned long timePosition3=0;
void setup() {
  
 Serial.begin(9600);
pinMode(swich1, INPUT);
pinMode(swich2, INPUT);
pinMode(swich3, INPUT);
}

void loop() {
  int Detect1=digitalRead(swich1);
  int Detect2=digitalRead(swich2);
  int Detect3=digitalRead(swich3);
  if(Detect1==LOW){
    timePosition1=millis();
  }
  else if(Detect2==LOW){
    timePosition2=millis();
  }
  else if(Detect3==LOW){
    timePosition3=millis();
  }
  if( timePosition1< timePosition2&& timePosition2< timePosition3){
    Serial.println("WALK");
  }
  else{
    Serial.println("STOP");
  }
}

                                                                                                                             วุฒิพงษ์ บุระดา

Captureas.PNG

 

ฝึกงาน FIBO

4/06/2018

 

 

       กลุ่ม Treadmill วันนี้ช่วงเช้าพวกผมได้ศึกษาเกี่ยวกับการเขียน Array และหัดเขียน code แบบ Array แต่ก็ยังไม่เข้าใจ ช่วงบายพวกผมได้มาศึกษาเพิมเติมจนเข้าใจ และได้ลองเขียน code อีกรอบแล้วรอบนี้ก็เขียนเสร็จและรันผ่าน  ต่อมาพวกผมได้เพิ่มคำสั่งคีย์บอดเพื่อแปลงค่าจากสวิตว์ให้เป็นคีย์บอด

 

     ตัวอย่าง code

#include <Keyboard.h>
int sen[] = {2,3,4,5,6,7};
unsigned long Time[6]={0,0,0,0,0,0};

void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(sen,INPUT);

}

void loop() {
  int sensor[6] = {digitalRead(sen[0]),digitalRead(sen[1]),digitalRead(sen[2]),digitalRead(sen[3]),digitalRead(sen[4]),digitalRead(sen[5])};

  if(sensor[0] == LOW){
    Time[0] = millis();
  }
  else if(sensor[1] == LOW){
    Time[1] = millis();
  }
  else if(sensor[2] == LOW){
    Time[2] = millis();
  }
  
  if(Time[0]<Time[1]&&Time[1]<Time[2]){
    Keyboard.press('w');
    delay(20);
  }
  else if(Time[0]<Time[1]){
    Keyboard.press('w');
    delay(20);
  }
  else if(Time[1]<Time[2]){
    Keyboard.press('w');
    delay(20);
  }
  else {
    Keyboard.releaseAll();
  }
}
เว็บไซต์ที่ศึกษา  https://www.ioxhop.com/article/7/arduino-ตอนที่-6-ตัวแปร-และอาเรย์

   กฤษดา  ชัยเนตร​

 

       กลุ่ม Robot Arm  หลังจากที่ได้ไปซื้อ Dc Motor มาแล้ว ก็ได้ทำการเขียนโปรแกรมควบคุมการทำงาน โดยให้หยุดตามตำแหน่งที่ Encoder อ่านค่าได้ตามที่เรากำหนด 
Code ที่ใช้ทำการทดสอบ
#define outputA 3
 #define outputB 2
 int counter = 0; 
 int aState;
 int aLastState;  
 int In1 = 4;
int In2 = 5;
int ENA = 6;
int SPEED = 255;
 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
analogWrite(ENA,255);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 
 void loop() { 
   aState = digitalRead(outputA); ifferent, that means a Pulse has occured
   if (aState != aLastState){     
    
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     if(counter == 150){
      digitalWrite(In1,LOW);
      digitalWrite(In2,LOW);
     }
     Serial.print("Position: ");
     Serial.println(counter);
   } 
   aLastState = aState; 
20180608_151631.jpg

 

เจษฎา   ทองภาพ

 

ฝึกงาน FIBO

5/06/2018

 

     สำหรับวันนี้กลุ่ม treadmill ได้ศึกษาเกี่ยวกับการเขียนฟังก์ชัน Arduino 

ฟังก์ชั่น Arduino เปรียบเสมือน เครื่องมือผลิตของ ที่เราป้อนวัตถุดิบเข้าไป ก็จะได้สิ่งของออกมา

เช่น เครื่องมื่อผลิตไข่ทอด วัตถุดิบคือ ไข่ และน้ำมัน สามารถเขียนในรูปแบบที่สั่น ๆ ได้

ไข่เจียว = เครื่องมื่อผลิตไข่ทอด(ไข่ , น้ำมัน);

ในคณิตศาสตร์พื้นฐาน เกือบทุกคนคงเคยแก้สมการฟังก์ชั่นง่าย ๆ แบบนี้

เช่น f(x) = x+20; ถ้า x=10  ผลลัพธ์ของฟังก์ชั่นนี้ก็คือ 30

ฟังก์ชั่นในการเขียนโปรแกรม Arduino ก็เหมือนกับทางคณิตศาสตร์ แบบนี้

โครงสร้างฟังก์ชั่น 

int fnName(int para1, int para2){

int sum = para1+para2;

return sum;

}

int คือ ประเภทตัวแปรที่ส่งค่ากลับ ถ้าไม่มีการส่งค่ากลับให้เขียนว่า void

fnName คือ ชื่อของฟังก์ชั่นที่เราตั้งเอง

int para1,int para2 คือ ค่าที่ส่งให้กับฟังก์ชั่น จะมีกี่ค่าหรือไม่มีก็ได้ ถ้ามีหลายค่าใช้ ‘,’ คั่น

return คือ ค่าตัวแปรที่จะให้ส่งค่ากลับ ถ้าเป็นฟังก์ชั่นแบบไม่มีการส่งค่ากลับ ตรงนี้ไม่ต้องเขียน

ดัดแปลงจากตัวอย่างนี้  f(x) = x+20; ถ้า x=10

เขียนเป็นฟังก์ชั่นใน Arduino ได้ง่าย ๆ แบบนี้

int f(int x){

     return  x+20;

}

ตัวอย่างวิธีเรียกใช้ฟังก์ชั่น Arduino

เรียกใช้โดยเอาตัวแปรมารับ ในกรณีมีการส่งค่ากลับ เช่น

int val = f(10); // จะได้ค่า val = 30

Arduino function อีกตัวอย่าง

สร้างฟังก์ชั่นชื่อ about ให้แสดงคำว่า “Arduino Easy by “+ชื่อที่ส่งเข้ามาในฟังก์ชั่น

โดยในฟังก์ชั่นนี้เป็นเพียงการแสดงค่าออกหน้าจอ Serial Monitor ไม่มีการส่งค่ากลับ

void setup() {}

 

void loop() {

  about("All");

}

 

void about(String name) {

  Serial.print("Arduino Easy by ");

  Serial.println(name);

}

เว็บไซต์ ที่ศึกษา คือ http://www.arduinoall.net/arduino-tutor/lessons/11-arduino-function-ok/

นายนพรัตน์  ขันธวิชัย

 

 

     กลุ่มแขนกลวันนี้  Robot  Arm ได้ทำการเขียนโค้ดเพิ่มเติมและแก้ไข ทิศทางการหมุนของ DC Motor ด้วย Encoder โดยการให้ Encoder ควบคุมการหมุนของมอเตอร์โดยการหาตำแหน่งองศา และได้ศึกษาจากเว็บไซต์ต่างๆ เพื่อทำการปรับมาใช้กับ Robot Arm และได้ลงไปห้องแลป ชั้นหนึ่ง เพื่อไปบัตกรีมอเตอร์เข้ากันบอร์ดที่ติดอยู่ตัวเครื่องแขนกล เพื่อติดมอเตอร์ไว้ที่แขนกล และได้ทำการทดสอบโค้ดการทำงานทั้งหมดของแขนกล แต่ก็ยังติดปัญหาที่สายพานของมอเตอร์ตัวที่ 2 เพราะสายพานยานเกินไป แต่ได้ทำการนำเฟืองมาใส่เพิ่ม เพื่อทำให้สายพานตรึงและทำงานได้ 

 

นาย บัญชา   ทองแดง

 

ฝึกงาน FIBO

6/06/2018

 

      VR Treadmill วันนี้ได้ลองใช้ IR proximity ต่อใช้งานแทนสวิตช์ เพื่อทดสอบความเร็วในการ

ตรวจกับของ sensor และระยะที่ตรวจจับได้ จากนั้น นำcode มา upload ลง arduino Leonardo

เพื่อทำการทดสอบ การเดินในเกม

code

#include <Keyboard.h>
int sensors[]={2,3,4,5,6,7};
unsigned long timePosition[6]={0,0,0,0,0,0};
void setup(){
 pinMode(sensors[5],INPUT);
 Serial.begin(9600);
 Keyboard.begin(); 
}

void loop() {
  
  int Detect[6]={digitalRead(sensors[0]),digitalRead(sensors[1]),digitalRead(sensors[2]),
                 digitalRead(sensors[3]),digitalRead(sensors[4]),digitalRead(sensors[5])};  
  if(Detect[0]==LOW){
    timePosition[0]= millis();
    
   }
  else if (Detect[1]==LOW){
    timePosition[1]= millis();
    
   }
  else if (Detect[2]==LOW){
    timePosition[2]= millis();
   
   }
  else if (Detect[3]==LOW){
    timePosition[3]= millis();
   
   }
  else if (Detect[4]==LOW){
    timePosition[4]= millis();
     
   }
  else if (Detect[5]==LOW){
    timePosition[5]= millis();
   }
  
 else if( timePosition[0]< timePosition[1]&&timePosition[1]<timePosition[2]){

   Keyboard.press('w');
   delay(20);
  }
else if( timePosition[3]<timePosition[4]&&timePosition[4]<timePosition[5]){
    Keyboard.press('w');
   delay(20);
 }
 else if(Detect[0]==LOW&&Detect[1]==LOW||Detect[1]==LOW&&Detect[2]==LOW){
   Keyboard.releaseAll();
 }
 else if(Detect[3]==LOW&&Detect[4]==LOW||Detect[4]==LOW&&Detect[5]==LOW){
    Keyboard.releaseAll();
 }
  else{
    Keyboard.releaseAll();
 }
}

   หลังจากที่ได้ทดสอบผลปรากฎว่า  สามารถทำให้ตัวละครในเกมเดินได้จริง แต่หลังจากที่ทำให้เดินได้แล้วนั้นกลับไม่สามารถหยุดได้ จึงต้อง

หาวิธีแก้ข้อบกพร่องนี้ต่อ                                                                                 

                                           

        

                                                                        วุฒิพงษ์ บุระดา

 

 

          กลุ่ม Robot arm วันนี้ครับผมได้ทำการเขียนโค้ดใหม่เพื่อทดลอง stepper motor ที่พี่ปูให้มาครับ ใช้โค้ดตัวเดียวกัน ฮาร์ดแวร์ตัวเดียวกัน แต่ทดลองคนละวันกัน ทำให้ได้ผลลัพธ์ที่ต่างกันสันนิษฐานว่าน่าจะเป็นเพราะความร้อน ของแขนทำให้เกิดความคลาดเคลื่อนในการทำงานของโค้ด ผมจึงพยายามหาข้อผิดพลาดในโค้ดนี้ด้วยตัวเอง แต่ก็ยังไม่พบ และพยายามเปลี่ยนความเร็วของ stepper motor ให้ช้าลง ให้เร็วขึ้น เพื่อทดสอบดูว่ามีผลต่อความแม่นยำหรือไม่ก็ยังไม่พบความเปลี่ยนแปลง แต่ stepper driver ยังมีความร้อนสูงเหมือนเดิม

 

 

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

 

โค้ดที่ใช้ทำการทดสอบ

 

                                                                     เจษฎา   ทองภาพ
 

 

ฝึกงาน FIBO

7/06/2018

 

      กลุ่ม Treadmill ต่อจากเมื่อวานที่พวกผมทำให้เดินได้แต่ไม่หยุดเดินเมื่อปล่อยมือจากสวิตว์ วันนี้พวกผมเลยสร้างเงื่อนไขเพิ่มเติมอีกเพื่อที่จะไปสั่งให้หยุดเดินแต่ก็เจอ error ตัวใหม่ที่สั่งให้พิมพ์ตัว W แต่ออกมาเป็นตัวอื่น ช่วงบ่ายเลยมาแก้ไข error ที่เกิดขึ้นเมื่อเช้า ก็เลยรู้สาเหตุว่าทำมัยถึงพิมพ์ออกมาเป็นตัวอื่น เพราะเขียน code ผิดตรงที่คำสั่งปริ้นที่จริงต้องเขียน Keyboard.press('W'); แต่ที่เขียนผิดคือฝันหนูที่หลงไปใส่เป็น ("W") หลังจากนี้ก็ได้หาวิธีสั่งให้หยุดเดินเมื่อปล่อยมือจากสวิตว์แต่ก็ยังไม่สำเร็จ

                                                                                        นายกฤษดา  ชัยเนตร

      กลุ่ม Robot Arm วันนี้ได้ทำการทดลองการหมุนของ  Motor กับ Encoder ให้อ่านค่าของการหมุน จึงได้รู้ว่า Encoder ตัวที่่ควบคุม Motor ตัวที่หนึ่งไม่อ่านค่า  จึงได้ถอดออกมาตรวจสอบและทดสอบอีกครั่ง แต่ก็ยังไม่อ่านค่าเหมือนเดิม จึงต้องหาตัวใหม่มาทดแทน 

                                                                                         นาย บัญชา ทองแดง

 

ฝึกงาน FIBO

8/06/2018

     กลุ่ม VR Treadmill  วันนี้หลังจากที่พวกเราได้หาวิธีควบคุมการหยุดเดินอยู่2วัน โดยคำสั่งจับ millis();ใน Arduino มาคำนวณ แต่ไม่เป็นไปตามที่ต้องการ เพราะคำสั่ง millis(); นั้นจะทำงานทันที่เมื่อเปิดการทำงานของ บอร์ด arduino และไม่สามารถสั่งรีเซ็ทค่าเวลาได้ โดยค่าจะรีเซ็ทเองเมื่อเวลาครบ 50 วัน 

        เนื่องจากที่ไม่สามารถสั่งรีเซ็จได้ ผมและวุฒิพงษ์ ได้หาวิธีอื่น แทนคำสั่ง millis โดยได้หาข้อมูลเกี่ยวกับ Timer และ interrupt เพื่อที่จะนำมาใช้แทน คำสั่ง millis  ส่วน กฤษดาก็พยามแก้code ต่อ

เว็บไซต์ที่ค้นหาข้อมูล

https://www.arduino.cc/reference/en/language/.../interrupts/interrupts/

www.instructables.com › technology › arduino

https://playground.arduino.cc/Code/Timer1

https://www.youtube.com/watch?v=1uDni82C1HE

                                                                                                            นพรัตน์

     กลุ่ม Robot  Arm  หลังจากวันที่ผ่านมายังหา Encoder มาแทนยังไม่ได้ ผมก็ได้ลองเอา Encoder ที่ยืมมาจากกลุ่ม    VR Treamill สามารถอ่านค่าใด้แต่ความละเอียดของค่าที่ Encode ตัวที่ติดอยู่กับ Robot Arm Encoder นี้เป็นแบบ 2000 pulse/rev นั่นก็คือการหมุน encoder รอบนึง จะส่งสัญญาณออกมา 2000 ครั้ง แต่ตัวของเพื่อนเป็นแบบ40 pulse/rev นั่นก็คือการหมุน encoder รอบนึง จะส่งสัญญาณออกมา 40 ครั้ง ค่าความละเอียดแตกต่างกันมากจึงไม่สามารถใช้ร่วมกันใด้ 

 

สายสี แดง คือ VCC

สายสี ดำ คือ GND

สายสี เขียว คือ OUTPUT1

สายสี ขาว คือ OUTPUT2

สายสี เหลือง คือ MODE

Code ที่ใช้ทำการทดสอบหาค่า

 #define outputA 3
 #define outputB 2
 int counter = 0; 
 int aState;
 int aLastState;  
 int In1 = 4;
int In2 = 5;
int ENA = 6;
int SPEED = 255;
 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
analogWrite(ENA,255);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 
 void loop() { 
   aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     if(counter == 40){ // สามารถเปลี่ยนค่าใด้
      digitalWrite(In1,LOW);
      digitalWrite(In2,LOW);
     }
     Serial.print("Position: "); //ดูค่าที่อ่านใด้
     Serial.println(counter);
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 }

                                                                      เจษฎา   ทองภาพ

 

ฝึกงาน FIBO

11/06/2018

        กลุ่ม Teradmill หลังจากวันศุกร์ที่ได้ศึกษาเกี่ยวกับคำสั่ง timer ที่จะใช้แทนคำสั่ง millis() วันนี้ช่วงเช้าได้ไปปรึกษาพี่ปูเกี่ยวโค้ตที่เขียนทำมัยถึงไม่หยุดเดินเมื่อปล่อย แล้วถ้าจะเปลี่ยนคำสั่งเวลาที่ใช้อยู่ปัจจุบันเป็นคำสั่งเวลาตัวอื่นมันจะทำได้ไหม พี่ปุได้แนะนำให้ไปศึกษาคำสั่ง Blink Without Delay และ Arduino Timer Object ว่ามันใช้ยังไงแล้วนำมาแทนคำสั่ง millis() ได้ไหม

พอได้ศึกษาก็ยังไม่ข้าใจ  ช่วงบายพอพี่เชามาก็เลยไปปรึกษาจะทำยังไงดี พี่เชาให้คำแนะนำว่า ควรทำยังไงแก้ไขตรงจุดไหนแล้วคำนวณหาเวลาที่จะนำมาสั่งให้มันหยุดเดินยังไง สุดท้ายพวกผมก็ทำได้สำเร็จ เมื่อสั่งให้เดินแล้วหยุดตามที่เราต้องการ

ตัวอย่าง Code

#include <Keyboard.h>
int sen[] = {2, 3, 4, 5, 6, 7};
unsigned long Time[6] = {0, 0, 0, 0, 0, 0};


void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(sen, INPUT);

}

void loop() {
  int sensor[6] = {digitalRead(sen[0]), digitalRead(sen[1]), digitalRead(sen[2]), digitalRead(sen[3]), digitalRead(sen[4]), digitalRead(sen[5])};


  for (int n = 0; n < 6; n++)
  {
    if (sensor[n] == LOW)
    {
      Time[n] = millis();
    }
  }

//คำสั่งเดิน
  if ((Time[0] < Time[1] && millis() - Time[1] < 650) { //ตัว0-1
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[2] && millis() - Time[2] < 650) { //ตัว0-2
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[2] && millis() - Time[2] < 650) { //ตัว1-2
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[4] && millis() - Time[4] < 650) { //ตัว3-4
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[5] && millis() - Time[5] < 650) { //ตัว3-5
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[5] && millis() - Time[5] < 650) { //ตัว4-5
    Keyboard.press('w');
  }
  else{
    Keyboard.releaseAll();
  }
}

นายกฤษดา  ชัยเนตร

 

ฝึกงาน FIBO

12/06/2018

กลุ่ม VR Treadmill

    หลังจากเมื่อวานสามารถทำให้เดินและหยุดได้แล้ว วันนี้จึงได้เพิ่มเงื่อนไงในการวิ่งขึ้นมา โดยใช้หลักเทียบค่าเวลา คือ การวิ่งจะใช้เวลาในการเคลื่อนที่น้อยกว่าการเดิน แล้วนำเงื่อนไขนี้ไปเขียนเป็น Code ออกมา

#include <Keyboard.h>
int sen[] = {2, 3, 4, 5, 6, 7};
unsigned long Time[6] = {0, 0, 0, 0, 0, 0};
unsigned long Speed1[6] = {0, 0, 0, 0, 0, 0};
unsigned long Speed2[6] = {0, 0, 0, 0, 0, 0};


void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(sen, INPUT);

}

void loop() {
  int sensor[6] = {digitalRead(sen[0]), digitalRead(sen[1]), digitalRead(sen[2]), digitalRead(sen[3]), digitalRead(sen[4]), digitalRead(sen[5])};


  for (int n = 0; n < 6; n++)
  {
    if (sensor[n] == LOW)
    {
      Time[n] = millis();
    }
  }

//คำสั่งเดิน
  if ((Time[0] < Time[1] && millis() - Time[1] < 650) &&  (millis() - Time[0] >= 100 && millis() - Time[0] < 800)) { //ตัว0-1
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[2] && millis() - Time[2] < 650) &&  (millis() - Time[0] >= 100 && millis() - Time[0] < 800)) { //ตัว0-2
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[2] && millis() - Time[2] < 650) &&  (millis() - Time[1] >= 100 && millis() - Time[1] < 800)) { //ตัว1-2
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[4] && millis() - Time[4] < 650) &&  (millis() - Time[3] >= 100 && millis() - Time[3] < 800)) { //ตัว3-4
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[5] && millis() - Time[5] < 650) &&  (millis() - Time[3] >= 100 && millis() - Time[3] < 800)) { //ตัว3-5
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[5] && millis() - Time[5] < 650) &&  (millis() - Time[4] >= 100 && millis() - Time[4] < 800)) { //ตัว4-5
    Keyboard.press('w');
  }
  
//คำสั่งวิ่ง
  else if ((Time[0] < Time[1] && millis() - Time[1] < 650 && millis() - Time[0] < 100)) { //ตัว 0-1
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[2] && millis() - Time[2] < 650 &&  millis() - Time[0] < 100)) { //ตัว0-2
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[2] && millis() - Time[2] < 650 && millis() - Time[1] < 100)) { //ตัว1-2
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[4] && millis() - Time[4] < 650 && millis() - Time[3] < 100)) { //ตัว3-4
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[5] && millis() - Time[5] < 650 && millis() - Time[3] < 100)) { //ตัว3-5
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[5] && millis() - Time[5] < 650 && millis() - Time[4] < 100)) { //ตัว4-5
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else {
    Keyboard.releaseAll();
  }

}
  

  จากนั้นก็ทำการทดสอบ ผลออกมาดีเป็นไปตามเงื่อนไขที่วางไว้ 

  ในตอนบ่ายได้ไปช่วยกลุ่ม Robot Arm ศึกษาCode คำสั่งการทำงานของ Robot Arm เนื่องจากได้เปลี่ยนชนิดของมอเตอร์จาก step motor เป็น dc motor จึงต้องศึกษา Code คำสั่งการทำงาน เพื่อปรับเปลี่ยนคำสั่งได้ตรงจุด

 จากนั้น ได้รายงานความคืบหน้าของ vr treadmill ให้อาจารย์ สยาม ฟัง พร้อมโชว์การทำงาน ที่ได้ทดสอบมา

และอาจารย์ก็ได้มอบหมายให้เตรียมการเสนองานที่ทำอยู่ให้ตัวแทนจาก บริษัท อาซาฮี จากญี่ปุน ในวันศุกร์ที่ 15 นี้ดู

                                                                                                                             วุฒิพงษ์

        กลุ่ม Robot Arm วันนี้ได้ปรึกษาพี่ปูพี่เชาว์เรื่อง ความร้อนของ stepper driver และก็ได้รับคำแนะนำมาคือเปลี่ยนจาก stepper เป็น DC Motor เพราะด้วยราคาของ stepper Motor ตัวที่พังมีราคาสูงเกินไป (6000 บาท) และต้องสั่งซื้อจากต่างประเทศจึงเป็นการล่าช้าต่อการทำงานครับผม  และผมได้ทดลองเขียนโค้ดควบคุม DC Motor Gear (ที่เลือกใช้ DC Motor Gear  เพราะมีแรงบิดที่สูงมากและราคาประหยัด) 

Code  ที่ใช้ทำการทดลอง 

#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}
void loop() {
  int potValue = analogRead(A0); // Read potentiometer value
  int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
  analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
  // Read button - Debounce
  if (digitalRead(button) == true) {
    pressed = !pressed;
  }
  while (digitalRead(button) == true);
  delay(20);
  // If button is pressed - change rotation direction
  if (pressed == true  & rotDirection == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    delay(20);
  }
  // If button is pressed - change rotation direction
  if (pressed == false & rotDirection == 1) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 0;
    delay(20);
  }
}

                                                           เจษฎา    ทองภาพ

 

ฝึกงาน FIBO

13/06/2018

      กลุ่ม Treadmill วันนี้ได้ลงไปตัดเหล็กแยกเป้นส่วนและเชื่อมทำเสา  แล้วเขียน code เงื่อนไขการเดินให้ครบทุกทิศทางเมื่อเขียนครบแล้วได้ทดสอบกับ IR Proximity Sensor ทั้ง 5 ตัวโดยจัดวางรูปแบบเป็นดาว แล้วใช้มือทำการจำลองเดินหรือวิ่ง เมื่อทำการทดสอบได้ซักพักก็ได้เจอปัญหาใหม่เพิ่มอีก พบว่าการทดลองด้วยสวิตซ์นั้นจะเก็บค่าตัวแปรก็ต่อเมื่อกดสวิตซ์เท่านั้น ซึ่งต่างกับ IR Proximity Sensor จะเก็บค่าตัวแปรก็ต่อเมื่อเปลี่ยนสถาะจาก LOW > HIGH เพราะการที่เราขึ้นไปเหยีบบน IR Proximity Sensor จะทำให้ค่าเป้น LOW อยู่ตลอดเวลาจึงไม่สามารถใช้กับ code ที่เราเขียนได้ แล้วหาทางแก้ไขอยู่ซักพักแต่ก็ไม่ได้ ก้เลยไปถามพี่เชาว่า พี่เชาได้ให้คำแนะนำว่าลองใช้ Interrupt ดูสิ ก็เลยได้ศึกษา Interrupt เกี่ยวกับบอร์ด Reonaldo และได้เขียน code เพิ่มเติมจากเดิม แล้วสามารถเดินและวิ่งได้ปกติ
ตัวอย่าง code

#include <Keyboard.h>
int sen[] = {2, 3, 4, 5, 6, 7};
unsigned long Time[6] = {0, 0, 0, 0, 0, 0};


void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(sen, INPUT);
  attachInterrupt(0,Ss0,RISING);
  attachInterrupt(1,Ss1,RISING);
  attachInterrupt(2,Ss2,RISING);
  attachInterrupt(3,Ss3,RISING);
  attachInterrupt(4,Ss4,RISING);

}
void loop() {

//คำสั่งเดิน
  //หันทาง 0
  if ((Time[0] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-4
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-3
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[4] >= 125 && millis() - Time[4] < 800)) { //ตัว4-3
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-1
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-2
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-2
    Keyboard.press('w');
  }
  
  //หันทาง 1
  else if ((Time[1] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-0
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-4
    Keyboard.press('w');
  }
//  else if ((Time[0] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-4
//    Keyboard.press('w');
//  }
//  else if ((Time[1] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-2
//    Keyboard.press('w');
//  }
  else if ((Time[1] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-3
    Keyboard.press('w');
  }
  else if ((Time[2] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-3
    Keyboard.press('w');
  }
  
  //หันทาง 2
  else if ((Time[2] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-1
    Keyboard.press('w');
  }
//  else if ((Time[1] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[1] >= 125 && millis() - Time[1] < 800)) { //ตัว1-0
//    Keyboard.press('w');
//  }
  else if ((Time[2] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-0
    Keyboard.press('w');
  }
//  else if ((Time[2] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-3
//    Keyboard.press('w');
//  }
  else if ((Time[3] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-4
    Keyboard.press('w');
  }
  else if ((Time[2] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-4
    Keyboard.press('w');
  }

  //หันทาง3
  else if ((Time[3] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-2
    Keyboard.press('w');
  }
  else if ((Time[3] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-1
    Keyboard.press('w');
  }
//  else if ((Time[2] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[2] >= 125 && millis() - Time[2] < 800)) { //ตัว2-1
//    Keyboard.press('w');
//  }
//  else if ((Time[3] < Time[4] && millis() - Time[4] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-4
//    Keyboard.press('w');
//  }
  else if ((Time[3] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-0
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[4] >= 125&& millis() - Time[4] < 800)) { //ตัว4-0
    Keyboard.press('w');
  }

  //หันทาง4
//  else if ((Time[4] < Time[3] && millis() - Time[3] < 500) &&  (millis() - Time[4] >= 125 && millis() - Time[4] < 800)) { //ตัว4-3
//    Keyboard.press('w');
//  }
  else if ((Time[4] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[4] >= 125 && millis() - Time[4] < 800)) { //ตัว4-2
    Keyboard.press('w');
  }
//  else if ((Time[3] < Time[2] && millis() - Time[2] < 500) &&  (millis() - Time[3] >= 125 && millis() - Time[3] < 800)) { //ตัว3-2
//    Keyboard.press('w');
//  }
//  else if ((Time[4] < Time[0] && millis() - Time[0] < 500) &&  (millis() - Time[4] >= 125 && millis() - Time[4] < 800)) { //ตัว4-0
//    Keyboard.press('w');
//  }
  else if ((Time[4] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[4] >= 125 && millis() - Time[4] < 800)) { //ตัว4-1
    Keyboard.press('w');
  }
//  else if ((Time[0] < Time[1] && millis() - Time[1] < 500) &&  (millis() - Time[0] >= 125 && millis() - Time[0] < 800)) { //ตัว0-1
//    Keyboard.press('w');
//  }

//คำสั่งวิ่ง
  //หันหน้าไป 0
  else if ((Time[0] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว 0-4
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว0-3
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[4] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4-3
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[1] && millis() - Time[1] < 300) && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว0-1
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[0] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว4-3
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1-2
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  
  // หันหน้าไป 1
  else if ((Time[1] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1<0
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  else if ((Time[1] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1<4
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
// else if ((Time[0] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว0<4
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
// else if ((Time[1] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1<2
//    Keyboard.press(0x81);
//    Keyboard.press('w');
// }
   else if ((Time[1] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1<3
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
   else if ((Time[2] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<3
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  
  // หันหน้าไป 2 
   else if ((Time[2] < Time[1] && millis() - Time[1] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<1
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
 // else if ((Time[1] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[1] > 10 && millis() - Time[1] < 125)) { //ตัว1<0
 //  Keyboard.press(0x81);
 //  Keyboard.press('w');
 // }
   else if ((Time[2] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<0
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
//   else if ((Time[2] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<3
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
 else if ((Time[3] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว 3<4
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
   else if ((Time[2] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<4
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
  
  //หันหน้าไป 3
 else if ((Time[3] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว3<2
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
   else if ((Time[3] < Time[1] && millis() - Time[1] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว3<1
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
//   else if ((Time[2] < Time[1] && millis() - Time[1] < 300) && (millis() - Time[2] > 10 && millis() - Time[2] < 125)) { //ตัว2<1
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
// else if ((Time[3] < Time[4] && millis() - Time[4] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว3<4
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
 else if ((Time[3] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว3<0
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
 else if ((Time[4] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4<0
    Keyboard.press(0x81);
    Keyboard.press('w');
  } 
  
  //หันหน้าไป 4
// else if ((Time[4] < Time[3] && millis() - Time[3] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4<3
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
 else if ((Time[4] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4<2
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
// else if ((Time[3] < Time[2] && millis() - Time[2] < 300) && (millis() - Time[3] > 10 && millis() - Time[3] < 125)) { //ตัว3<2
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
// else if ((Time[4] < Time[0] && millis() - Time[0] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4<0
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
 else if ((Time[4] < Time[1] && millis() - Time[1] < 300) && (millis() - Time[4] > 10 && millis() - Time[4] < 125)) { //ตัว4<1
    Keyboard.press(0x81);
    Keyboard.press('w');
  }
//  else if ((Time[0] < Time[1] && millis() - Time[1] < 300)  && (millis() - Time[0] > 10 && millis() - Time[0] < 125)) { //ตัว0<1
//    Keyboard.press(0x81);
//    Keyboard.press('w');
//  }
 else{
  Keyboard.releaseAll();
 }
}

void Ss0(){
  Time[0] = millis();
}
void Ss1(){
  Time[1] = millis();
}
void Ss2(){
  Time[2] = millis();
}
void Ss3(){
  Time[3] = millis();
}
void Ss4(){
  Time[4] = millis();
}

                                                                      นายกฤษดา   ชัยเนตร
    กลุ่ม Robot Arm วันนี้ได้ลงไปชั้น 1 เอาแขนกลลงไปเจาะและใส่เฟือง เพื่อที่จะติดตั้ง DC Motor  และได้ช่วยกลุ่ม Treadmill ตัดเหล็ก ทำเสา และเชื่อมเหล็ก  เพราะวันศุกร์ จะมีคนจากบริษัท อาซาฮี มาเยี่ยมชม FIBO 
35533275_1455790181231607_70597244598249

 

                                                                         นาย บัญชา  ทองแดง

 

ฝึกงาน FIBO

14/06/2018

         วันนี้ช่วงเช้าได้เตรียมเหล็กที่จะนำมาทำเป็นส่วนเสาและฐานพร้อมกับวางแผนการสร้างปรับเปลี่ยนสเกลใหม่เนื่องจากเราใช้ของที่มีมาใช้ใหม่

 ส่วนในช่วงบ่ายก็ได้ไปศึกษาการสร้างเกมใน Unity

https://www.youtube.com/watch?v=mXe5MY31BQ0&t=764s

https://www.youtube.com/watch?v=pQwQYYNjOCQ

จากนั้นก็เตรียมสคริปที่จะนำเสนอในวันพรุ่งนี้ พร้อมซ้อมไปหลายรอบก่อนกลับ 

                                                                                                  วุฒิพงษ์

 

        กลุ่ม Robot Arm  วันนี้ครับหลังจากใด้รับมอบหมายจากอาจารย์สยามคือ  ทำให้ทุกส่วนของ Robot Arm ขยับให้ได้เพื่อโชว์ในวันพรุ่งนี้ ผมก็ได้ทำการเขียนโค้ดและใด้ทำการทดลองควบคุมการทำงานผ่าน Serial monitor ครับผม  และช่วงบ่ายทำการซ้อมพูด present เกี่ยวกับการทำงาน การนำไปใช้งานของ Robot arm 

 

Code ที่ใช้ทำการทดสอบ  


#include 

//definitions for each command to be recieved via serial port
#define COMMAND_LEFT '4'//ซ้าย
#define COMMAND_RIGHT '6'//ขวา
#define COMMAND_FORWARD '8'//ขึ้น
#define COMMAND_BACK '2'//ลง
#define COMMAND_STOP'5'//หยุด

//enter the steps per rev for your motors here
int stepsInRev = 200;
int in1 = 12; //Define Pins To Control Motor
int in2 = 13;
int speedA = 10;
int speedB = 11;

//this sets the value for the for loops and therefore sets the amount of steps in each call
int num_of_steps = 1;
// setup pins for each driver motor1 ~ IN1, IN2, IN3, IN4; motor2 ~ IN1, IN2, IN3, IN4
Stepper myStepper2(stepsInRev, 30, 32, 34, 36);
Stepper myStepper1(stepsInRev, 6, 7, 8, 9);
// variable to store the last call to the serial port
char lastCall = ' ';

//I had prototyped all of the functions here, but for some reason the Arduino IDE didn't like it
//so they are coded out until I an figure out why
//void forwardStep();
//void backwardStep();
//void leftStep();
//void rightStep();
//void allStop();

//to move the motors forward
void forwardStep(int steps){
  Serial.println("forward");
  // step one step each forward
  myStepper2.step(-300);
  delay(10);
}

// to move the motors back
void backwardStep(int steps){
  Serial.println("backward");
  // step one step each backward
  myStepper2.step(300);
  delay(10);
}

 

// to move the motors in opposite directions (left)
void leftStep(int steps){
  Serial.println("left");
 // step one step each left
  myStepper1.step(-100);
  delay(10);
}


// to move the motors in opposite directions (right)
void rightStep(int steps){
  Serial.println("right");
  // step one step each right
  myStepper1.step(100);
  delay(10); 
}

// to power down the motor drivers and stop the motors
void allStop(){
  Serial.println("stop");
  // steppers stop
  PORTD = B00000000; //sets all of the pins 0 to 7 as LOW to power off stepper1
  PORTB = B00000000; //sets all of the pins 8 to 13 as LOW to power off stepper2
}
void setup() {
  Serial.begin(9600);//start the bluetooth serial port - send and recieve at 9600 baud
  // set the speed at 60 rpm:
  pinMode (in1, OUTPUT);
pinMode (in2, OUTPUT);
pinMode (speedA, OUTPUT);
pinMode (speedB, OUTPUT);


int Forward1(){
digitalWrite (in1, LOW);
digitalWrite (in2, LOW);
digitalWrite (speedA, HIGH);
digitalWrite (speedB, HIGH);
}

int Reverse1(){
digitalWrite (in1, HIGH);
digitalWrite (in2, HIGH);
digitalWrite (speedA, HIGH);
digitalWrite (speedB, HIGH);
}

int Left1(){
digitalWrite (in1, HIGH);
digitalWrite (in2, LOW);
digitalWrite (speedA, HIGH);
digitalWrite (speedB, HIGH);
delay(300);
}

int Right1(){
digitalWrite (in1, LOW);
digitalWrite (in2, HIGH);
digitalWrite (speedA, HIGH);
digitalWrite (speedB, HIGH);
delay(300);
}
int Stop1(){
digitalWrite (in1, LOW);
digitalWrite (in2, LOW);
digitalWrite (speedA, LOW);
digitalWrite (speedB, LOW);
}
 // myStepper1.setSpeed(100);
//  myStepper2.setSpeed(255);
//}

void loop() {
  if (Serial.available() > 0) {
int inByte = Serial.read();

switch (inByte) {      //following are subroutines for their corresponding function

case 'w': 
Forward1();
break;

case 's': 
Reverse1();
break;

case 'd': 
Left1();
break;

case 'a': 
Right1();
break;

case 'q':
Stop1();
break;

default:
digitalWrite (speedA, HIGH); //All of This is Just to Say STOP the Motors
digitalWrite (speedB, HIGH);
digitalWrite (in1, LOW);
digitalWrite (in2, LOW);


}

}

//check to see if there is serial communication and if so read the data
//if(Serial.available()) {
char data = (char)Serial.read();
// switch to set the char via serial to a command
switch(data) {
  case COMMAND_FORWARD:
    forwardStep(num_of_steps);
    break; 
  case COMMAND_BACK:
    backwardStep(num_of_steps);
    break;
  case COMMAND_LEFT:
    leftStep(num_of_steps);
    break;
  case COMMAND_RIGHT:
    rightStep(num_of_steps);
    break;
  case COMMAND_STOP:
    allStop();
    break;
    
}
// set the 'lastCall' variable to the last call from the serial
lastCall = data;
}
else{
char data = lastCall;
switch(data) {
  case COMMAND_FORWARD:
    forwardStep(num_of_steps);
    break; 
  case COMMAND_BACK:
    backwardStep(num_of_steps);
    break;
  case COMMAND_LEFT:
    leftStep(num_of_steps);
    break;
  case COMMAND_RIGHT:
    rightStep(num_of_steps);
    break;
  case COMMAND_STOP:
    allStop();
    break;
}
lastCall = data;
}
}

                                                                               เจษฎา     ทองภาพ

 

ฝึกงาน FIBO

15/06/2018

 

       วันนี้ช่วงเช้า พวกเราทุกคนได้เตรียมตัว เตรียมสถานที่ เตรียมอุปกรณ์ แล้วได้แก้ไข Delay ในการเดินให้ดูเนียนขึ้นอีก

ช่วงบ่าย บริษัท อาซาฮี ได้มาเยี่ยมชมแล็ป HCI ที่พวกผมฝึกงานอยู่ แต่พวกผมไม่ได้พรีเซนต์ ก็เลยได้มาอักวีดีโอส่งอาจารย์แทนครับ

 

ฝึกงาน FIBO

18/06/2018

      วันนี้ เราทั้ง2กลุ่มมาช่วยกันศึกษาcodeคำสั่งการทำงานของ Robot Arm เพื่อจะเปลี่ยนคำสั่งจากการใช้ stepper motor เป็น DC motor แทน หลังจากนั้น

ก็ได้คำแนะจากพี่เชา ว่าใช้ PID ในการควบคุมตำแหน่งการหยุดของmotor แล้วต่อจากนั้นได้เรียนการควบคุมตำแหน่งของ motor ขั้นให้ตรงตำแหน่ง ด้วยวิธี Bang Bang control และ P control 

 Bang Bang control จะเป็นการควบคุมที่ใช้แค่ setpoint และ ค่าอ่านได้จาก sensor มาคำนวณหา error มาควบคุมมอเตอร์ 

 ตัวอย่าง เช่น setpoint ไว้ที่ 100 องศา motor ทำงาน sensorอ่านค่า 105 องศา

     จะได้

            error = setpoint - sensorread

            error = 100-105 

            error = 5 

 เมื่อเราได้ค่า error แล้วก็มาสร้างเขื่อนไขการทำงานของ motor เช่น

            

          ถ้า error = 0  motor stop

          ถ้า error > 0  motor Rotate right

          ถ้า error < 0  motor Rotate left

ส่วน  P control ก็ใช้หลักการเดียวกัน แค่คูณค่า Gain เข้าไป  

 

ตัวอย่างการทำงานของ Bang Bang control

 

                                                                              วุฒิพงษ์ 

 

ฝึกงาน FIBO

19/06/2018

    วันนี้ ทั้งสองกลุ่มได้ช่วยกันศึกษาCode คำสั่ง PID ที่พี่เชาว์ได้แนะนำ โดยวันนี้ได้ศึกษาส่วน P Proportinal control action เป็นหนึ่งในเทอมของการควบคุมแบบ PID  
การควบคุมแบบ PID เป็นการพิจารณาจากค่า Error ที่เกิดขึ้นจากความแตกต่างระหว่างสัญญาณ set point กับสัญญาณอินพุตป้อนกลับ

(feed back) โดยมีการคูณด้วยอัตราการขยายหรือเกน เข้ากับค่า Error ที่ได้ เรียกว่าค่า K สำหรับการควบคุม P ก็จะเรียกค่าเกนว่า Kp

 

สมการการควบคุมแบบ P

Output = Kpe (t)

Code ตัวอย่างที่ได้ศึกษาวันนี้

#define outputA 20
#define outputB 21
int counter = 0; 
int aState;
int aLastState;  
int In1 =13;
int In2 = 12;
int ENA = 10;
int Spd = 0 ;

 void setup() { 
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 
 void loop() { 
    
   aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     int setpoint=-100;
     int err = setpoint-counter;
     Spd = err * 2;
     if( err > 0){
      digitalWrite(In1,LOW);
      digitalWrite(In2,HIGH);
      analogWrite(ENA,200);
     }
     else if ( err < 0){
      digitalWrite(In1,HIGH);
      digitalWrite(In2,LOW);
      analogWrite(ENA,200);
     }
     else if( err == 0){
      digitalWrite(In1,LOW);
      digitalWrite(In2,LOW);
      analogWrite(ENA,200);
     }
     //Serial.print("Position: ");
     Serial.print(setpoint); 
     Serial.print(" ");
     Serial.println(counter);
 
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 }

                                                             บัญชา    ทองแดง

 

ฝึกงาน FIBO

21/06/2018

    วันนี้ ทั้งสองกลุ่มได้ช่วยกันศึกษาCode คำสั่ง PID control เป็นการควบคุมในระบบวงปิด คือระบบควบคุมที่มีการป้อนกลับ
ประกอบด้วยส่วนการควบคุมที่สำคัญคือ
- Proportinal control action (P - Action)   การกำหนดการทำงานของ ouput ให้เป็นสัดส่วนเปอร์เซ็นกับค่า error 
- Integral control action (I-Action)  เป็นสัดส่วนของขนาดความผิดพลาดและระยะเวลาของความผิดพลาด
- Derivative control action (D-Action)  อัตราการเปลี่ยนแปลงของความผิดพลาด การรบกวนระบบจากภายนอก

Code ตัวอย่างที่ได้ศึกษาวันนี้

#define outputA 20
#define outputB 21
int counter = 0; 
int aState;
int aLastState;  
int In1 =13;
int In2 = 12;
int ENA = 10;
int setpoint =150;
 void setup() { 
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
analogWrite(ENA,255);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 
 void loop() { 
   aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     int err = setpoint-counter;
     if( err > 0){
      digitalWrite(In1,LOW);
      digitalWrite(In2,HIGH);
     }
     else if ( err < 0){
      digitalWrite(In1,HIGH);
      digitalWrite(In2,LOW);
     }
     else if( err == 0){
      digitalWrite(In1,LOW);
      digitalWrite(In2,LOW);
     }
     //Serial.print("Position: ");
     Serial.print(setpoint); 
     Serial.print(" ");
     Serial.println(counter);
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 }

และตอนบ่ายก็ได้ช่วยกันทำระบบแมคคานิค Robot arm ที่ทำไว้วันก่อนยังไม่แข็งแรงพอครับ จึงส่งผลต่อการควบคุม DC motor ทำให้การหมุนไปยังทำแหน่ที่ต้องการใช้เวลานานและยังสั่นมากครับ และส่วนหนึ่งก็มาจาก DC Motor ที่พี่เชาว์ให้มาตัวเล็กและมีความเร็วมากไปทำไห้แรงบิด ( Torque )ในรอบต่ำมีไม่มากพอ ละพอก็ได้ทำเฟืองทดเพิ่ม ทำให้การหมุนช้าลงแต่ใด้แรงบิด ( Torque ) ที่เพิ่มมากขึ้น  จากเดิม DC Motor  19rpm  ใด้ทำการทดรอบเพิ่ม 2 : 1 = 9.5 rpm จากการคำนวน

แรงบิด (Torque): 3.95 kg.cm - 13.5kg.cm 

20180621_164146.jpg

การค้นหาข้อมูล

http://ctms.engin.umich.edu/CTMS/index.php?aux=Activities_DCmotorB

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction§ion=ControlPID

https://sites.google.com/site/suppapongclub/ceaa-luk-rabbpid

                                                                          เจษฎา  ทองภาพ

 

ฝึกงาน FIBO

22/06/2018

bottom of page