- #1
thekey
- 14
- 0
Hi
Controlling the LEGO NXT Using MatLab
What are my mistakes in this code ??!
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
COM_CloseNXT(handle);
NXT_GetBatteryLevel(handle);
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
OpenSwitch(SENSOR_1);
x = 1;
power=50;
foreverLoop= 1;
loop = 1;
Kp = 1000;
offset = 45;
Tp = 25;
error = 0;
powerA = 0;
powerB = 0;
degrees=360;
powerA = Tp + Turn;
powerB = Tp - Turn;
Kd = 1;
dervative = 0;
lastError = 0;
while
foreverloop
while
x == 1
if GetSwitch(SENSOR_1)
disp (
'Hello world')
x = 2;
end
end
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
getlight (SENSOR_3)
motorA = NXTMotor (MOTOR_A,
'Power',power,'TachoLimit', degrees);
motorB = NXTMotor (MOTOR_B,
'Power',power,'TachoLimit', degrees);
motorA.Stop (
'off');
motorA.ResetPosition();
data1 = motorA.ReadFromNXT();
position1 = data1.Position;
motorB.SendToNXT();
motorB.WaitFor();
motorB.Stop (
'off');
data2 = motorA.ReadFromNXT();
position2 = data2.Position;
dsip(position1,position2);
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
OpenSwitch(SENSOR_1);
OpenUltrasonic(SENSOR_2);
mA = NXTMotor (MOTOR_A,
'Power',power);
mA.Stop (
'off');
mA.ResetPosition();
mB=NXTMotor(MOTOR_B,
'Power',power);
mB.Stop(
'off');
mB.ResetPosition();
while
x == 2
if GetUltrasonic(SENSOR_2) <= 15
motorA.Stop (
'brake');
data2 = motorA.ReadFromNXT();
position2 = data2.Position;
disp (
'Pardon Me')
x = 1;
else
motorA.SendToNXT();
end
end
motorA.Stop (
'off');
COM_CloseNXT(handle);
integral=integral+error;
ForeverLoop=1;
OpenSwitch(SENSOR_3);
OpenLight(SENSOR_1,
'Active' )
Loop
forever;
Turn=(Kp*error);
LightValue = OpenLight;
error= LightValue - offset;
Turn= (Turn) / 1000;
powerA = ceil(Tp + Turn);
powerB = ceil(Tp - Turn);
motorA = NXTMotor (MOTOR_A,
'Power',powerA, 'TachoLimit',0);
motorB = NXTMotor (MOTOR_B,
'Power',powerC, 'TachoLimit',0);
motorA.SendToNXT();
motorB.SendToNXT();
derivative = error - lastError;
Turn = (Kp * error) + (Ki * integral) + (Kd * derivative);
lastError = error;
end
Controlling the LEGO NXT Using MatLab
What are my mistakes in this code ??!
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
COM_CloseNXT(handle);
NXT_GetBatteryLevel(handle);
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
OpenSwitch(SENSOR_1);
x = 1;
power=50;
foreverLoop= 1;
loop = 1;
Kp = 1000;
offset = 45;
Tp = 25;
error = 0;
powerA = 0;
powerB = 0;
degrees=360;
powerA = Tp + Turn;
powerB = Tp - Turn;
Kd = 1;
dervative = 0;
lastError = 0;
while
foreverloop
while
x == 1
if GetSwitch(SENSOR_1)
disp (
'Hello world')
x = 2;
end
end
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
getlight (SENSOR_3)
motorA = NXTMotor (MOTOR_A,
'Power',power,'TachoLimit', degrees);
motorB = NXTMotor (MOTOR_B,
'Power',power,'TachoLimit', degrees);
motorA.Stop (
'off');
motorA.ResetPosition();
data1 = motorA.ReadFromNXT();
position1 = data1.Position;
motorB.SendToNXT();
motorB.WaitFor();
motorB.Stop (
'off');
data2 = motorA.ReadFromNXT();
position2 = data2.Position;
dsip(position1,position2);
COM_CloseNXT(handle);
COM_CloseNXT
all
clc
clear
handle = COM_OpenNXT();
COM_SetDefaultNXT(handle);
OpenSwitch(SENSOR_1);
OpenUltrasonic(SENSOR_2);
mA = NXTMotor (MOTOR_A,
'Power',power);
mA.Stop (
'off');
mA.ResetPosition();
mB=NXTMotor(MOTOR_B,
'Power',power);
mB.Stop(
'off');
mB.ResetPosition();
while
x == 2
if GetUltrasonic(SENSOR_2) <= 15
motorA.Stop (
'brake');
data2 = motorA.ReadFromNXT();
position2 = data2.Position;
disp (
'Pardon Me')
x = 1;
else
motorA.SendToNXT();
end
end
motorA.Stop (
'off');
COM_CloseNXT(handle);
integral=integral+error;
ForeverLoop=1;
OpenSwitch(SENSOR_3);
OpenLight(SENSOR_1,
'Active' )
Loop
forever;
Turn=(Kp*error);
LightValue = OpenLight;
error= LightValue - offset;
Turn= (Turn) / 1000;
powerA = ceil(Tp + Turn);
powerB = ceil(Tp - Turn);
motorA = NXTMotor (MOTOR_A,
'Power',powerA, 'TachoLimit',0);
motorB = NXTMotor (MOTOR_B,
'Power',powerC, 'TachoLimit',0);
motorA.SendToNXT();
motorB.SendToNXT();
derivative = error - lastError;
Turn = (Kp * error) + (Ki * integral) + (Kd * derivative);
lastError = error;
end