3D Printing X Robotics
InMoov Hand Robo Making
Chapter 9
작동 코드의 분석
-
-
-

작동 코드에 대하여 분석하도록 하겠습니다
현재 설계된 로봇 의수의 경우, 아두이노를 이용하여 제어되기 때문에
관련된 프로그램을 설치하고 코드를 작성, 활용하여야 합니다
https://www.arduino.cc/
위 페이지에서 아두이노 코드를 작성할 수 있는 개발 환경을 다운로드 받아 설치해야 합니다
구현하고자 하는 기능을 단순화 해 보면 다음과 같습니다
1. 특정 센서를 통해 손가락의 움직임 정도를 제어하도록 조절함
2. 센서를 통해 받아들여진 값에 따라 서보모터가 작동하도록 함
이 두 가지 기능을 구현시키기 위해서 필요한 것이 바로 다음의 소스코드입니다
#include <Servo.h>
Servo thumbservo,indexservo,middleservo,ringservo,littleservo; // create servo object to control a servo
int thumbpin = 0; // analog pin for thumb connect the flex sensor
int indexpin = 1; // analog pin for index connect the flex sensor
int middlepin = 2; // analog pin for middle connect the flex sensor
int ringpin=3; // analog pin for ring connect the flex sensor
int littlepin=4; // analog pin for little connect the flex sensor
int val1,val2,val3,val4,val5; // variable to read the value from the analog pin
void setup()
{
thumbservo.attach(5); // attaches the servo on pin 5 for the thumb
indexservo.attach(6); // attaches the servo on pin 6 for index finger
middleservo.attach(9); // attaches the servo on pin 9 for the middle finger
ringservo.attach(10); // attaches the servo on pin 10 for the ring finger
littleservo.attach(11); // attaches the servo on pin 11 for the little finger
}
void loop()
{
val1 = analogRead(thumbpin); // reads the value of the potentiometer (value between 0 and 1023)
val1= map(val1, 100, 900, 0, 179); // scale it to use it with the servo (value between 0 and 180)
thumbservo.write(val1); // sets the servo position according to the scaled value
val2 = analogRead(indexpin); // reads the value of the potentiometer (value between 0 and 1023)
val2= map(val2, 100, 900, 0, 179); // scale it to use it with the servo (value between 0 and 180)
indexservo.write(val2); // sets the servo position according to the scaled value
val3 = analogRead(middlepin); // reads the value of the potentiometer (value between 0 and 1023)
val3= map(val3, 100, 900, 0, 179); // scale it to use it with the servo (value between 0 and 180)
middleservo.write(val3); // sets the servo position according to the scaled value
val4 = analogRead(ringpin); // reads the value of the potentiometer (value between 0 and 1023)
val4= map(val4, 100, 900, 0, 179); // scale it to use it with the servo (value between 0 and 180)
ringservo.write(val4); // sets the servo position according to the scaled value
val5 = analogRead(littlepin); // reads the value of the potentiometer (value between 0 and 1023)
val5= map(val5, 100, 900, 0, 179); // scale it to use it with the servo (value between 0 and 180)
littleservo.write(val5); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
}
소스코드를 기반으로 기능에 대해 한 가지씩 설명하도록 하겠습니다
include <servo.h>
서보모터를 사용하는 라이브러리를 추가하는 코드입니다