Bots and Simulations > DNA - General
Multibot movement ideas
rayz:
Please forgive me if I'm being redundant and rambling. I can be that way.
I was thinking about how to move a large multibot. I was thinking that one of the major problems in moving a large multibot is the difficulty in making each individual bot face the same direction... so I was trying to create an algorithm to make each individual bot move the same direction, no matter what the heading of the bot is at the time. So this is my small mini-algorithm:
sine and cosine take the top value from the stack, and give back the sine and cosine values for that number (in Darwinbot units).
heading is a variable that is passed along ties-- it shows what heading the bots want to move in.
magnitude is a variable that is passed along ties-- it shows how fast the bot wants to move in the particular direction.
--- Code: ---cond
start
heading *.angle sub cosine magnitude mult .up store
heading *.angle sub sine magnitude mult .dx store
stop
--- End code ---
If this worked, then the heading could be determined by some sort of queen, and passed along to each bot using ties-- so each bot would move in the same direction, preventing the need for more complicated algorithms to deal with other suff.
It wasn't until I tried to implement this that I realized that the sine and cosine functions don't exist! I then started thinking that a sine and function would be so nice to have... Does anyone know if a sine and cosine function exist? If so, what are they? If not, how should I mimic them?
Thankee all!
-rayz
ikke:
Three solutions:
use sine cosine and implement through polynominal approximation
use angle / pyth (pythagoras) and the formulas to calculate sine and cosine
vector decomposition have two parameters x and y to pass, and not heading and magnitude
rayz:
--- Quote from: ikke ---Three solutions:
use sine cosine and implement through polynominal approximation
use angle / pyth (pythagoras) and the formulas to calculate sine and cosine
vector decomposition have two parameters x and y to pass, and not heading and magnitude
--- End quote ---
How would you recommend implementing them?
Also, heading and magnitude are an easy way for the bot to move relative to its own heading--thus, there is less manipulation of variables, making it more efficient.
Thankee!
-rayz
ikke:
--- Quote from: rayz ---Also, heading and magnitude are an easy way for the bot to move relative to its own heading--thus, there is less manipulation of variables, making it more efficient.
-rayz
--- End quote ---
Efficient is a very relative term and highly dependant on what you want to achieve (and what you already have). There is more than one way to skin a cat. Using angle and speed is only efficient in some respects. Try programming a snake like mb to move around a corner with angle and speed. Using waypoints would probably be easier there.
If you elaborate on what you want to do specifically we could be of more help than by giving you the general math and physics class.
rayz:
Got it!
It's not a multibot yet, but it can direct its heading according to the value stored in aimheading no matter what direction it is facing. Because it uses an approximation, it's not perfect. Uses Taylor series to calculate sine.
--- Code: ---'An attempt to make the bot move north no matter how it is turned.
'Lacks precision due to a integer-only stack.
'Attempt to correct that by waiting to divide bigs numbers till end.
'edit these to wherever--maybe pi should be epigenetic?
def sineIn 50
def sineOut 51
def pi 52
def factor 53
def aimHeading 410
def magnitude 54
'set constants
cond
*.robage 1 =
start
31415 .pi store
10000 .factor store
100 .magnitude store
628 .aimHeading store
stop
cond
start
*.aim 10 add .setaim store
*.aimHeading 10 add .aimHeading store
*.aimHeading *.aim sub .sineIn store
stop
cond
*.sineIn 0 <
start
*.sineIn 1256 add .sineIn store
stop
cond
*.sineIn 1256 >
start
*.sineIn 1256 sub .sineIn store
stop
'Taylor expansion of sine function--takes value in Darwinbots units and outputs sine of that value.
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow 1 div 628 *.sineIn sub *.pi mult 628 div *.factor div 3 pow 6 div sub 628 *.sineIn sub *.pi mult 628 div *.factor div 5 pow 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7 pow 5040 div sub .sineOut store
stop
cond
start
*.sineOut *.magnitude mult .sx store
stop
cond
start
314 *.aimHeading *.aim sub sub .sineIn store
stop
cond
*.sineIn 0 <
start
*.sineIn 1256 add .sineIn store
stop
cond
*.sineIn 1256 >
start
*.sineIn 1256 sub .sineIn store
stop
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow 1 div 628 *.sineIn sub *.pi mult 628 div *.factor div 3 pow 6 div sub 628 *.sineIn sub *.pi mult 628 div *.factor div 5 pow 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7 pow 5040 div sub .sineOut store
stop
cond
start
*.sineOut *.magnitude mult .up store
stop
end
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version