Ev3 mindstorm going back and forward in a straight line

9 visualizaciones (últimos 30 días)
Karl-Axel Ruuth
Karl-Axel Ruuth el 17 de Dic. de 2017

I want to write a code for my Ev3 robot with two motors. I want it to be able to go a certain distance, in this case forward until the motors have turned a maximum of 2500 degress for four seconds. Then I want the robot to go back the same distance. But the problem is that sometimes only one motor spins while the other does nothing and sometimes a motor will continue to spin long after it has returned to its original position. I wonder if there is any way I can improve the code I have. I have tried it on several different Ev3 equitment so it is most likely not a hardware problem. Any help would be appreciated :)

b = Brick('ioType','usb');
b.outputStepSpeed(0,Device.MotorA,60,0,2500,0,Device.Brake);
b.outputStepSpeed(0,Device.MotorD,60,0,2500,0,Device.Brake); 
pause(4) 
b.outputStop(0,Device.MotorA,Device.Brake);
b.outputStop(0,Device.MotorD,Device.Brake); 
tacho = b.outputGetCount(0,Device.MotorA);         
disp(['> Tachometer: ' num2str(tacho)]);
b.outputClrCount(0,Device.MotorA); 
b.outputClrCount(0,Device.MotorD); 
pause(0) 
b.outputStepSpeed(0,Device.MotorA,-60,0,tacho,0,Device.Brake); 
b.outputStepSpeed(0,Device.MotorD,-60,0,tacho,0,Device.Brake); 
pause(4) 
b.outputStop(0,Device.MotorA,Device.Brake); 
b.outputStop(0,Device.MotorD,Device.Brake); 
tacho = 
b.outputGetCount(0,Device.MotorA);         
disp(['> Tachometer: ' num2str(tacho)]); 
b.outputClrCount(0,Device.MotorA); 
b.outputClrCount(0,Device.MotorD); 
clear

Respuestas (0)

Categorías

Más información sobre ROS Toolbox Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by