SlideShare uma empresa Scribd logo
1 de 10
Conveyor
• เป้ าหมาย
– ควบคุมสายพานด้วยคาสั่งจากคอมพิวเตอร์
– ป้ อนคาสั่งผ่านทาง serial monitor ของ Arduino
• ‘1’ - ‘9’ หมุนด้วยความเร็ว 10%-90% ของความเร็วสูงสุด ป้ อน ‘0’ หยุด
• ‘c’ หรือ ‘C’ เลือกหมุนตามเข็มและทวนเข็ม
Conveyor
• หัวต่อแบบ D sub 9 pin
Driver board
• แผงวงจรขับมอเตอร์
Procedure
• เตรียมชุดทดลอง = หัวต่อ D sub 9 pin + บอร์ดขับกระแส +
Arduino  คอมพิวเตอร์
– เลือกขาสาหรับขับมอเตอร์ และเอ็นโค้ดเดอร์
• ทดสอบความสัมพันธ์ (? pulse/cm)
– วัดระยะที่จานวนพัลส์ต่างๆกัน โดยทาทั้งสายพานหมุนไปทางซ้าย/ทางขวา
– นาผลการทดสอบไปพล็อตกราฟหาความสัมพันธ์
• ทดสอบความเร็วสูงสุด (? rpm)
– ขับด้วย PWM 100%
– อ่านค่าความเร็วจาก serial monitor
const int enPin = X;
const int dirPin = X;
const int pwmPin = X;
void motorTurn(float duty_cycle) {
byte pwm;
if (duty_cycle != 0)
digitalWrite(enPin, HIGH);
else
digitalWrite(enPin, LOW);
if (duty_cycle > 0) {
digitalWrite(dirPin, LOW);
pwm = map(duty_cycle, 0, 100, 0, 255);
analogWrite(pwmPin, pwm);
} else {
digitalWrite(dirPin, HIGH);
pwm = 255 - map(-duty_cycle, 0, 100, 0, 255);
analogWrite(pwmPin, pwm);
}
}
โค้ดตัวอย่างสาหรับขับมอเตอร์ #1
หมุนด้วย Ton
หมุนด้วย Toff
กาหนดค่าตามขาที่เลือก
const int chB = X;
volatile unsigned long count = 0;
void pulseCount() {
if (digitalRead(chB) == HIGH)
count++;
else
count--;
}
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
pinMode(enPin, OUTPUT);
pinMode(chB, INPUT);
attachInterrupt(X,pulseCount,RISING);
Serial.begin(9600);
}
โค้ดตัวอย่างสาหรับนับพัลส์ #2
กาหนดค่าตามขาที่เลือก
0  D2 หรือ 1  D3
#define NUM_PULSE (X)
void loop() {
if (count < NUM_PULSE)
motorTurn(50.0);
else
motorTurn(0);
Serial.print("Count: "); Serial.println(count);
delay(100);
}
#define PULSE_PER_CM (X.X)
void loop() {
float speed = count / PULSE_PER_CM * 60;
count = 0;
motorTurn(100.0);
Serial.print("Speed: "); Serial.println(speed);
delay(1000);
}
โค้ดตัวอย่างสาหรับทดลอง
จากผลการทดลอง
cm/min
PID controller
• หลักการควบคุม = สร้างสัญญาณควบคุมจากการคานวณ
error = setpoint - feedback
• setpoint อ่านค่าจาก potentiometer
• Feedback อ่านค่าจากเอ็นโค้ดเดอร์
#define MAX_SPEED (X.Y)
const float Kp = 1.0;
const float Ki = 0.0;
const float Kd = 0.0;
float sumErr = 0.0;
float lastSpeed = 0.0;
setpoint = readSerial();
speed = count / PULSE_PER_CM * 600;
speed = speed/MAX_SPEED * 100.0;
float pidCtrl(float setpoint, float speed) {
float error, ctrl, speedChange;
error = setpoint – speed;
sumErr += error;
speedChange = speed – lastSpeed;
ctrl = Kp*error + Ki*sumErr + Kd*speedChange;
lastSpeed = speed;
return ctrl;
}
โค้ดตัวอย่างสาหรับตัวควบคุม PID
มาจากผลทดลอง
อ่านตัวอักษรและคืนค่า
แปลง rpm รอบ 0.1 s
Results
• เอกสารสรุปงาน (ประมาณ 3-4 หน้า ส่งพร้อมสาธิต)
– ค่า pulse/cm และความเร็วสูงสุดจากการทดลอง
– กราฟแสดง speed ของตัวควบคุม PID เมื่อปรับค่า Kp,Ki,Kd
ต่างๆกัน (ใช้ delay(100) ภายใน loop)
– โค้ดสมบูรณ์ที่รวมโค้ดตัวอย่างเข้าด้วยกัน
• รับคาสั่งปรับทิศทางและความเร็วจากคอมพิวเตอร์
• กราฟแสดงการควบคุมความเร็ว เมื่อทดลองวางของที่น้าหนักต่างกันบนสายพาน
• การให้คะแนนพิจารณาความเรียบร้อยของชิ้นงานด้วย

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

การออกแบบตัวควบคุมความเร็วสายพาน

  • 1. Conveyor • เป้ าหมาย – ควบคุมสายพานด้วยคาสั่งจากคอมพิวเตอร์ – ป้ อนคาสั่งผ่านทาง serial monitor ของ Arduino • ‘1’ - ‘9’ หมุนด้วยความเร็ว 10%-90% ของความเร็วสูงสุด ป้ อน ‘0’ หยุด • ‘c’ หรือ ‘C’ เลือกหมุนตามเข็มและทวนเข็ม
  • 4. Procedure • เตรียมชุดทดลอง = หัวต่อ D sub 9 pin + บอร์ดขับกระแส + Arduino  คอมพิวเตอร์ – เลือกขาสาหรับขับมอเตอร์ และเอ็นโค้ดเดอร์ • ทดสอบความสัมพันธ์ (? pulse/cm) – วัดระยะที่จานวนพัลส์ต่างๆกัน โดยทาทั้งสายพานหมุนไปทางซ้าย/ทางขวา – นาผลการทดสอบไปพล็อตกราฟหาความสัมพันธ์ • ทดสอบความเร็วสูงสุด (? rpm) – ขับด้วย PWM 100% – อ่านค่าความเร็วจาก serial monitor
  • 5. const int enPin = X; const int dirPin = X; const int pwmPin = X; void motorTurn(float duty_cycle) { byte pwm; if (duty_cycle != 0) digitalWrite(enPin, HIGH); else digitalWrite(enPin, LOW); if (duty_cycle > 0) { digitalWrite(dirPin, LOW); pwm = map(duty_cycle, 0, 100, 0, 255); analogWrite(pwmPin, pwm); } else { digitalWrite(dirPin, HIGH); pwm = 255 - map(-duty_cycle, 0, 100, 0, 255); analogWrite(pwmPin, pwm); } } โค้ดตัวอย่างสาหรับขับมอเตอร์ #1 หมุนด้วย Ton หมุนด้วย Toff กาหนดค่าตามขาที่เลือก
  • 6. const int chB = X; volatile unsigned long count = 0; void pulseCount() { if (digitalRead(chB) == HIGH) count++; else count--; } void setup() { pinMode(dirPin, OUTPUT); pinMode(enPin, OUTPUT); pinMode(enPin, OUTPUT); pinMode(chB, INPUT); attachInterrupt(X,pulseCount,RISING); Serial.begin(9600); } โค้ดตัวอย่างสาหรับนับพัลส์ #2 กาหนดค่าตามขาที่เลือก 0  D2 หรือ 1  D3
  • 7. #define NUM_PULSE (X) void loop() { if (count < NUM_PULSE) motorTurn(50.0); else motorTurn(0); Serial.print("Count: "); Serial.println(count); delay(100); } #define PULSE_PER_CM (X.X) void loop() { float speed = count / PULSE_PER_CM * 60; count = 0; motorTurn(100.0); Serial.print("Speed: "); Serial.println(speed); delay(1000); } โค้ดตัวอย่างสาหรับทดลอง จากผลการทดลอง cm/min
  • 8. PID controller • หลักการควบคุม = สร้างสัญญาณควบคุมจากการคานวณ error = setpoint - feedback • setpoint อ่านค่าจาก potentiometer • Feedback อ่านค่าจากเอ็นโค้ดเดอร์
  • 9. #define MAX_SPEED (X.Y) const float Kp = 1.0; const float Ki = 0.0; const float Kd = 0.0; float sumErr = 0.0; float lastSpeed = 0.0; setpoint = readSerial(); speed = count / PULSE_PER_CM * 600; speed = speed/MAX_SPEED * 100.0; float pidCtrl(float setpoint, float speed) { float error, ctrl, speedChange; error = setpoint – speed; sumErr += error; speedChange = speed – lastSpeed; ctrl = Kp*error + Ki*sumErr + Kd*speedChange; lastSpeed = speed; return ctrl; } โค้ดตัวอย่างสาหรับตัวควบคุม PID มาจากผลทดลอง อ่านตัวอักษรและคืนค่า แปลง rpm รอบ 0.1 s
  • 10. Results • เอกสารสรุปงาน (ประมาณ 3-4 หน้า ส่งพร้อมสาธิต) – ค่า pulse/cm และความเร็วสูงสุดจากการทดลอง – กราฟแสดง speed ของตัวควบคุม PID เมื่อปรับค่า Kp,Ki,Kd ต่างๆกัน (ใช้ delay(100) ภายใน loop) – โค้ดสมบูรณ์ที่รวมโค้ดตัวอย่างเข้าด้วยกัน • รับคาสั่งปรับทิศทางและความเร็วจากคอมพิวเตอร์ • กราฟแสดงการควบคุมความเร็ว เมื่อทดลองวางของที่น้าหนักต่างกันบนสายพาน • การให้คะแนนพิจารณาความเรียบร้อยของชิ้นงานด้วย