한 개의 모터를 제어해보니 여러개의 모터를 제어해보고 싶어집니다.
그래서 AX-18A를 2개 더 추가 구매합니다.
이렇게 모터 3형제가 준비되었으니 로보티즈의 Roboplus를 통해 모터의 ID를 부여할 준비를 합니다.
로보티즈의 U2D2와 SMPS2Dynamixel을 연결합니다.
이렇게 연결한 후 로보플러스를 실행합니다. 그리고 전문가 탭에서 Dynamixel Wizard를 클릭합니다.
그 후에 U2D2의 포트 번호를 확인한 후 연결을 누릅니다.
다음 화면에서 검색 시작을 누르면 연결되어 있는 모터의 리스트가 나옵니다.
액츄에이터를 각각 선택한 후에 모터에 1, 2, 3번의 ID를 부여해줍니다.
이제 모터를 제어할 준비가 다 되었으니 아두이노에 연결하여 모터를 움직일 준비를 합니다.
회로를 구성한 후 다음과 같이 아두이노 코드를 작성해 봅니다. (저번글 1축 모터 제어 소스에서 약간 수정)
#include "DynamixelMotor.h"
// id of the motor
const uint8_t id1 = 1;
const uint8_t id2 = 2;
const uint8_t id3 = 3;
// speed, between 0 and 1023
int16_t speed=512;
// communication baudrate
const long unsigned int baudrate = 1000000;
// hardware serial without tristate buffer
// see blink_led example, and adapt to your configuration
HardwareDynamixelInterface interface(Serial);
DynamixelMotor motor1(interface, id1);
DynamixelMotor motor2(interface, id2);
DynamixelMotor motor3(interface, id3);
void setup()
{
interface.begin(baudrate);
delay(100);
// check if we can communicate with the motor
// if not, we turn the led on and stop here
uint8_t status=motor1.init();
if(status!=DYN_STATUS_OK)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
while(1);
}
motor1.enableTorque();
motor2.enableTorque();
motor3.enableTorque();
// set to joint mode, with a 180° angle range
// see robotis doc to compute angle values
motor1.jointMode(204, 820);
motor1.speed(speed);
motor2.jointMode(204, 820);
motor2.speed(speed);
motor3.jointMode(204, 820);
motor3.speed(speed);
}
void loop()
{
// go to middle position
motor1.goalPosition(512);
motor2.goalPosition(512);
motor3.goalPosition(512);
delay(500);
// move 45° CCW
motor1.goalPosition(666);
motor2.goalPosition(666);
motor3.goalPosition(666);
delay(500);
// go to middle position
motor1.goalPosition(512);
motor2.goalPosition(512);
motor3.goalPosition(512);
delay(500);
// move 45° CW
motor1.goalPosition(358);
motor2.goalPosition(358);
motor3.goalPosition(358);
delay(500);
}
이렇게 코드를 작성한 후에 업로드를 하면 모터가 나란히 동작하는 것을 확인할 수 있네요.
'컴퓨터 > 아두이노' 카테고리의 다른 글
아두이노 우노 활용한 로보티즈 모터(AX-18A)의 블루투스 제어 (0) | 2017.12.04 |
---|---|
아두이노 메가 2560을 활용한 블루투스 통신 테스트(LED제어) (0) | 2017.12.04 |
아두이노 메가 2560을 활용한 로보티즈 모터(AX-18A) 제어 (0) | 2017.11.30 |
아두이노 메가 2560을 활용한 LED 제어 (0) | 2017.11.28 |
아두이노 우노를 활용한 로보티즈 모터(AX-18A) 제어 (1) | 2017.11.23 |