# Random?

Is there a way to make your robot use an action at random?
Just wondering…

THere is no such thing as random in coding and computers. Everything on computers is based off of mathematical equations and numbers. So in short, no, you cannot make your robot execute a random task.

Technic-R-C

The simplest way to generate random events for your robot is to use a random number generator algorithm to generate the motor commands and have it move randomly. The random number generator algorithm can be coded in Microchip C. Many examples of random number generators can be found on the web or in numerical methods books such as “Numerical Recipes in C” found on Amazon.

Yes, but … At the precision with which unaided humans are able to measure such things, it is quite easy to create a set of fully deterministic instructions (in the sense you describe) that will make a machine behave in ways that are indistinguishable from truly random actions. Hence the old joke about repeatedly covering half the distance to someone you would enjoy kissing. Don’t give up because you will never reach them; instead just get close enough for something useful to happen.

Yes, but … I’ll bet that simply starting a timer and reading it to obtain a (pseudo)random number (maybe keep the last two, three or four digits of the value that is returned); and then repeatedly reading that same timer or another (while your program goes about its other business) until you happen to get a match with that the digits you kept from that first number, will be an adequate and simple way to introduce (pseudo)random timing into a machine’s actions. The same basic concept can be modified to create the appearance of randomly choosing an action to perform.

For the timer approach to work really well, there needs to be something just a little unpredictable going on between successive reads of the timer. Almost any interaction with the “real world” will suffice. The unpredictable nature (again from the perspective of unaided humans) of the interaction between the Vextroller’s master and user CPUs will probably introduce enough (pseudo)randomness to do the trick; but if you can throw in some external real world event; then you should be doubly OK. Examples are waiting for something to hit a limit switch; waiting for a shaft encoder count to reach a certain value; waiting for a light sensor’s readout to change by one count, etc.

On the other hand, studying the algorithms TSwift referred us to can lead to an entire career in a fascinating field of mathematics…

Blake

If you look at it like above then technically “random” does not exist, rolling a dice, it all depends on momentum, angles, velocity, gravity, surface, etc…

I would try and make a function that outputs a number or string based on previous variables. Every time the robot makes an action save it in a variable, based on something. Say, if the light sensor gives a value of 50 add it to variable x, then if you press a button on the joystick add a value of 3 on variable b

then take all the variables and make a formula, then in the function return a number based on the formula i.e.
randomnum = a ^ 7(b) + c / d + 4 - (e - 2) ^ 2

the randomnum would keep changing as the variables change, to make it even more random add if commands that change the formula based on other variables

or you can choose a seed (a number of your choice or base it of a variable) and then use a sigle variable that generates a number based on the seed

(might be a better option, less code)

I like the light sensor idea… Better yet, with a floor and the Line Follower, you should get a variance even with a constant floor color, because of variation in Light Sources and Reflections.

Thank you for your ideas! I got an idea from the light sensor idea… I don’t know if it will work yet, but i was thinking that i could add up the value of every sensor on my robot and store the data with a variable. Depending on the value of the variable, the robot will perform a different action. I can add on light sensors, ultrasonic range finders, a compass sensor and on and on…
It will be very hard to get the same exact number twice.

What do you guys think?

Tha approach can work well, and it can be easy to adjust if you need to tweak it. Go for it!

You should learn a lot as you implement the first version and then refine it over time. Have fun.

Blake

sounds good, tell us how it goes!

I haven’t started working on it yet because i am waiting for my graduation money so i can buy the sensors. Here is a plan:

ultrasonic sensor value/85= variable ul.
light sensor value/85=variable ls.
line tracker (x3) value/127.5=lt.
shaft encoder?=se
potentiometer?=p(not sure if max value is 255 for potentiometer and shaft encoder)
gyro sensor?=gs
compass sensor?=cs
and
accelerometer?=a(these did not come out yet for vex yet)
bumper and limit =bl

/=division

ul+is+it+se+p+gs+cs+bl=mv(master variable)
And i’ll have a bunch of “if” statements for mv

example:
if mv<22 and>20 then move forward an inch

Sorry, i don’t know the format for all sensors.
what do you guys think?
i might be able to improve it:D

the gyro and compass also didn’t come out for vex.

it will be a longggg program to encompass all possible numbers, even with divisions

when you get sensors, try to print the max value possible from them and figure out what to divide by to get it into your programmed range.

anyways, good setup/plan

I’m graduating from 5th grade. I got my graduation money(\$100) today and i’m going to find out what sensors i want to buy.

…And i thought vex said they were making a gyro sensor…

/basicxman faints

lol

they are making a gyro sensor but have not posted a release date yet

Congratulations! (on both the graduation, and the windfall )

They announced it earlier this year, but it hasn’t shipped yet. Here is the FAQ, where they list it as “available soon”

Keep in mind that you may need to buy new software to use it. When the quadrature shaft encoders first shipped, you needed MPLAB (maybe RobotC?) to fully use them. Apparently, EasyC Pro now supports them too, but that isn’t a free upgrade.

As far as I can tell, there have been very few details about the new sensors and how they will be integrated into the system. If anybody has any further details, please post!

Cheers,

• Dean

Not to brag or get off topic, but I have an accelerometer. Accelerometers and gyroscopes are pretty similar. My fully VEX compatible accelerometer, was very easy to make (thanks to the help of Quazar) and it works very well. I have found that you can use them in almost any robot. The accelerometer only cost about 25 dollars to make. And to program it is very easy, all you need is EasyC. If you want to make one, just ask.

isn’t the thing itself \$30

1.Is Easy-C Pro harder to program?
and