Move a dynamixel starting from acceleration

Hi all, I am a very rookie in the Arduino environment.
I am planning to detect the accelerations of an OpenCR 1.0 thanks to its incorporated IMU and to move a dynamixel consequentially.
Thus, what I want is to mix the sketch of IMU_Read_AccRAW and that one of Dynamixel Workbench library, called j_Current_Based_Position.
When for example the x_acceleration overpasses a value or it is in a specific range of numbers, then the dynamixel has to reach a specific angle.
I am sorry for my not complete knowledge about it indeed some tip could be nice for sure.
By the way, the first sketch is built completely on the loop. Instead, the second sketch in the setup. I tried more ways but I never figured it out.
Can U please explain to me something about the way of thinking?
IMU_Read_AccRAW:

#include <IMU.h>
cIMU    IMU;
uint8_t   led_tog = 0;
uint8_t   led_pin = 13;
void setup()
{
  Serial.begin(115200);
  IMU.begin();
  pinMode( led_pin, OUTPUT );
}
void loop()
{
  static uint32_t tTime[3];
  static uint32_t imu_time = 0;
  if( (millis()-tTime[0]) >= 500 )
  {
    tTime[0] = millis();
    digitalWrite( led_pin, led_tog );
    led_tog ^= 1;
  }
  tTime[2] = micros();
  if( IMU.update() > 0 ) imu_time = micros()-tTime[2];
  if( (millis()-tTime[1]) >= 50 )
  {
    tTime[1] = millis();
    Serial.print(imu_time);
    Serial.print(" \t");
    Serial.print(IMU.accRaw[0]);    // ACC X
    Serial.print(" \t");
    Serial.print(IMU.accRaw[1]);    // ACC Y
    Serial.print(" \t");
    Serial.print(IMU.accRaw[2]);    // ACC Z
    Serial.println(" ");
  }
}

J_Current_Based_Position:

#include <DynamixelWorkbench.h>
#if defined(__OPENCM904__)
  #define DEVICE_NAME "3" //Dynamixel on Serial3(USART3)  <-OpenCM 485EXP
#elif defined(__OPENCR__)
  #define DEVICE_NAME ""
#endif   
#define BAUDRATE  57600
#define DXL_ID    1
DynamixelWorkbench dxl_wb;
void setup() 
{
  Serial.begin(57600);
  while(!Serial); // Wait for Opening Serial Monitor
  const char *log;
  bool result = false;
  uint8_t dxl_id = DXL_ID;
  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.currentBasedPositionMode(dxl_id, 30, &log);
  if (result == false)
  {
    Serial.println(log);
    Serial.println("Failed to change current based position mode");
  }
  else
  {
    Serial.println("Succeed to change current based position mode");
    Serial.println("Dynamixel is moving...");
    for (int count = 0; count < 3; count++)
    {
      dxl_wb.goalPosition(dxl_id, (int32_t)0);
      delay(3000);
      dxl_wb.goalPosition(dxl_id, (int32_t)2048);
      delay(3000);
    }
  }
}

void loop() 
{
}