Hello everyone! I’m new to control system and Robotis product. So, I have a problem related to changing the PID value of the XL-320. So, I use system identification in Matlab to obtain the transfer function (using the goal and present position detected by the XL-320), then tune the Kp, Ki and Kd value to get the desired response of the system. Then, I try to put those (Kp, Ki, Kd) values to the Dynamixel XL-320 via Dynamixel Wizard 2 + OpenRB-150 and also try it in the Dynamixel+Arduino Uno, but both of the final response doesn’t change at all . Here attach the code that I used in the Arduino. Does anyone know what my problem is and how to solve this problem? Thank you in advance!
Regards,
Eka
/*******************************************************************************
* Copyright 2016 ROBOTIS CO., LTD.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/** Please refer to each DYNAMIXEL eManual(http://emanual.robotis.com) for supported Operating Mode
* Operating Mode
* 1. OP_POSITION (Position Control Mode in protocol2.0, Joint Mode in protocol1.0)
* 2. OP_VELOCITY (Velocity Control Mode in protocol2.0, Speed Mode in protocol1.0)
* 3. OP_PWM (PWM Control Mode in protocol2.0)
* 4. OP_EXTENDED_POSITION (Extended Position Control Mode in protocol2.0, Multi-turn Mode(only MX series) in protocol1.0)
* 5. OP_CURRENT (Current Control Mode in protocol2.0, Torque Mode(only MX64,MX106) in protocol1.0)
* 6. OP_CURRENT_BASED_POSITION (Current Based Postion Control Mode in protocol2.0 (except MX28, XL430))
*/
#include <DynamixelShield.h>
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
#include <SoftwareSerial.h>
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
#define DEBUG_SERIAL soft_serial
#elif defined(ARDUINO_SAM_DUE) || defined(ARDUINO_SAM_ZERO)
#define DEBUG_SERIAL SerialUSB
#else
#define DEBUG_SERIAL Serial
#endif
const uint8_t DXL_ID = 3;
const float DXL_PROTOCOL_VERSION = 2.0;
int32_t goal_position[2] = {900, 1000};
int8_t direction = 0;
unsigned long timer = 0;
// Position PID Gains
// Adjust these gains to tune the behavior of DYNAMIXEL
uint16_t position_p_gain = 1;
uint16_t position_i_gain = 20;
uint16_t position_d_gain = 0;
DynamixelShield dxl;
//This namespace is required to use Control table item names
using namespace ControlTableItem;
void setup() {
// put your setup code here, to run once:
// For Uno, Nano, Mini, and Mega, use UART port of DYNAMIXEL Shield to debug.
DEBUG_SERIAL.begin(115200);
// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(1000000);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
// Get DYNAMIXEL information
dxl.ping(DXL_ID);
// put your main code here, to run repeatedly:
// Position Control Mode in protocol2.0, Joint Mode in protocol1.0
// Turn off torque when configuring items in EEPROM area
dxl.torqueOff(DXL_ID);
dxl.setOperatingMode(DXL_ID, OP_POSITION);
dxl.torqueOn(DXL_ID);
// Set Position PID Gains
dxl.writeControlTableItem(POSITION_P_GAIN, DXL_ID, position_p_gain);
dxl.writeControlTableItem(POSITION_I_GAIN, DXL_ID, position_i_gain);
dxl.writeControlTableItem(POSITION_D_GAIN, DXL_ID, position_d_gain);
}
void loop(){
while(true) {
DEBUG_SERIAL.print("Goal_Position:");
DEBUG_SERIAL.print(dxl.readControlTableItem(GOAL_POSITION, DXL_ID));
DEBUG_SERIAL.print(",");
DEBUG_SERIAL.print("Present_Position:");
DEBUG_SERIAL.print(dxl.getPresentPosition(DXL_ID));
DEBUG_SERIAL.print(",");
DEBUG_SERIAL.println();
delay(10);
if (millis() - timer >= 2000) {
dxl.setGoalPosition(DXL_ID, goal_position[direction]);
timer = millis();
break;
}
}
if(direction >= 1) {
direction = 0;
} else {
direction = 1;
}
}