Sign in to follow this  
Followers 0
Battle-Bug

Random Timer - RSLogix 1000

11 posts in this topic

I'm a student at Texas A&M University and I'm in a class on robotics. For my final project, I've chosen to build a Whac-O-Mole machine. However, I don't know how to make random timers. I found the following link, but don't exactly know how to turn it into a random timer. I also don't know if it even works with MicroLogix 1000 (which is what I'm using). http://forums.mrplc.com/index.php?showtopic=16883 Please help me to create a random timer for my school project. Thanks, Mike Edited by Battle-Bug

Share this post


Link to post
Share on other sites
Check out the attached program. It is generating a new random number after each timer timeout. To read more about shift register random number generators check this link [Edit - I have modified the RSS file to fix obvious problems. I don't have a MLX1000 to test on though.] 15_BIT_SR.RSS Edited by b_carlton

Share this post


Link to post
Share on other sites
With a bottom dweller like the ML 1000 you have some limitations. The ML1K has limited math and it doesn't support indirect addressing and it has a very small and limited data file set. For a game you will want random numbers that are limited to a specific range. One approach might be to use a table containing a large number of random numbers - if you have a large enough table then the game will appear to be random to a human even though it repeats. Excel can be used to generate the numbers you put in the table and it can be set up to limit the numbers to the time range you want (e.g. 0 to 300 for 0 to 3 seconds). Once you have the table constructed then just move the numbers from the table to your timers. Since you can't use indirect addressing one way to do this is to use a sequencer SQO instruction. Configure the SQO to move a new value to the timer preset after the time period completes. SQO sequences through the file and then wraps back around to the beginning. I've attached a file that shows how to sequence through a table containing 95 random numbers and load those numbers into three different timers. (PS, I didn't put any random numbers in the table - that'll be up to you should you decide to use a tabular method.) Wackamole.RSS Edited by Alaric

Share this post


Link to post
Share on other sites
Go to your library and search for Donald Knuth's famous "Art of Computer Programming" series. http://en.wikipedia.org/wiki/The_Art_of_Computer_Programming Volume 2 has an entire section devoted to nothing more than random numbers. You can trivially make a pretty good random number generator with the simple expression (seed*A+B) mod M. At each iteration, you plug the last calculated value back in as the seed for the next iteration. This is a linear congruent generator: http://en.wikipedia.org/wiki/Linear_congruential_generator Note that it is easily possible to have M equal to say 2^15 so that in practice you run the calculation and then bitwise AND it with 32767 to keep it within the confines of a word. There are also some clever tricks to keep the intermediate value (seed*A) down to a reasonable value. As I said, see Knuth because he has an amazing amount of data on the subject. The advantage of using a linear congruential generator is that it is so utterly simple to implement, and that it takes almost no memory (just 1 or 2 words) and very little code. There are ways of mixing multiple linear congruential generators to make them even more random (again, see Knuth) if they are carefully chosen. Most LGC's have patterns. There are definitely good ones and bad ones out there. Fortunately since you have timing data available from a true random source (the player), you can probably blend in hashes of timing data from the player to create additional seed data and thus destroy any potential patterns generated by a linear congruential generator. This gets over into the subject of randomness harvesting and cryptographically secure random number generators, so happy hunting on a seemingly simple but fascinating topic.

Share this post


Link to post
Share on other sites
I have no idea how to load these numbers. If I open N7, it lists about 100 numbers (all zeroes). Do I just manually plug in random numbers for each? I notice that you have the destination #N7:10. Does the # make it a rolling number so that it goes to N7:11 then N7:12...? I also need to choose a random mole (I have 5 moles). Would it be useful for me to pull a number from N7 (that is 1 to 5), compare that number to identify the mole number, then take the next value on N7 for the timer? A number 1-5 with a time base of 0.2 seconds would give me satisfactory results. It would be random enough... would this work?

Share this post


Link to post
Share on other sites
Th U:6 is a reference to Subroutine 6. The command is a Jump to SubRoutine. The subroutine operates on N7:0. The first part, a Bit Shift Right requires the file sign (#) even though we are jsut working on one N register the instruction could operate on many more bits. The second rung performs the XOR portion of the feedback as mentioned in the link I provided. Thus each call to the subroutine (each time the timer times out - the timer isn't necessary, it's just a way of demonstrating changing random numbers) a new number is generated in N7:0. The third rung clears the enable so that the shift happens on each call to the subroutine.

Share this post


Link to post
Share on other sites
I got this working. The following is the program and a screen shot of it. I filled the N7 table with the numbers 20, 40, 60, 80, and 100. With a time base of 0.01 seconds, that gives times between 0.2 and 1 seconds. Values are tested for equality to select a mole: 20 = mole 1, 40 = mole 2,..., 100 = mole 5. Anyways, I have a few questions because I have to write a report and I need to sound like I know what I'm talking about. 1. What's up with the mask on the SQO? I'm not sure what that is/does and what OFFFFh means. 2. What is the R6 (controller) and what is it used for? 3. What should I do to make the mole turn off once hit? I tried putting the "examine open" switch in the middle of rung 4, but it just paused the timer. I added rung 3 to finish the timer, but it didn't help. Any advice? Should I delete rung 3 or the examine open? 4. There are no pauses between moles, but I'm not sure the instructor has ever seen a Wac-O-Mole machine before... and no one else has ever completed a project on this scale for him before. However, do you guys have any easy-to-implement ideas? If not, it probably wont affect my grade anyways. Thanks, Mike WAC.RSS

Share this post


Link to post
Share on other sites
You could double the length of your sequencer and put values in every other step that don't trigger any moles... Edited by OkiePC

Share this post


Link to post
Share on other sites
If all the above does not help, feel free to come to my backyard and whac all the moles you see. You'll receive a big prize if you get them all. Z

Share this post


Link to post
Share on other sites
Feed them juicy fruit gum. http://www.forces-of-nature.net/topics/mol...y_Fruit_Gum.htm Edited by Mickey

Share this post


Link to post
Share on other sites
Interesting idea on how to treat moles. But I have come across a more satisfying solution. I got a pack on inline mole traps. Strong spring action pinches the moles in half almost. Then I have the satisfaction of checking the trap and pulling it out with a dead mole in its jaws. I just got the traps last week and have killed two moles already. The hard part is just determining the active tunnels. The fun part is knowing the mole is going to die in a manner that Jigsaw himself would be envious. Z

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0