RS485 Send and Receive Simultaneously. (Please help!)
Posted: 17 May 2011, 04:36
hhhhhhhhhhhhHi there, I am right now making a robot which uses two NXT's, six sensors, and four motors; however, I have run into a problem with programming it which is halting it's production. So, what I currently have is two NXT-G programs. One, for the master NXT, and the other for the slave NXT. It's purpose is to be an autonomus vehicle which (I hope) will be very inteligent due partially to its large number of sensors.
hhhhhhhhhhhhAt this point, I have gotten the slave NXT to send the value of its ultra sonic and light sensors to the master NXT so that the master can read the values in real time as though they're connected to that NXT itself. In addition, I have been trying to make there be three certain commands that the master can directly send to the slave NXT and control its motor. With this, the master NXT will be dependent on the slave NXT only for these things, and I will be able to program the rest of this robot's functions on the master NXT, that way, I will not have to constantly switch between the two programs when programming my robot.
hhhhhhhhhhhhUnfortunately, I have had trouble getting these motor commands to sucessfully send to the slave NXT over RS485. I have proven that the problem is with the master NXT, because I temporarily deleted the part of the master NXT's program which receives the sensor values, and sure enough, I was able to control the slave NXT's motor A. It is my belief that the receiving part of the RS485 command was taking proirity over the sending part. However, I have tried putting the sending commands into a separate thread from the receiving, and that didn't work. (I find it strange that the slave program, though it uses a thread for sending, and a thread for receiving, it has no problems. This could partially be due to the fact that it's not as big of a program or something else.)
hhhhhhhhhhhhFurthermore, I tried making a logic variable, setting it to false whenever the send commands were supposed to go, and setting the variable true whenever the send commands are not going, and only allowing the receive commands to execute when the logic variable is true. I've tried many other techniques that have failed, so please, if you are going to help me, then don't just present a theory without testing it. Please modify the program(s) included, and only post back if you've tested and gotten it to work.
hhhhhhhhhhhhSo, in a nutshell, I want the master NXT to be able to read from the slave NXT's light sensor in port 3, and ultra sonic sensor in port 1 as I can right now in the program, and also send motor commands to the slave NXT simultaneously. There are a few extra blocks that you will need to have installed to be able to edit these programs. Don't worry, I'll include them in the attachment incase you don't already have them installed. Plus, my programs have annotations in them which I think will help you out a lot in helping me (and maybe elongate your attention span). Please leave all code in NXT-G, I don't know any other programming languages for the NXT, and I don't have enough time to learn one well enough to finish this program and meet the deadline, so please keep it NXT-G. So, below are the programs:
hhhhhhhhhhhhAt this point, I have gotten the slave NXT to send the value of its ultra sonic and light sensors to the master NXT so that the master can read the values in real time as though they're connected to that NXT itself. In addition, I have been trying to make there be three certain commands that the master can directly send to the slave NXT and control its motor. With this, the master NXT will be dependent on the slave NXT only for these things, and I will be able to program the rest of this robot's functions on the master NXT, that way, I will not have to constantly switch between the two programs when programming my robot.
hhhhhhhhhhhhUnfortunately, I have had trouble getting these motor commands to sucessfully send to the slave NXT over RS485. I have proven that the problem is with the master NXT, because I temporarily deleted the part of the master NXT's program which receives the sensor values, and sure enough, I was able to control the slave NXT's motor A. It is my belief that the receiving part of the RS485 command was taking proirity over the sending part. However, I have tried putting the sending commands into a separate thread from the receiving, and that didn't work. (I find it strange that the slave program, though it uses a thread for sending, and a thread for receiving, it has no problems. This could partially be due to the fact that it's not as big of a program or something else.)
hhhhhhhhhhhhFurthermore, I tried making a logic variable, setting it to false whenever the send commands were supposed to go, and setting the variable true whenever the send commands are not going, and only allowing the receive commands to execute when the logic variable is true. I've tried many other techniques that have failed, so please, if you are going to help me, then don't just present a theory without testing it. Please modify the program(s) included, and only post back if you've tested and gotten it to work.
hhhhhhhhhhhhSo, in a nutshell, I want the master NXT to be able to read from the slave NXT's light sensor in port 3, and ultra sonic sensor in port 1 as I can right now in the program, and also send motor commands to the slave NXT simultaneously. There are a few extra blocks that you will need to have installed to be able to edit these programs. Don't worry, I'll include them in the attachment incase you don't already have them installed. Plus, my programs have annotations in them which I think will help you out a lot in helping me (and maybe elongate your attention span). Please leave all code in NXT-G, I don't know any other programming languages for the NXT, and I don't have enough time to learn one well enough to finish this program and meet the deadline, so please keep it NXT-G. So, below are the programs: