Author Topic: Multibot movement ideas  (Read 5148 times)

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Multibot movement ideas
« on: January 06, 2009, 09:56:01 PM »
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: [Select]
cond
start
heading *.angle sub cosine magnitude mult .up store
heading *.angle sub sine magnitude mult .dx store
stop

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
« Last Edit: December 22, 2011, 12:06:49 PM by Shasta »

Offline ikke

  • Bot Destroyer
  • ***
  • Posts: 300
    • View Profile
Multibot movement ideas
« Reply #1 on: January 07, 2009, 02:43:47 AM »
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

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Multibot movement ideas
« Reply #2 on: January 08, 2009, 12:52:54 AM »
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

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

Offline ikke

  • Bot Destroyer
  • ***
  • Posts: 300
    • View Profile
Multibot movement ideas
« Reply #3 on: January 08, 2009, 02:42:33 AM »
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
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.

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Multibot movement ideas
« Reply #4 on: April 02, 2009, 12:13:00 AM »
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: [Select]
'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
« Last Edit: April 02, 2009, 12:15:53 AM by rayz »

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Multibot movement ideas
« Reply #5 on: April 02, 2009, 12:43:47 AM »
Just added a few small tweaks to make this a simplebot.
Forgot: Change "magnitude" to change how fast the bot will go.
sineIn and sineOut are inputs and outputs for the Taylor series
pi and factor are internal variables needed for the Taylor series
aimheading is the absolute heading (e.g. 0 for east, 314 for north, etc.) that the bot wants to go in.

Code: [Select]
'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

'try to aim the eye and shoot
cond
*.refsx *.mysx !=
*.eye5 0 !=
start
*.refxpos *.refypos angle .aimHeading store
*.aimHeading *.aim sub .eye5dir store
*.aim *.aimHeading sub .aimshoot store
-1 .shoot store
stop

cond
start
*.aim 10 add .setaim store
*.aimHeading 1 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
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

cond
*.nrg 4000 >
start
50 .repro store
stop
end
« Last Edit: April 02, 2009, 12:50:01 AM by rayz »

Offline Prsn828

  • Bot Destroyer
  • ***
  • Posts: 139
    • View Profile
Multibot movement ideas
« Reply #6 on: April 02, 2009, 10:42:58 AM »
I am happy to say this little conundrum will be solved when DB3 comes out.

DB3 will have sine (and with small math tricks, cosine as well) functions.
So, what will it be? Will you submit to my will, or must I bend reality to suit my needs?
Better answer before I do BOTH!

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Multibot movement ideas
« Reply #7 on: April 03, 2009, 12:41:04 AM »
Near-final version:

I've reduced it back to a framework, on top of which almost everything can be added.
I've also commented out a section of the code that would turn the bot to enemies, make the bot go towards them, make eye5 point to them, and direct body shots to the enemy.

Code: [Select]
'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?
'sineIn and sineOut are input/output for Taylor series
'sineOut returns a number multiplied by factor2 (approx.)
'pi and factor are internal constants for sine calculation
'aimHeading is the absolute heading that the bot wants to travel
'magnitude is how approximately how fast (in Darwinbots units) the bot will travel
'turn is how much the bot itself turns each cycle--useful to sweep area around the bot
'aimTurn is how much the bot changes the heading each cycle.
def sineIn 50
def sineOut 51
def pi 52
def factor 53
def aimHeading 410
def magnitude 54
def turn 55
def aimTurn 56
def factor2 57

'set constants
cond
*.robage 1 =
start
31415 .pi store
10000 .factor store
32000 .factor2 store
100 .magnitude store
0 .aimHeading store
*.tiepres .deltie store
35 .turn store
5 .aimTurn store
'just to move them out of the way
1221 .eye1width store
1221 .eye2width store
1221 .eye3width store
1221 .eye4width store
'1221 .eye5width store
1221 .eye6width store
1221 .eye7width store
1221 .eye8width store
1221 .eye9width store
stop

'manage body
cond
*.body 10 <
*.nrg 300 >
start
100 .strbody store
stop

cond
*.nrg 500 <
*.body 10 >
start
10 .fdbody store
stop

cond
start
*.aim *.turn add .setaim store
*.aimHeading *.aimTurn add .aimHeading store
stop

'try to aim the eye and shoot
'cond
'*.refup *.myup !=
'*.eye5 0 !=
'start
'*.refxpos *.refypos angle .aimHeading store
'*.aimHeading *.aim sub *.turn sub .eye5dir store
'*.turn *.aim add *.aimHeading sub .aimshoot store
'-6 .shoot store
'*.nrg 2 div .shootval store
'stop
'
'cond
'*.waste 100 >
'start
'-4 .shoot store
'*.waste .shootval store
'stop

'begin movement section: it makes the bot move in the direction of aimHeading
'normalize aimheading
cond
*.aimHeading 1256 >=
start
*.aimHeading 1256 sub .aimHeading store
stop

cond
*.aimHeading 0 <
start
*.aimHeading 1256 add .aimHeading store
stop

'from here down it makes the bot move in the direction of *.aimheading
cond
start
*.aimHeading *.aim sub .sineIn store
stop

'begin sineIn normalization
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
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow *.factor2 mult 1 div 628 *.sineIn sub *.pi

mult 628 div *.factor div 3 pow *.factor2 mult 6 div sub 628 *.sineIn sub *.pi mult 628 div

*.factor div 5 pow *.factor2 mult 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7

pow *.factor2 mult 5040 div sub .sineOut store
stop

cond
start
*.sineOut *.magnitude mult *.factor2 div .sx store
stop

'calculate value for .up
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

'Taylor expansion of sine function
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow *.factor2 mult 1 div 628 *.sineIn sub *.pi

mult 628 div *.factor div 3 pow *.factor2 mult 6 div sub 628 *.sineIn sub *.pi mult 628 div

*.factor div 5 pow *.factor2 mult 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7

pow *.factor2 mult 5040 div sub .sineOut store
stop

cond
start
*.sineOut *.magnitude mult *.factor2 div .up store
stop
'end movement section

cond
*.nrg 500 >
'*.body 1000 >=
start
50 .repro store
stop
end
« Last Edit: April 05, 2009, 12:31:46 AM by rayz »