Main Method won't run
The main method is completely skipped when it hits the first for statement. I have tried to debug it and it just skips to the end. I get bizarre Error and debug messages like: Error IDE-0010 Error Communicating over the serial port (corrupt packet $00);
[noparse][[/noparse]Debug] Discarding packet (<-- I get this one multiple times.); [noparse][[/noparse]Debug] Unknown message from Javelin.
This is the main method. The whole thing compiles fine. I need to figure this out ASAP. So please don't hesitate to help. I am running the latest IDE from parallax and I'm using a Serial port on my windows XP PC.
Post Edited (Gibith) : 2/5/2008 5:30:32 AM GMT
[noparse][[/noparse]Debug] Discarding packet (<-- I get this one multiple times.); [noparse][[/noparse]Debug] Unknown message from Javelin.
public static void main(){
Rover a = new Rover(2);
ChromoAmount = DNA.length;
Timer min = new Timer();
min.mark();
System.out.println("Program RUnning");
for(int i = 0; i > 10; i ++){
a.DNA = new String[noparse][[/noparse]15];
for( i = 0; i < DNA.length; i ++){
if (DNA[i] == null){
continue;
}
if (DNA[i] == StartServosEx){
a.StartServos();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == StopLeftEx){
a.StopLeft();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == StopRightEx){
a.StopRight();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == ChangeRightEx){
a.ChangeRight();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == ChangeLeftEx){
a.ChangeLeft();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == DelayEx){
a.Delay();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == RandomizeRightEx){
a.RandomizeRight();
if (CheckTime(min)){
break;
}
else continue;
}
if (DNA[i] == RandomizeLeftEx){
a.RandomizeLeft();
if (CheckTime(min)){
break;
}
else continue;
}
} /* End of for loop */
if (RightUsed == true){
RightUsed = false;
PWM11 = InPWM11;
}
else if (LeftUsed == true){
LeftUsed = false;
PWM22 = InPWM22;
}
else{
System.out.println("Else!");
}
System.out.println("Pre Mutation");
a.MutationMarker(a);
a.Mutate(a);
lstDNA = a.DNA;
GenerationPop.add(lstDNA);
System.out.println("Post Mutation");
while(true)
{
switch(Terminal.getChar()){
case 'c':
System.out.println(begin);
for(int k = 0; k < GenerationPop.size(); k ++){
for(int j = 0; j < ((String [noparse][[/noparse]])GenerationPop.get(k)).length; j++){
System.out.println(((String [noparse][[/noparse]])GenerationPop.get(k))[noparse][[/noparse]j]);[/i][/i][/i][/i][/i][/i][/i][/i][/i]
This is the main method. The whole thing compiles fine. I need to figure this out ASAP. So please don't hesitate to help. I am running the latest IDE from parallax and I'm using a Serial port on my windows XP PC.
Post Edited (Gibith) : 2/5/2008 5:30:32 AM GMT

Comments
can load it into the IDE to figure out what happens.
regards peter
import stamp.core.*; //import stamp.core.PWM; //import stamp.core.Timer; import java.util.*; import stamp.util.*; public class RetardRover{ public static int MutMarker [noparse][[/noparse]]; public static List GenerationPop = new List(10); public static String [noparse][[/noparse]] lstDNA; public static String [noparse][[/noparse]] DNA; public static Random rDelay = new Random(17); public static Random rPWM11 = new Random(4); public static Random rPWM22 = new Random(16); public static int rate; public static int ChromoAmount; public static int PWM11 = 173; public static int PWM22 = 173; public static String Possible [noparse][[/noparse]] = new String[noparse][[/noparse]7]; public static int DelayTime; public static PWM Right = new PWM(CPU.pin12, 173, 2304); public static PWM Left = new PWM(CPU.pin13, 173, 2304); public static String StartServosEx = "StartServos"; public static String StopLeftEx = "StopLeft"; public static String StopRightEx = "StopRight"; public static String ChangeRightEx = "ChangeRight"; public static String ChangeLeftEx = "ChangeLeft"; public static String DelayEx = "Delay"; public static String RandomizeRightEx = "RandomizeRight"; public static String RandomizeLeftEx = "RandomizeLeft"; public static boolean OutoTime = false; public static final int TimeLimit = 360; /* This could be a value that I would want to add into the constructor */ public static boolean RightUsed = false; public static boolean LeftUsed = false; public static int InPWM11; public static int InPWM22; public static String begin = "Begin"; public static String end = "End"; public RetardRover(int MutationRate){ rate = MutationRate; } public static void main(){ RetardRover a = new RetardRover(2); ChromoAmount = DNA.length; Timer min = new Timer(); min.mark(); System.out.println("Program RUnning"); for(int i = 0; i > 10; i ++){ a.DNA = new String[noparse][[/noparse]15]; for( i = 0; i < DNA.length; i ++){ if (DNA[i] == null){ continue; } if (DNA[i] == StartServosEx){ a.StartServos(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == StopLeftEx){ a.StopLeft(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == StopRightEx){ a.StopRight(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == ChangeRightEx){ a.ChangeRight(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == ChangeLeftEx){ a.ChangeLeft(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == DelayEx){ a.Delay(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == RandomizeRightEx){ a.RandomizeRight(); if (CheckTime(min)){ break; } else continue; } if (DNA[i] == RandomizeLeftEx){ a.RandomizeLeft(); if (CheckTime(min)){ break; } else continue; } } /* End of for loop */ if (RightUsed == true){ RightUsed = false; PWM11 = InPWM11; } else if (LeftUsed == true){ LeftUsed = false; PWM22 = InPWM22; } else{ System.out.println("Else!"); } System.out.println("Pre Mutation"); a.MutationMarker(a); a.Mutate(a); lstDNA = a.DNA; GenerationPop.add(lstDNA); System.out.println("Shet sum Mewtant!"); while(true) { switch(Terminal.getChar()){ case 'c': System.out.println(begin); for(int k = 0; k < GenerationPop.size(); k ++){ for(int j = 0; j < ((String [noparse][[/noparse]])GenerationPop.get(k)).length; j++){ System.out.println(((String [noparse][[/noparse]])GenerationPop.get(k))[noparse][[/noparse]j]); } } } } }/* End of for loop */ }/* End of main method */ public static boolean CheckTime(Timer TimerName){ if (TimerName.timeoutSec(TimeLimit)); /*Check to see if 1 minute has passed*/ return OutoTime = true; } //public static void LIVE(RobotRetard){ //System.out.println("sup");/* Put DNA Strand Together */ //} public static String StartServos(){ Right.start(); Left.start(); return StartServosEx; } public static String StopLeft(){ Left.update(173, 2304); return StopLeftEx; } public static String StopRight(){ Right.update(173, 2304); return StopRightEx; } public static String ChangeRight(){ Right.update(PWM11, 2304); return ChangeRightEx; } public static String ChangeLeft(){ Left.update(PWM22, 2304); return ChangeLeftEx; } public static String Delay(){ CPU.delay(DelayTime); return DelayEx; } public static String RandomizeRight(){ InPWM11 = PWM11; PWM11 = ((rPWM11.next() % 130)+110); RightUsed = true; return RandomizeRightEx; } public static String RandomizeLeft(){ InPWM22 = PWM22; PWM22 = ((rPWM22.next() % 130)+110); LeftUsed = true; return RandomizeLeftEx; } public static void BuildLists(RetardRover a){ Possible[noparse][[/noparse]0] = StartServosEx; Possible = StopLeftEx; Possible = StopRightEx; Possible = ChangeRightEx; Possible = ChangeLeftEx; Possible = DelayEx; Possible[noparse][[/noparse]6] = RandomizeRightEx; Possible[noparse][[/noparse]7] = RandomizeLeftEx; } public static void MutationMarker(RetardRover a){ Random RandRate = new Random(144); ChromoAmount = DNA.length; int MutMarker [noparse][[/noparse]]= new int[noparse][[/noparse]ChromoAmount]; /* Make MutMarker as long as the number of chromosomes a 1 signifies a mutation*/ for(int i = 0; i < ChromoAmount; i ++){ /* iterate through MutMarker*/ if((RandRate.next() % rate) == rate){ /* if a mutation occurs on a specific chromosome */ MutMarker [i] = 1; /* mark that chromosome */ Random coinFlip = new Random(23); int MutType = ((coinFlip.next() % 2) + 1); if (MutType == 1){ } /* End if statement */ } /* End if statement */ } /* End for loop */ } public static void Mutate (RetardRover a){ Random coinFlip = new Random(23); Random RandPoss = new Random(42); Random MutRight = new Random(99); Random MutLeft = new Random(91); int MutChromoType; int MutType = ((coinFlip.next() % 2) + 1); /*is it a point mutation or chromosome mutation? */ if (MutType == 1){ /*if it is a chromosome Mutation */ MutChromoType = ((coinFlip.next() % 2) +1); /* what type of chromosome mutation is it? */ if (MutChromoType == 1){ /* If it is a insertion Chromsome Mutation */ a.DNA[noparse][[/noparse]-1]=(Possible[noparse][[/noparse](((RandPoss.next() % 7) + 1))]); /* Add a random Chromosome */ } else if (MutChromoType == 2){ /* if it is a chromosome deletion */ a.DNA[noparse][[/noparse]((RandPoss.next() % ChromoAmount) + 1)] = null; } /* end else if */ } /* end if */ if (MutType == 2){ for(int i = 0; i >= MutMarker.length; i ++){ if (MutMarker[i] == 1){ if (DNA[i] == null){ continue; } if (DNA[i] == DelayEx){ DelayTime = rDelay.next(); } if (DNA[i] == ChangeRightEx){ PWM11 = ((MutRight.next() % 130) + 110); } if (DNA[i] == ChangeLeftEx){ PWM22 = ((MutLeft.next() % 130) + 110); } } } } } } /*End of class */[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]There are also some inside jokes pretaining to some of the System.out.println lines. These are just to test if a piece of code has executed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
From what I see, you declare a class RetardRover, that has a constructor,
and it has a static void main() method, and from main() you create
RetardRover instances. Maybe that works on the PC (and the compiler allows
it because it is a PC compiler), but it is bad programming.
Put the method main() into its own class, say RetardRover_test,
and import the RetardRover class. That also has the benefit
that you can reuse the RetardRover class in other projects.
regards peter
C:\Program Files\Parallax Inc\Javelin Stamp IDE\lib;C:\Program Files\Parallax Inc\Javelin Stamp IDE\Projects
import gene.*;
If that doesn't work, move your gene folder to
...\lib\stamp
and use
import stamp.gene.*;
regards peter
I thought all you had to do was delcare something public and when you imported it you could manipulate it directly.
Post Edited (Gibith) : 2/5/2008 5:01:25 PM GMT
//file RetardRover.java
package stamp.gene;
import stamp.core.*;
public class RetardRover {
· //your class code
}
Save the file RetardRover.java in folder ...\lib\stamp\gene
//file RetardRover_test.java
import stamp.core.*;
import stamp.gene.*
public class RetardRover_test {
· //your class code here (remember to use static for variables)
· static void main() {
··· //your main method
· }
}
Save the file RetardRover_test.java either in folder Projects or folder ...\lib\stamp\gene
When you program the javelin, make sure you have this file active (on top)
regards peter
for(int i = 0; i < 10; i++){code}I wrote it like this:
for(int i = 0; i < 10; i++){code}But I have more issues pertaining to this program. I will post them soon.
Thanks,
Gibith
Nevermind I fixed that problem however I have a new one. I keep getting index out of bounds error but i don't understand why it's out of bounds. I appears to be in bounds.
Post Edited (Gibith) : 2/6/2008 3:50:36 AM GMT
and both files compile now without error.
You need to check them for possible logical errors.
I also think you need to think about how to setup this particular project,
as it seems to me that RetardRover could be split in several more logical units.
regards peter
I keep getting index out of bounds error but i don't understand why it's out of bounds. It appears to be in bounds.
Post Edited (Gibith) : 2/6/2008 4:06:23 AM GMT
If you take it from there you will have less issues.
An index out of bounds exception·means you are indexing an array
beyond its limits, for example if you declare
· int[noparse]/noparse p = new int[noparse][[/noparse]5];
you can only use p[noparse][[/noparse]0] to p[noparse][[/noparse]4]
Using p[noparse][[/noparse]5] will generate an index out of bounds exception.
regards peter
How can I randomize the seed values? I thought that maybe I could use some external stimulus. At this point I want something that works and something I can quickly incorporate into my code.
Thanks,
Gibith
Then the blocks will get different random values.
regards peter