|
|
|
|
|
|
|
¾îÁ¦ : 909
|
¿À´Ã : 623
|
ÃÖ´ë : 3,402
|
Àüü : 756,477
|
|
|
|
|
|
|
|
|
|
|
ÀÚÀ¯°Ô½ÃÆÇ |
¢Æ Home | > | | ¹æ¹®ÀÚÄÚ³Ê | > | ÀÚÀ¯°Ô½ÃÆÇ |
|
|
|
|
|
|
|
|
Blue_RC_Car_linetrace.ino [Ãâó] [ºí·çRCÄ«] ¶óÀμ¾¼ ¼³Ä¡¿Í ¿¹Á¦ÄÚµå|ÀÛ¼ºÀÚ µð¹ÙÀ̽º¸¶Æ® |
|
|
±Û¾´ÀÌ : (58.¢½.52.195)
³¯Â¥ : 22-12-02 08:56
Á¶È¸ : 1061
|
|
https://blog.naver.com/no1_devicemart/221312208838 (591) |
|
#define MOTOR_A_a 3 //¸ðÅÍAÀÇ +Ãâ·ÂÇÉÀº 3¹øÇÉÀÔ´Ï´Ù
#define MOTOR_A_b 11 //¸ðÅÍAÀÇ -Ãâ·ÂÇÉÀº 11¹øÇÉÀÔ´Ï´Ù
#define MOTOR_B_a 5 //¸ðÅÍBÀÇ +Ãâ·ÂÇÉÀº 5¹øÇÉÀÔ´Ï´Ù
#define MOTOR_B_b 6 //¸ðÅÍBÀÇ -Ãâ·ÂÇÉÀº 6¹øÇÉÀÔ´Ï´Ù
#define MOTOR_SPEED 60 //¸ðÅÍÀÇ ±âÁؼӷÂÀÔ´Ï´Ù(0~255), ¶óÀÎÆ®·¹À̼´Â Àú¼ÓÁÖÇàÀ» ±ÇÀåµå¸³´Ï´Ù.
#define LINESENS_L 7 //¿ÞÂÊ ¶óÀμ¾¼ ÀÔ·ÂÇÉÀÔ´Ï´Ù.
#define LINESENS_R 8 //¿À¸¥ÂÊ ¶óÀμ¾¼ ÀÔ·ÂÇÉÀÔ´Ï´Ù.
unsigned char m_a_spd = 0, m_b_spd = 0; //¸ðÅÍÀÇ ¼Ó·ÂÀ» ÀúÀåÇÏ´Â Àü¿ªº¯¼ö
boolean m_a_dir = 0, m_b_dir = 0; //¸ðÅÍÀÇ ¹æÇâÀ» °áÁ¤ÇÏ´Â Àü¿ªº¯¼ö
void setup()
{
TCCR1B = TCCR1B & 0b11111000 | 0x05; //Àú¼ÓÁÖÇàÀÌ °¡´ÉÇϵµ·Ï ¸ðÅÍA PWM ÁÖÆļö º¯°æ
TCCR2B = TCCR2B & 0b11111000 | 0x07; //Àú¼ÓÁÖÇàÀÌ °¡´ÉÇϵµ·Ï ¸ðÅÍB PWM ÁÖÆļö º¯°æ
//¸ðÅÍ Á¦¾î ÇɵéÀ» Ãâ·ÂÀ¸·Î ¼³Á¤ÇÕ´Ï´Ù.
pinMode(MOTOR_A_a, OUTPUT);
pinMode(MOTOR_A_b, OUTPUT);
pinMode(MOTOR_B_a, OUTPUT);
pinMode(MOTOR_B_b, OUTPUT);
//¶óÀμ¾¼ ÇɵéÀ» ÀÔ·ÂÀ¸·Î ¼³Á¤ÇÕ´Ï´Ù.
pinMode(LINESENS_L, INPUT);
pinMode(LINESENS_R, INPUT);
}
void loop()
{
linetrace_val(); //ÀÔ·ÂµÈ µ¥ÀÌÅÍ¿¡ µû¶ó ¸ðÅÍ¿¡ ÀÔ·ÂµÉ º¯¼ö¸¦ Á¶Á¤ÇÏ´Â ÇÔ¼ö
motor_drive(); //¸ðÅ͸¦ ±¸µ¿ÇÏ´Â ÇÔ¼ö
}
void linetrace_val() //ÀÔ·ÂµÈ µ¥ÀÌÅÍ¿¡ µû¶ó ¸ðÅÍ¿¡ ÀÔ·ÂµÉ º¯¼ö¸¦ Á¶Á¤ÇÏ´Â ÇÔ¼ö
{
boolean line_l = digitalRead(LINESENS_L), line_r = digitalRead(LINESENS_R); //¿ÞÂÊ°ú ¿À¸¥ÂÊ ¶óÀμ¾¼ÀÇ °¨Áö°ªÀ» º¯¼ö¿¡ ÀúÀåÇÕ´Ï´Ù.
if(line_l == 0 && line_r == 0) //¶óÀÎÀÌ °¨ÁöµÇÁö ¾ÊÀ»¶§ ÀüÁø
{
m_a_dir = 0; //¸ðÅÍA Á¤¹æÇâ
m_b_dir = 0; //¸ðÅÍB Á¤¹æÇâ
m_a_spd = MOTOR_SPEED; //¸ðÅÍAÀÇ ¼Ó·Â°ª Á¶Á¤
m_b_spd = MOTOR_SPEED; //¸ðÅÍBÀÇ ¼Ó·Â°ª Á¶Á¤
}
else if(line_l == 1 && line_r == 0) //¿ÞÂÊ ¼¾¼ °¨Áö½Ã ¿ÞÂÊÀ¸·Î ÀüÁø
{
m_a_dir = 1; //¸ðÅÍA ¿ª¹æÇâ
m_b_dir = 0; //¸ðÅÍB Á¤¹æÇâ
m_a_spd = 0; //¸ðÅÍAÀÇ Á¤Áö
m_b_spd = constrain(MOTOR_SPEED*2, 0, 255); //¸ðÅÍBÀÇ ¼Ó·Â°ª Á¶Á¤
}
else if(line_l == 0 && line_r == 1) //¿À¸¥ÂÊ ¼¾¼ °¨Áö½Ã ¿À¸¥ÂÊÀ¸·Î ÀüÁø
{
m_a_dir = 0; //¸ðÅÍA Á¤¹æÇâ
m_b_dir = 1; //¸ðÅÍB ¿ª¹æÇâ
m_a_spd = constrain(MOTOR_SPEED*2, 0, 255); //¸ðÅÍAÀÇ ¼Ó·Â°ª Á¶Á¤
m_b_spd = 0; //¸ðÅÍBÀÇ Á¤Áö
}
else
{
m_a_dir = 0; //¸ðÅÍA Á¤¹æÇâ
m_b_dir = 0; //¸ðÅÍB Á¤¹æÇâ
m_a_spd = 0; //¸ðÅÍAÀÇ Á¤Áö
m_b_spd = 0; //¸ðÅÍBÀÇ Á¤Áö
}
}
void motor_drive() //¸ðÅ͸¦ ±¸µ¿ÇÏ´Â ÇÔ¼ö
{
if(m_a_dir == 0)
{
digitalWrite(MOTOR_A_a, LOW); //¸ðÅÍA+ LOW
analogWrite(MOTOR_A_b, m_a_spd); //¸ðÅÍA-ÀÇ ¼Ó·ÂÀ» PWM Ãâ·Â
}
else
{
analogWrite(MOTOR_A_a, m_a_spd); //¸ðÅÍA+ÀÇ ¼Ó·ÂÀ» PWM Ãâ·Â
digitalWrite(MOTOR_A_b, LOW); //¸ðÅÍA- LOW
}
if(m_b_dir == 1)
{
digitalWrite(MOTOR_B_a, LOW); //¸ðÅÍB+ LOW
analogWrite(MOTOR_B_b, m_b_spd); //¸ðÅÍB-ÀÇ ¼Ó·ÂÀ» PWM Ãâ·Â
}
else
{
analogWrite(MOTOR_B_a, m_b_spd); //¸ðÅÍB+ÀÇ ¼Ó·ÂÀ» PWM Ãâ·Â
digitalWrite(MOTOR_B_b, LOW); //¸ðÅÍB- LOW
}
}
[Ãâó] [ºí·çRCÄ«] ¶óÀμ¾¼ ¼³Ä¡¿Í ¿¹Á¦ÄÚµå|ÀÛ¼ºÀÚ µð¹ÙÀ̽º¸¶Æ®
|
|
|
|
|
|
|
|