6

I am new to NBC programming and am trying to program my Lego NXT Brick to search for and follow a line of black electrical tape that I have on the floor (I have the light sensor in the front and pointing straight down at the ground). As of right now, the light turns on, but the robot just continues to go over the tape without acknowledging it. I also have it set up to stop and turn around if it bumps into a wall, which is working. The only thing that isn't working is acknowledging and following the black tape when the light goes over it. Can anyone take a look at my code and tell me where I am going wrong?

                                          dseg segment
  Switch sword 0
  Volume sword 0
  Level sword 0
  Distance sword 0
dseg ends

thread main
  SetSensorTouch(IN_1)    // touch sensor connected to IN_1
  SetSensorSound(IN_2)    // sound sensor connected to IN_2
  SetSensorLight(IN_3)    // Light Sensor connected to input 3
  SetSensorUltrasonic(IN_4) // Ultrasonic Sensor connected to input 4
  OnFwd(OUT_BC,80)     // move forward

CheckSensor:

  ReadSensor(IN_1,Switch)       // reads current value of sensor (0/1)
  brtst EQ, CheckSensor, Switch // branch to CheckSensor if Switch = 0
                              // i.e., exit the loop when Switch = 1


  OnRev(OUT_BC,40)      // move backward
  wait 500
  OnFwd(OUT_B,20)       // turn
  wait 500

  jmp CheckSound

CheckSound:
  ReadSensor(IN_2, Volume)
  brcmp GT, ExitCheck, Volume, 60

  jmp CheckSound

 ExitCheck:

 OnFwd(OUT_BC,60)

  jmp CheckLight

  CheckLight:
  ReadSensor(IN_3,Level)
  brcmp LT, CheckLight, Level, 60

  ReadSensorUS(IN_4,Distance)
  brcmp LT, EndPoint, Distance, 30

  OnFwd(OUT_C, 10)

  FindPath:
  ReadSensor(IN_3,Level)
  brcmp GTEQ, FindPath, Level, 60

  OnFwd(OUT_BC, 60)

  jmp CheckLight

  EndPoint:

  Off(OUT_BC)

  wait 1500



endt

enter image description here

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
Bryan
  • 2,659
  • 8
  • 46
  • 84
  • 2
    сan you remove unneccessary sounds call in you code (in order to simplify to understand)? And also LDD or at least photo of your bot will be useful to understand where you sensor situated and how your drive you wheels – Sergey N Lukin Dec 15 '13 at 15:47
  • 1
    Edited the post with an image of what the bot looks like and took out the sound parts in the code. – Bryan Dec 15 '13 at 16:35
  • If I need to do anything more to make it easier for you to help me, please let me know. Would really appreciate some help! – Bryan Dec 15 '13 at 21:11

2 Answers2

3

If this is the same NXT that I used, then you aren't getting anywhere soon. The light sensor in this kit is garbage, you have to just fiddle with what it considers "On" until it actually picks it up. I wish i had a better answer for you, but I've used these things for 4 years and never had it work exactly the way I want. I used the visual software that came with the kit, and it had an option to set how much was needed for it to be set, try looking for something similar.

  • If the light turns on, should I expect it to recognize the black tape, or is that not necessarily the case? – Bryan Dec 28 '13 at 02:53
  • 1
    @Bryan Not necessarily. It can be pretty tricky to fine tune what the robot defines as "black" and "not-black". – Andrew Gies Jan 05 '14 at 20:22
  • I ran some tests and have confirmed that the light sensor DOES pick up on the black electrical tape, it is just my code that isn't working properly. Any help with my code? – Bryan Jan 14 '14 at 05:05
0

If you are using NXT-G, there are many ways to get your code to react to your dark tape.

The easiest (but maybe not the best for what you're doing) is to have a wait block wait for the light's reading to go below a certain value (when it detects darkness) while the wheels are turning "unlimited". You specify that value in the details pane at the bottom.

Or, you could use a yellow sensor block to get the reading from the light sensor and use yellow data wires to put that number into a compare block. Then, the compare block will check if your brightness is dark enough with it's true/false output data wire.

A tip for using electrical tape: it is shiny! So maybe turn off red light by unchecking the box, otherwise, it will just reflect light and the robot won't see it.

Colin
  • 1