anybody help me with servo controller in matlab
hi,everyone,recently I am doing basic control of BLDC motor in matlab, I tried many ways but the dc motor still not going any body did control in MATLAB please give me a hand, I attached the code below please show me what's the mistake I had! Thanks
function y = servo_control(u)
pulse_width=round(u);
ser_obj=serial('COM8','baudrate',9600);
ser_obj.terminator = 'CR';
fopen(ser_obj);
fprintf(ser_obj,'%d\n',pulse_width); % send duration of pulse width used to control the servomotor
fclose(ser_obj);
y=u;
function y = servo_control(u)
pulse_width=round(u);
ser_obj=serial('COM8','baudrate',9600);
ser_obj.terminator = 'CR';
fopen(ser_obj);
fprintf(ser_obj,'%d\n',pulse_width); % send duration of pulse width used to control the servomotor
fclose(ser_obj);
y=u;
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......
function servo_control(sp)
global magSerial
magSerial=serial('COM8');
set(magSerial,'BaudRate',2400,'StopBits',2,'Terminator','cr') %USB Serial Port
magSerial.Timeout = 1; %time to wait for the recorded data
magSerial.ByteOrder = 'bigEndian';
magSerial.terminator = 'CR';
fopen(magSerial)
servoPos=sp+750;
servoRamp=20;
highByte=floor(servoPos/256);
lowByte=servoPos-highByte*256;
%send data to the serial port
fwrite(magSerial,[noparse][[/noparse]abs('!SC'),0,servoRamp,lowByte,highByte,13])
%fwrite(magSerial,[noparse][[/noparse]abs('!SC'),1,servoRamp,lowByte,highByte,13])
fclose(magSerial)
clear magSerial
end
that is the position control and for example give a initial postion 1500 and desired postion 500 just give command in matlab servo_control(1500);servo_control(500)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......