Light sensor program in C

This topic contains 3 replies, has 1 voice, and was last updated by  Abhey 2 years, 5 months ago.

  • Author
    Posts
  • #11157

    WinMan
    Member

    Beginner in C here and was tasked with working with a light sensor (attached to a Lego Mindstorms Robot) in C.

    I am needed to work with 3 objects that vary different light values and therefore I am using an array and working with if statements to declare what action to take between certain values that the objects are defined.

    All of these commands work apart from one,when hitting an object (2), the black line, which when hit the robot is meant to reverse and change direction.

    The code used within that area:

    The actions performed here do work but only sparsely and was wondering if anyone could provide a quick and easy solution.

    And to those wondering the average value of array [2] is normally 30-35, while the next closest light value is between 45-50

  • #11158

    Adelaid
    Member

    The code looks reasonable, assuming that the motor commands are correct. This would indicate that something else is wrong. Possible problems are:

    One other possibility is that the preceding code has an error that causes this code to be skipped.

  • #11159

    SapnaVishwas
    Member

    myLight is connected to the correct sensor, as for your other two points I am unsure how it can contain or return a different value as future strings of code that execute the colour[0] and [1]’s specific requirements work as expected and the method of recording those values are the same as colour[2]

    Currently looking to see if any possible errors could be caused to skip the code, so here’s the preceding section for those to gander at.

  • #11160

    Abhey
    Member

    It looks like sensor problem. I don’t know what kind of sensors are used in lego mindstorm, and how thick are your lines. It might be that sensor exposure to object is to short. So try to slow down your robot. If then it will start to act properly, it was a sensor problem.

    If so, you can try different programing approach, based on digital signal processing (if it’s possible in lego mind storm).

You must be logged in to reply to this topic.