아두이노로 속도제어와 위치제어를 동시에 구현하고 싶은데,
다이나믹셀이 2개라서 기존 <write_x>를 수정해야 합니다.
어떻게 수정해야 할까요?
+) void loop문에서 "suggested alternative: ‘dxl_1’ exit status 1 ‘dx1_1’ was not declared in this scope "
라고 오류 메세지가 뜹니다.
(참고 : 제어기는 OpenRB-150 사용)
#include <Dynamixel2Arduino.h>
#include <DynamixelShield.h>
// Please modify it to suit your hardware.
#if defined(ARDUINO_OpenRB) // When using OpenRB-150
//OpenRB does not require the DIR control pin.
#define DXL_SERIAL Serial1
#define DEBUG_SERIAL Serial
const int DXL_DIR_PIN = -1;
#else // Other boards when using DynamixelShield
#define DXL_SERIAL Serial1
#define DEBUG_SERIAL Serial
const int DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
#endif
//Please see eManual Control Table section of your DYNAMIXEL.
//This example is written for DYNAMIXEL X series(excluding XL-320)
#define OPERATING_MODE_ADDR 11
#define OPERATING_MODE_ADDR_LEN 1
#define TORQUE_ENABLE_ADDR 64
#define TORQUE_ENABLE_ADDR_LEN 1
#define LED_ADDR 65
#define LED_ADDR_LEN 1
#define GOAL_POSITION_ADDR 116
#define GOAL_POSITION_ADDR_LEN 4
#define PRESENT_POSITION_ADDR 132
#define PRESENT_POSITION_ADDR_LEN 4
#define POSITION_CONTROL_MODE 3
#define TIMEOUT 10 //default communication timeout 10ms
uint8_t turn_on = 1;
uint8_t turn_off = 0;
const uint8_t DXL_ID_1 = 1;
const uint8_t DXL_ID_0 = 0;
const float DXL_PROTOCOL_VERSION = 2.0;
//Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
DynamixelShield dxl_1;
DynamixelShield dxl_0;
Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
using namespace ControlTableItem;
uint8_t operatingMode = POSITION_CONTROL_MODE;
uint32_t a;
uint32_t b;
void setup() {
Serial.begin(57600);
DEBUG_SERIAL.begin(115200); //Set debugging port baudrate to 115200bps
while(!DEBUG_SERIAL); //Wait until the serial port for terminal is opened
// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl_1.begin(57600);
dxl_0.begin(57600);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl_1.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
dxl_0.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
dxl_1.ping(DXL_ID_1);
dxl_0.ping(DXL_ID_0);
// Turn off torque when configuring items in EEPROM area
if(dxl_0.write(DXL_ID_0, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_off , TORQUE_ENABLE_ADDR_LEN, TIMEOUT) && dxl_1.write(DXL_ID_1, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_off , TORQUE_ENABLE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println("DYNAMIXEL Torque off");
else
DEBUG_SERIAL.println("Error: Torque off failed");
// Set Operating Mode
if(dxl_0.write(DXL_ID_0, OPERATING_MODE_ADDR, (uint8_t*)&operatingMode, OPERATING_MODE_ADDR_LEN, TIMEOUT)&& dxl_1.write(DXL_ID_1, OPERATING_MODE_ADDR, (uint8_t*)&operatingMode, OPERATING_MODE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println("Set operating mode");
else
DEBUG_SERIAL.println("Error: Set operating mode failed");
// Turn on torque
if(dxl_0.write(DXL_ID_0, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_on, TORQUE_ENABLE_ADDR_LEN, TIMEOUT)&& dxl_1.write(DXL_ID_1, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_on, TORQUE_ENABLE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println("Torque on");
else
DEBUG_SERIAL.println("Error: Torque on failed");
}
void loop() {
dx1_1.write(DXL_ID_1, LED_ADDR, (uint8_t*)&turn_on, LED_ADDR_LEN, TIMEOUT);
delay(100);
dxl_1.write(DXL_ID_1, GOAL_POSITION_ADDR, (uint8_t*)&a, GOAL_POSITION_ADDR_LEN, TIMEOUT);
delay(1000);
dxl_1.write(DXL_ID_1, LED_ADDR, (uint8_t*)&turn_off, LED_ADDR_LEN, TIMEOUT);
delay(100);
dxl_1.write(DXL_ID_1, GOAL_POSITION_ADDR, (uint8_t*)&b, GOAL_POSITION_ADDR_LEN, TIMEOUT);
delay(1000);
}