ROBOTIS-GIT / Dynamixel2Arduino

DYNAMIXEL protocol library for Arduino
Apache License 2.0
88 stars 55 forks source link

setOperatingMode does not work #89

Open THEb0nny opened 2 years ago

THEb0nny commented 2 years ago

I set the hinge mode to the 3rd ax-12a in the loop, but as it turned out that motors with id 2 and 3 did not set this mode. All motors were connected and the port monitor displayed the model number according to their ID. The motors were not working correctly, the motor was working correctly 1. Then I opened the RoboPlus application and looked at their mode of operation. 2 and 3 had wheel mode.

ROBOTIS-Will commented 2 years ago

Hi @THEb0nny

Could you give provide more information about the items below?

THEb0nny commented 2 years ago

@ROBOTIS-Will I am using opencm 9.04-c with OpenCM 485 EXP. The power supply is a Robiton power supply with various power options. I've tried 9 and 12 volts. I don't understand what point 3 means.

#include <Dynamixel2Arduino.h>  // Подключение библиотеки Dynamixel

#define DEBUG_SERIAL Serial // Установка константы, отвечающей за последовательный порт, подключаемый к компьютеру
#define DXL_SERIAL Serial3 // OpenCM9.04 EXP Board's DXL port Serial. (To use the DXL port on the OpenCM 9.04 board, you must use Serial1 for Serial. And because of the OpenCM 9.04 driver code, you must call Serial1.setDxlMode(true); before dxl.begin();.)

#define DXL_DIR_PIN 22 // Инициализация переменной, отвечащей за номер пина, подключенного к информационному пину приводов манипулятора
#define DXL_PROTOCOL_VERSION 1.0 // Инициализация переменной, отвечащей за протокол передачи данных от OpenCM9.04 к приводам

#define JOINT_N 3 // Количество приводов

Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN); // Инициализация указателя на команды из библиотеки Dynamixel

void setup() {
  Serial.begin(57600); // Установка скорости обмена данными по последовательному порту компьютера
  while(!DEBUG_SERIAL); // Ждём, пока монитор порта не откроется
  Serial.println("Setup...");
  dxl.begin(1000000); // Установка скорости обмена данными по последовательному порту манипулятора
  dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION); // Выбор протокола обмена данными
  delay(2000); // Ждём, чтобы моторы успели подключиться
  for (int i = 1; i <= JOINT_N; i++) { // Цикл для перебора всех приводов
    dxl.setOperatingMode(i, OP_POSITION); // Установка режима работы привода в качестве шарнира
    if(dxl.ping(i) == true) { // Проверка отвечает ли мотор
      Serial.print("Dynamixel with ID "); Serial.print(i); Serial.print(" found, model "); Serial.print(dxl.getModelNumber(i)); Serial.println(".");
    } else {
      Serial.print("Dynamixel with ID "); Serial.print(i); Serial.println(" not found!");
    }
  }
  delay(500);
}

void loop() {
  for (int i = 1; i <= JOINT_N; i++) {
    dxl.setGoalVelocity(i, 50); // Задание целевой скорости 50 приводу с номером i
    dxl.setGoalPosition(i, 410); // Задание целевого положения -30 градусов приводу с номером i
  }
  delay(2000); // Задержка, пока приводы займут нужное положение

  for (int i = 1; i <= JOINT_N; i++) {
    dxl.setGoalVelocity(i, 50); // Задание целевой скорости 50 приводу с номером i
    dxl.setGoalPosition(i, 614); // Задание целевого положения +30 градусов приводу с номером i
  }
  delay(2000); // Задержка, пока приводы займут нужное положение
}
ROBOTIS-Will commented 2 years ago

@THEb0nny Thanks for the code.

Is there a reason of commenting out several definitions in the beginning of the code? There are some critical definitions, so you should leave them uncommented when using DYNAMIXEL2Arduino library.

Not sure what went wrong other than that. Do you properly get the ping from each DYNAMIXEL? Could you check if applying a delay(10) after the setOperatingMode() helps?

THEb0nny commented 2 years ago

@THEb0nny Thanks for the code.

Is there a reason of commenting out several definitions in the beginning of the code? There are some critical definitions, so you should leave them uncommented when using DYNAMIXEL2Arduino library.

Not sure what went wrong other than that. Do you properly get the ping from each DYNAMIXEL? Could you check if applying a delay(10) after the setOperatingMode() helps?

I always write comments in define and I never had a problem. Can be removed.

The ping from the speakers works well. The motors are now tuned with cm-530. Each motor responds with its own ID and writes the model number.

ROBOTIS-Will commented 2 years ago

Oops, my bad.

My C++ intellisense wasn't working and the definitions just had the same text color with the comments so I thought they were commented out.

Each motor responds with its own ID and writes the model number.

So everything works fine now?

THEb0nny commented 2 years ago

Oops, my bad.

My C++ intellisense wasn't working and the definitions just had the same text color with the comments so I thought they were commented out.

Each motor responds with its own ID and writes the model number.

So everything works fine now?

Yes, everything works for us. Sorry I forgot to reply... It was necessary to turn off the torque so that memory writing could be carried out.