
من میخام داینامیکسل ax12 رو با لپ تاپ و برنامه متلب راه اندازی کنم
کسی هست توی این زمینه منو راهنمایی کنه؟
مبدل یو اس بی به داینامیکسل رو گرفتم و از طریق ویزارد میتونم داینامیکسل رو پیدا میکنه
یه برنامه متلب هم واردش میکنم ولی جوابی از داینامیکسل نمیگیرم
دلیل: ادغام دو پست برای جلوگیری از اسپم
این برنامه ای هست که میدم
function [] = ReadWrite()
global ERRBIT_VOLTAGE
ERRBIT_VOLTAGE = 1;
global ERRBIT_ANGLE
ERRBIT_ANGLE = 2;
global ERRBIT_OVERHEAT
ERRBIT_OVERHEAT = 4;
global ERRBIT_RANGE
ERRBIT_RANGE = 8;
global ERRBIT_CHECKSUM
ERRBIT_CHECKSUM = 16;
global ERRBIT_OVERLOAD
ERRBIT_OVERLOAD = 32;
global ERRBIT_INSTRUCTION
ERRBIT_INSTRUCTION = 64;
global COMM_TXSUCCESS
COMM_TXSUCCESS = 0;
global COMM_RXSUCCESS
COMM_RXSUCCESS = 1;
global COMM_TXFAIL
COMM_TXFAIL = 2;
global COMM_RXFAIL
COMM_RXFAIL = 3;
global COMM_TXERROR
COMM_TXERROR = 4;
global COMM_RXWAITING
COMM_RXWAITING = 5;
global COMM_RXTIMEOUT
COMM_RXTIMEOUT = 6;
global COMM_RXCORRUPT
COMM_RXCORRUPT = 7;
loadlibrary('dynamixel','dynamixel.h');
libfunctions('dynamixel');
%Default Setting
id = 1; % dynamixel id
P_GOAL_POSITION = 30;
P_PRESENT_POSITION = 36;
DEFAULT_PORTNUM = 4; % com3
DEFAULT_BAUDNUM = 1; % 1mbps
P_Moving = 46;
int64 GoalPos;
GoalPos = [0 1023];
%GoalPos = [0 4095] %for Ex Series
int64 index;
index = 1;
int64 PresentPos;
int64 Moving;
int64 CommStatus;
%open device
res = calllib('dynamixel','dxl_initialize',DEFAULT_PORTN UM,DEFAULT_BAUDNUM);
if res == 1
disp('Succeed to open USB2Dynamixel!');
while (1)
reply = input('Do you want more? Y/N [Y]: ', 's');
if isempty(reply)
continue;
elseif (reply =='Y' || reply == 'y')
%Write goal position
calllib('dynamixel','dxl_write_word',id,P_GOAL_POS ITION,GoalPos(index));
Moving = 1;
while Moving == 1
%Read Present position
PresentPos = int64(calllib('dynamixel','dxl_read_word',id,P_PRE SENT_POSITION));
CommStatus = int64(calllib('dynamixel','dxl_get_result'));
if CommStatus == COMM_RXSUCCESS
Position =[GoalPos(index) PresentPos];
disp(Position);
PrintErrorCode();
else
PrintCommStatus(CommStatus);
break;
end
%Check moving done
Moving = int64(calllib('dynamixel','dxl_read_byte',id,P_Mov ing));
CommStatus = int64(calllib('dynamixel','dxl_get_result'));
if CommStatus == COMM_RXSUCCESS
if Moving == 0
if index == 1
index=2;
else
index=1;
end
end
PrintErrorCode();
else
PrintCommStatus(CommStatus);
break;
end
end
elseif(reply =='n' || reply=='N')
break;
end
end
else
disp('Failed to open USB2Dynamixel!');
end
%Close Device
calllib('dynamixel','dxl_terminate');
unloadlibrary('dynamixel');
%Print commuication result
function [] = PrintErrorCode()
global ERRBIT_VOLTAGE
global ERRBIT_ANGLE
global ERRBIT_OVERHEAT
global ERRBIT_RANGE
global ERRBIT_CHECKSUM
global ERRBIT_OVERLOAD
global ERRBIT_INSTRUCTION
if int64(calllib('dynamixel','dxl_get_rxpacket_error' , ERRBIT_VOLTAGE))==1
disp('Input Voltage Error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_ANGLE))==1
disp('Angle limit error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_OVERHEAT))==1
disp('Overheat error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_RANGE))==1
disp('Out of range error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_CHECKSUM))==1
disp('Checksum error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_OVERLOAD))==1
disp('Overload error!');
elseif int64(calllib('dynamixel','dxl_get_rxpacket_error' ,ERRBIT_INSTRUCTION))==1
disp('Instruction code error!');
end
% Print error bit of status packet
function [] = PrintCommStatus( CommStatus )
global COMM_TXFAIL
global COMM_RXFAIL
global COMM_TXERROR
global COMM_RXWAITING
global COMM_RXTIMEOUT
global COMM_RXCORRUPT
switch(CommStatus)
case COMM_TXFAIL
disp('COMM_TXFAIL : Failed transmit instruction packet!');
case COMM_TXERROR
disp('COMM_TXERROR: Incorrect instruction packet!');
case COMM_RXFAIL
disp('COMM_RXFAIL: Failed get status packet from device!');
case COMM_RXWAITING
disp('COMM_RXWAITING: Now recieving status packet!');
case COMM_RXTIMEOUT
disp('COMM_RXTIMEOUT: There is no status packet!');
case COMM_RXCORRUPT
disp('COMM_RXCORRUPT: Incorrect status packet!');
otherwise
disp('This is unknown error code!');
end