Posted January 8, 201510 yr I'm a beginner at nxt programming. I built a train drawbridge for my lego city. I thought, I would try and use the nxt technology to make the bridge go up and down as the train crossed over the bridge. I put a pressure switch at each end of the bridge. One to tell the bridge to go up and one to tell the bridge to go down. It seems so simple but has become so frustrating. If train comes from one direction each time no problem. But if the train comes from the other direction the commands get confused. I did two series of commands, each by themselves work just fine. If I put them together, since I'm using the same switches, the program gets confused. I hope someone can help me with my problem.
January 8, 201510 yr Some pictures of the bridge and sensors would help a bit if you can post them. At a guess, maybe you could add a timer for each switch. The timer is started when its switch is triggered. When the train approaches the bridge and hits the first switch, the other timer won't be running so the nxt can decide this is bridge up. It will then hit the second switch and see the first timer is still running so this is bridge down. If the train is comes in from the other direction, it will hit switch 2, but timer 1 is not running so it triggers bridge up. I may have to re-write all of that ^ if I've missed what you said earlier. By drawbridge I'm guessing you want it to open to allow the train through rather than boom gate that you would close when the train comes through? Good luck :) Edited January 8, 201510 yr by OzShan
January 8, 201510 yr Most likely it's the program itself (of course). Can you post a screenshot of the blocks/program? The way I would do this: 1. Start Program 2. Check if either of the two switches is activated If so, lower bridge, branch out (2 Y branches) 3. Wait for the other switch to be activated 4. Lift bridge. 5. Infinite loop, go back to #2 3/4/5 need to be done twice in your program, once for each of the branches. Edited January 8, 201510 yr by DrJB
January 8, 201510 yr Author Thanks for responding guys! The idea was for the bridge to stay up. As the train comes to the bridge, the bridge lowers and the train goes over the bridge. Once the train goes over the last pressure switch, it goes back up again. I'll try and post a picture of the program I've written. Any ideas to help out, will be greatly appreciated. I tried posting a picture of the program I wrote but it says the file was too big to upload. Not sure how to get that to work?
January 8, 201510 yr Author Most likely it's the program itself (of course). Can you post a screenshot of the blocks/program? The way I would do this: 1. Start Program 2. Check if either of the two switches is activated If so, lower bridge, branch out (2 Y branches) 3. Wait for the other switch to be activated 4. Lift bridge. 5. Infinite loop, go back to #2 3/4/5 need to be done twice in your program, once for each of the branches. I see what you are saying. How do you get the program to check if either of the switches is activated? I've tried posting a picture of what I've done so far but it didn't work. The way I wrote it was, the first switch lowers the bridge. Upon release of the second switch the bride goes back up. The problem I'm having is when the train comes back from the other direction. The switch comands between the two branches of comands get mixed up. If I could get it to read one branch at a time, it would solve my problem. It seems to read both at the same time. I'm sure it's an easy fix, if you know what you are doing. Thanks for your help.
January 8, 201510 yr I see what you are saying. How do you get the program to check if either of the switches is activated? I've tried posting a picture of what I've done so far but it didn't work. The way I wrote it was, the first switch lowers the bridge. Upon release of the second switch the bride goes back up. The problem I'm having is when the train comes back from the other direction. The switch comands between the two branches of comands get mixed up. If I could get it to read one branch at a time, it would solve my problem. It seems to read both at the same time. I'm sure it's an easy fix, if you know what you are doing. Thanks for your help. There is a special 'A or B' block you need to use. I do not recall the exact name, I'll look it up tonight and get back to you.
January 8, 201510 yr An 'A or B' block would certainly be simpler, but it can be done using simple commands by nesting the B sensor under the A sensor. Look at this diagram for code (if you have any questions, just ask): Key: A? : is sensor A pressed B? : is sensor B pressed Arrow+Y : Yes Arrow+N : No DownArrow+D : Lower Drawbridge UpArrow+D : Raise Drawbridge Loop encircling+infinity : Infinite Loop --- : Do Nothing (This was done quickly, so there may be errors, but I have checked the logic and it works in my head... I am not sure if NXT programming allows for a loop on only the "No" side of the sensor check...) Edited January 8, 201510 yr by Slegengr
January 8, 201510 yr Author There is a special 'A or B' block you need to use. I do not recall the exact name, I'll look it up tonight and get back to you. I'm not sure if I have a A or B block or how to get it? I have NXT 2.0.
January 9, 201510 yr I am going to use north and south entrance instead of A and B as this seems to be a bit confusing. I hope that's ok. This is the easiest program I can think of: - If the north sensor is pressed --- Yes: Lower bridge, allowing trains to pass --- --- Wait for south sensor to be bumped --- --- Raise bridge --- No: Is the south sensor pressed --- --- Yes: Lower bridge, allowing trains to pass --- --- --- Wait for north sensor to be bumped --- --- --- Raise bridge --- --- No: Do nothing I have attached an image of the program. If you like, PM me with your email and I can send the .rbt file to you.
January 9, 201510 yr Author I am going to use north and south entrance instead of A and B as this seems to be a bit confusing. I hope that's ok. This is the easiest program I can think of: - If the north sensor is pressed --- Yes: Lower bridge, allowing trains to pass --- --- Wait for south sensor to be bumped --- --- Raise bridge --- No: Is the south sensor pressed --- --- Yes: Lower bridge, allowing trains to pass --- --- --- Wait for north sensor to be bumped --- --- --- Raise bridge --- --- No: Do nothing I have attached an image of the program. If you like, PM me with your email and I can send the .rbt file to you. Thank you so much for your help! Your program worked perfectly. I see now what I was doing wrong. Thank you again for your time in helping me with this program.
January 9, 201510 yr Thank you so much for your help! Your program worked perfectly. I see now what I was doing wrong. Thank you again for your time in helping me with this program. ������ No problem. Have fun! Don't forget to post a video so we can see your creation. :)
January 9, 201510 yr I am going to use north and south entrance instead of A and B as this seems to be a bit confusing. I hope that's ok. This is the easiest program I can think of: - If the north sensor is pressed --- Yes: Lower bridge, allowing trains to pass --- --- Wait for south sensor to be bumped --- --- Raise bridge --- No: Is the south sensor pressed --- --- Yes: Lower bridge, allowing trains to pass --- --- --- Wait for north sensor to be bumped --- --- --- Raise bridge --- --- No: Do nothing I have attached an image of the program. If you like, PM me with your email and I can send the .rbt file to you. You beat me to it ... thanks to a busy schedule. But, all is good, as OP has the answer he needs. Thanks to all who helped.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.