EV3 Color Sensor Fails

HomeForumsMonoBrick EV3 FirmwareEV3 Color Sensor Fails

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3963

    Hi,

    I am currently using this simple program:

    using System.Threading;
    using System.Threading.Tasks;
    using MonoBrickFirmware.UserInput;
    using MonoBrickFirmware.Display;
    using MonoBrickFirmware.Sensors;
    using MonoBrickFirmware.Movement;
    using MonoBrickFirmware;
    
    namespace EV3Program
    {
    	internal class Program
    	{
    		private static void Main(string[] args)
    		{
    			ManualResetEvent terminateProgram = new ManualResetEvent(false);
    
    			ButtonEvents buts = new ButtonEvents();
    			buts.EscapePressed += () =>
    			{
    				System.Threading.Thread.Sleep(100);
    				terminateProgram.Set();
    			};
    
    			Task.Factory.StartNew(() => new Program().MainAlgorythm());
    
    			terminateProgram.WaitOne();
    		}
    
    		private void MainAlgorythm()
    		{
    			EV3ColorSensor SensorColorLeft = new EV3ColorSensor (SensorPort.In3, ColorMode.Reflection);
    			EV3ColorSensor SensorColorRight = new EV3ColorSensor (SensorPort.In4, ColorMode.Reflection);
    			//Touch Sensor
    			IRSensor IRSensor_Front = new IRSensor (SensorPort.In2, IRMode.Proximity);
    
    			Motor MotorA = new Motor (MotorPort.OutA);
    			Motor MotorB = new Motor (MotorPort.OutB);
    			Motor MotorPliers = new Motor (MotorPort.OutD);			  
    
    			MotorSync SyncAB = new MotorSync (MotorPort.OutA, MotorPort.OutB);
    
    			sbyte spinA = 30;
    			sbyte spinB = 30;
    
    			while (true) 
    			{
    				LcdConsole.WriteLine ("Reflection Value:" + SensorColorLeft.ReadRaw ());
    
    				MotorA.On (spinA);
    				MotorB.On (spinB);
    
    				if (SensorColorLeft.ReadRaw () < 15 && SensorColorRight.ReadRaw () >  15 && spinB != 60) 
    				{
    					spinA = -15;
    					spinB = 60;
    					//MotorB.ResetTacho ();
    				}
    
    				if(SensorColorLeft.ReadRaw () > 15 && SensorColorRight.ReadRaw () <  15 && spinA != 60)
    				{
    					spinA = 60;
    					spinB = -15;
    					//MotorA.ResetTacho ();
    				}
    
    				/*if (SensorColorLeft.ReadRaw () > 15 && SensorColorRight.ReadRaw () >  15 && MotorA.GetTachoCount() > 90 && MotorB.GetTachoCount() > 90) 
    				{
    					spinA = 30;
    					spinB = spinA;
    					MotorA.ResetTacho ();
    					MotorB.ResetTacho ();
    				}
    				if (IRSensor_Front.ReadDistance () < 20) 
    				{
    					spinA = 100;
    					spinB = 100;
    				}*/
    						 
    			}
    		}
    	}
    }

    The EV3 just follows the line like it should, but it seems not to recognize black in irregular intervals and just keeps spinning around… This happens in both directions, left and right, so I think it is not because of the sensors. I had a program where the black value was printed on the screen, and it was about <17 so this should not be the problem, too.

    #3968
    Author Image
    Anders Søborg
    Keymaster

    Hi

    What happens if both the left and right sensor is above 15 or both the left and right sensor is below 15? Won’t robot keep spinning (or keep doing the last thing you told it to)?

    Anders

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Posted in

Make a donation