Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Arduino IDE][AX-12A] Issues reading Present Position from AX-12A #66

Closed
t-kitajima opened this issue Dec 19, 2018 · 7 comments
Closed
Assignees
Labels

Comments

@t-kitajima
Copy link

I tried to get the Present Position value of AX-12A by using Dynamixelworkbench, but it does not cause an error and the value is 0.
API of 1 can get the value with , but it could not get with API of 2.
What is the cause?
I will attach the log and code at that time.

1. bool readRegister (uint8_t id, uint16_t address, uint16_t length, uint32_t * data, const char ** log = NULL);
2. bool readRegister (uint8_t id, const char * item_name, int32_t * data, const char ** log = NULL);

Environment
OpenCM9.04, SMPS2Dynamixel, Arduino IDE 1.8.8, DynamixelWorkbench 1.3.0, Windows10

Dynamixel Setting

  • Model Name
    AX-12A

  • ID
    ID1

  • Baud Rate of Dynamixels
    1000000

  • Protocol Version
    Protocol1.0

code

#include <DynamixelWorkbench.h>

#define DEVICE_NAME "1"

#define BAUDRATE  1000000
#define DXL_ID_1  1

DynamixelWorkbench dxl_wb;

uint8_t dxl_id = DXL_ID_1;
uint16_t goal_position[2] = {0, 1023};
const uint8_t handler_index = 0;

void setup()
{
  Serial.begin(57600);
  while (!Serial); // Wait for Opening Serial Monitor

  const char *log;
  bool result = false;

  uint16_t model_number = 0;

  result = dxl_wb.init(DEVICE_NAME, BAUDRATE, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to init");
  }
  else
  {
    Serial.print("Succeeded to init : ");
    Serial.println(BAUDRATE);
  }
  result = dxl_wb.ping(dxl_id, &model_number, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to ping");
  }
  else
  {
    dxl_wb.torqueOn(dxl_id);
    Serial.println("Succeeded to ping");
    Serial.print("id : ");
    Serial.print(dxl_id);
    Serial.print(" model_number : ");
    Serial.println(model_number);
  }
}

void loop()
{
  const char *log;
  bool result = false;

  int32_t get_data = 0;

  // id , address , data_length , read_data, log
  result = dxl_wb.writeRegister(dxl_id, 30, 2, (uint8_t*)&goal_position[0], &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to write position");
  }
  else
  {
    Serial.println(log);
  }
  
  do
  {
    //result = dxl_wb.readRegister(dxl_id, 36 , 2, &get_data , &log);
    result = dxl_wb.readRegister(dxl_id, "Present_Position", &get_data , &log);
    if (result == false)
    {
      Serial.println(log);
    }
    else
    {
      Serial.print("[ID ");
      Serial.print(dxl_id);
      Serial.print(" ]");
      Serial.print(" Goal Position : ");
      Serial.print(goal_position[0]);
      Serial.print(" Present Position : ");
      Serial.println(get_data);
    }
  } while (abs(goal_position[0] - get_data) > 15);

  swapUint16(goal_position);
}

void swapUint16(uint16_t *array)
{
  uint16_t tmp = array[0];
  array[0] = array[1];
  array[1] = tmp;
}

log

Succeeded to init : 1000000
Succeeded to ping
id : 1 model_number : 12
[DynamixelDriver] Succeeded to write!
[ID 1 ] Goal Position : 0 Present Position : 0
[DynamixelDriver] Succeeded to write!
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
...
@routiful
Copy link

You should torque on and set joint mode to your dynamixels
Add below code after Ping()

    result = dxl_wb.jointMode(dxl_id, 0, 0, &log);
    if (result == false)
    {
      printf("%s\n", log);
      printf("Failed to change joint mode\n");
    }
    else
    {
      printf("Succeed to change joint mode\n");
    }

@t-kitajima
Copy link
Author

Does AX-12A not support jointMode?
Because it causes an error, torque is turned ON with "dxl_wb.torqueOn (dxl_id);" after ping.
I will also attach a log of errors.

log

Succeeded to init : 1000000
Succeeded to ping
id : 1 model_number : 12
[DynamixelWorkbench] Failed to set Joint Mode!
Failed to change joint mode
[DynamixelDriver] Succeeded to write!
[ID 1 ] Goal Position : 0 Present Position : 0
[DynamixelDriver] Succeeded to write!
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0
[ID 1 ] Goal Position : 1023 Present Position : 0

@routiful
Copy link

routiful commented Dec 21, 2018

I have found terribly mistakes write and readRegister functions.
Please update your OpenCM version.

I give you to test code, too.

#include <DynamixelWorkbench.h>

#define DEVICE_NAME "1"

#define BAUDRATE  1000000
#define DXL_ID_1  1

DynamixelWorkbench dxl_wb;

uint8_t dxl_id = DXL_ID_1;
uint16_t goal_position[2] = {0, 1023};
const uint8_t handler_index = 0;

void setup()
{
  Serial.begin(57600);
  while (!Serial); // Wait for Opening Serial Monitor

  const char *log;
  bool result = false;

  uint16_t model_number = 0;

  result = dxl_wb.init(DEVICE_NAME, BAUDRATE, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to init");
  }
  else
  {
    Serial.print("Succeeded to init : ");
    Serial.println(BAUDRATE);
  }
  
  result = dxl_wb.ping(dxl_id, &model_number, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to ping");
  }
  else
  {
    Serial.println("Succeeded to ping");
    Serial.print("id : ");
    Serial.print(dxl_id);
    Serial.print(" model_number : ");
    Serial.println(model_number);
  }

  result = dxl_wb.jointMode(dxl_id, 0, 0, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to set joint mode");
  }
  else
  {
    Serial.println("Succeeded to set joint mode");
  }
}

void loop()
{
  const char *log;
  bool result = false;

  int32_t get_data = 0;

  result = dxl_wb.writeRegister(dxl_id, "Goal_Position", goal_position[0], &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to write position");
  }
  else
  {
    Serial.println(log);
  }
  
  do
  {
    result = dxl_wb.readRegister(dxl_id, "Present_Position", &get_data , &log);
    if (result == false)
    {
      Serial.println(log);
    }
    else
    {
      Serial.print("[ID ");
      Serial.print(dxl_id);
      Serial.print(" ]");
      Serial.print(" Goal Position : ");
      Serial.print(goal_position[0]);
      Serial.print(" Present Position : ");
      Serial.println(get_data);
    }
  } while (abs(goal_position[0] - get_data) > 15);

  swapUint16(goal_position);
}

void swapUint16(uint16_t *array)
{
  uint16_t tmp = array[0];
  array[0] = array[1];
  array[1] = tmp;
}

@t-kitajima
Copy link
Author

I found the same bug yesterday.
Thanks for the measure of the bug.

I have an opinion on the modified code, where should I post?
modified write and read register

@t-kitajima
Copy link
Author

It is the case that JointMode becomes an error,
I think the AX - 12A seems to be unable to set MovingSpeed unless the torque is ON.
Is this a specification?

@routiful
Copy link

You can comment code line in commit or use pull request with your opinion.

I have tested that code with new version and the test is successful

Succeeded to init : 1000000
Succeeded to ping
id : 2 model_number : 12
Succeeded to set joint mode
[DynamixelDriver] Succeeded to write!
[ID 2 ] Goal Position : 0 Present Position : 0
[DynamixelDriver] Succeeded to write!
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0
[ID 2 ] Goal Position : 1023 Present Position : 0

@t-kitajima
Copy link
Author

It helped a lot.
I will write a comment in the code.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants