Can use SERIN to read PIN 2 of Javelin Stamp?
StereoPonyz
Posts: 82
I am using localizer - stargazer hagisonic on the robot to detect its location. It was programmed using Bs2sx stamp previously and the command used was:
SERIN 2,16624,[noparse][[/noparse]WAIT ("~^I"),SDEC storeangle,WAIT("|"), SDEC BB3x,WAIT ("|") ,SDEC BB3y]
where SERIN 2, 16624, means to receive input thru pin 2 of Bs2sx and '16624' means 9600 baud rate. while SDEC means to retreive negative decimal.
I would like to know if to use Javelin Stamp can i use the same command? I search through the manual and knew that Javelin Stamp suport SERIN command, however, what command can i use for SDEC? Also, if the same pin can be used for reading?
SERIN 2,16624,[noparse][[/noparse]WAIT ("~^I"),SDEC storeangle,WAIT("|"), SDEC BB3x,WAIT ("|") ,SDEC BB3y]
where SERIN 2, 16624, means to receive input thru pin 2 of Bs2sx and '16624' means 9600 baud rate. while SDEC means to retreive negative decimal.
I would like to know if to use Javelin Stamp can i use the same command? I search through the manual and knew that Javelin Stamp suport SERIN command, however, what command can i use for SDEC? Also, if the same pin can be used for reading?
Comments
means pin P2 (not physical pin2 which is SIN, which would use SERIN 16,...)
On the javelin you therefor just use an Uart.
Uart myUart = new Uart(Uart.dirReceive,CPU.pin2,Uart.dontInvert,Uart.speed9600,Uart.stop1);
while (true) { //wait for "~^I"
· do {
··· int c = myUart.receiveByte();
· while (c != '~');
··c = myUart.receiveByte();
· if (c != '^') continue;
··c = myUart.receiveByte();
· if (c == 'I') break;
}
You can expand on this to mimic the BS line.
Or use·a generic wait method
void wait(Uart rx, String toWaitFor) {
· int index = 0;
· while (index < toWaitFor.length) {
····int c = rx.receiveByte();
··· if·(c != toWaitFor.charAt(index)) {
····· index= 0;
····· if (c == toWaitFor.charAt(0)) index=1; //for example wait for "~^I" but receive "~~^I"
····· continue;
··· }
··· index++;
· }
}
This is not quite working. It would fail if you wait for "~~^I" but receive "~~~^I"
but you get the idea.
regards peter
import stamp.core.*;
public class Stargazer {
static Uart myUart = new Uart(Uart.dirReceive,CPU.pin2,Uart.dontInvert,Uart.speed9600,Uart.stop1);
static int a;
static String b = "";
public static void main() {
for (int i = 0; i < 11; i++)
{
a = myUart.receiveByte();
System.out.println(a);
if(a == '+' || a == '-')
{
a = myUart.receiveByte();
b = b + Integer.toString(a);
System.out.println(b);
} // end of if
} // end of for loop
} // end of main()
}
I realised that the results can only print one time and i have to restart the boe-bot to detect the next coordinate. Besides that, restarting the boe-bot too early, the results will show all zeroes, i need to wait for a few seconds before i can get the whole data. Is it cos, the UART cannot read continously?
Post Edited (StereoPonyz) : 12/31/2009 10:32:49 AM GMT
This will print continuesly the received bytes as hexadecimal values.
regards peter
I flipped through the javelin manual and found some information on PWN stating that
"PWM will accept values from 0 to 65535. The Javelin's int field can hold values from -32768 to 32767. To enter PWN values abv 32767 use the following maps"
is this the map i need to look at to see what are exactly are the hexadecimal values are?
The localizer will output the data in the format circle in red. Actually i require only the X and Y coordinates, but the results produced by the Javelin is so different, since i am using UART class that will only accept Integer. Thus, i am unable to tell which is the starting integer and which is the ending ones.
Can i know if there is way to output the data in the Stargazer format --> ~^I+150.23|-33.12|+12.00|64` which means ( ~^I : Map Mode, +150.23:Angle, -33.12:X, +12,00:Y, 64 : IDNumber )
Change the line
a = myUart.receiveByte();
into
a = myUart.receiveByte() & 255;
regards peter
regards peter
regards peter
What you get per line are 16 hexvalues and 16 characters (readable text) of those values.
Unprintable values (0-31, 127-255) are replaced by dots.
regards peter
http://www.robotshop.ca/content/PDF/StarGazer_User_Manual_Ver_04_080417%28English%29.pdf
the stargazer communicates at baudrate 115200, which is not supported by the javelin.
You could try a Propeller SpinStamp which has identical 24pins footprint.
regards peter
The stargazer can only output from a range of values from -180 to 180. What can i do to extract the values, since (0-31, 127-255) are unprintable?
Try using invert mode
· static Uart myUart = new Uart(Uart.dirReceive,CPU.pin2,Uart.invert,Uart.speed9600,Uart.stop1);
and see if that generates more readable output
The stargazor outputs TTL levels 0-3.3V which is ok for the javelin
regards peter
When using the StarGazerMonitor software, the measurement output has a constant +/- 1.something changes. Could this be the reason why there are many hexadecimal?
I noticed that, the results does not always produce the 6 information (Map, IDNum, Angle, X, Y, Height)
~^I16|+81.35|-17.53|-25.59|231.09' --> (~^I:Map 16:ID Num | +81.35:Angle | -17.53:X | -25.59:Y| 231.09:Height')
There is Only ONE set of data (highlighted in organge) which consists of the right information and in the right format. So, it means i will only have one set of data for feedback usage?
Post Edited (StereoPonyz) : 1/5/2010 4:05:32 PM GMT
regards peter
Thank you once again....
· static int buf[noparse]/noparse = new int[noparse][[/noparse]16];
into
· static char buf[noparse]/noparse = new char[noparse][[/noparse]16];
regards peter
I have added in extra codes to output X, Y using the same codes as in case 3, while Height output use the same codes as in case 5. Is it that i need to change the if condition
May I know, the IF CONDITION in case 7 codes is to prevent OutofMemory Exception error? i had tried without that IF CONDITION and used the same codes like in CASE 3 to 6, it resulted OutofMemory Exception.
import stamp.core.*;
import stamp.util.text.*;
public class StargazerFinal {
static Uart myUart = new Uart(Uart.dirReceive,CPU.pin2,Uart.invert,Uart.speed9600,Uart.stop1);
static int a,i;
static char buf[noparse]/noparse = new char[noparse][[/noparse]16];
static int state = 0;
static int index = 0;
static int value[noparse]/noparse = new int;
static int MapID, Angle, Boebot3x, Boebot3y, Height;
static void main() {
i = 0;
while (true) {
switch (state) {
case 0: //wait for ~
a = myUart.receiveByte() & 255;
if (a == '~') state = 1;
break;
case 1: //wait for ^
a = myUart.receiveByte() & 255;
if (a == '^') state = 2;
else state = 0;
break;
case 2: //wait for I
a = myUart.receiveByte() & 255;
if (a == 'I') {
index = 0;
state = 3;
}
else state = 0;
break;
case 3: //wait for |, storing +,-, Landmark Map ID
a = myUart.receiveByte() & 255;
if (a != '|') buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
MapID = value[noparse][[/noparse]0];
Format.printf("Landmark Map ID = %d :", MapID);
index = 0;
state = 4;
}
break;
case 4: //wait for |, storing +,-,Angle
a = myUart.receiveByte() & 255;
if (a != '|') buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
Angle = value[noparse][[/noparse]0];
Format.printf("Angle = %d :",Angle);
index = 0;
state = 5;
}
break;
case 5: //wait for |, storing +,-,X-Coordinates
a = myUart.receiveByte() & 255;
if (a != '|') buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
Boebot3x = value[noparse][[/noparse]0];
Format.printf("Boebot3x = %d :",Boebot3x);
index = 0;
state = 6;
}
break;
case 6: //wait for |, storing +,-,Y-Coordinates
a = myUart.receiveByte() & 255;
if (a != '|') buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
Boebot3y = value[noparse][[/noparse]0];
Format.printf("Boebot3y = %d :",Boebot3y);
index = 0;
state = 7;
}
break;
/* case 7: //wait for |, storing +,-,Height
a = myUart.receiveByte() & 255;
if (a != '|') buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
Height = value[noparse][[/noparse]0];
Format.printf("Height = %d :",Height);
index = 0;
state = 0;
}
break;
*/
case 7: //storing +,-,Height
a = myUart.receiveByte() & 255;
if ((a == '-') || (a == '+') || ((a >= '0') && (a <= '9'))) buf[noparse][[/noparse]index++] = (char)a;
else {
buf[noparse][[/noparse]index] = 0;
Format.sscanf(buf,"%d",value); //convert signed number in buf to binary value
Height = value[noparse][[/noparse]0];
Format.printf("Height = %d\n",Height);
index = 0;
state = 0;
}
break;
}
}
}
}
Storing stops at any other character.
Note that in the other cases there is a simple test for not | ,assuming
there will only·be -,+ or digits before |
That may however be not the case. You really should study the protocol
description·in the manual and create a decode routine that catches all
possible outputs.
The code·you have now contains all the logic·you·need to implement
such a decode routine.
regards peter
regards peter
Post Edited (Peter Verkaik) : 1/8/2010 3:02:12 PM GMT
~^I16|+84.89|-26.51|-47.19|181.79`
which is different from chapter of the manual I found
· 10a . New format of Received Data · The format of data received from StarGazer for the command ~#CalcStart` are as follows:
········ F
·· ~ ^ I iiii | ±aaaa.aa | ±xxxx.xx | ±yyyy.yy | zzzz.zz `
········ Z
·· ^· Means the result data
·· F· Indicates the Map-Building Mode
·· I Indicates the Map Mode
·· Z Indicates the Height Calculation Mode
·· iiii The number of an ID
·· ±aaaa.aa Value of Angle (degrees; -180~+180)
·· ±xxxx.xx Position on X axis (cm)
·· ±yyyy.yy Position on Y axis (cm)
·· zzzz.zz Last value (what parameter??)
It looks iiii now follows mode letter
Try this
[/code][/size]
Now you should get identical lines for receive and recreate
regards peter
10a . New format of Received Data
The format of data received from StarGazer for the command ~#CalcStart` are as follows:
F
~ ^ I iiii | ±aaaa.aa | ±xxxx.xx | ±yyyy.yy | zzzz.zz `
Z
^ Means the result data
F Indicates the Map-Building Mode
I Indicates the Map Mode
Z Indicates the Height Calculation Mode
iiii The number of an ID
±aaaa.aa Value of Angle (degrees; -180~+180)
±xxxx.xx Position on X axis (cm)
±yyyy.yy Position on Y axis (cm)
zzzz.zz Last value (what parameter??)
zzzz.zz --> was the height parameter.
In my case, i configure the localizer to be Map Mode, so it indicates a "I"
The output is in this sequence: ~^MapMode IDNum | Angle | X | Y | Height ` (~^I16|+84.89|-26.51|-47.19|181.79`)
Thank You Very Much for your help. I have attached the output using your latest codes. The localizer got this weird prob of giving a wrong output after every few correct ones.
Post Edited (StereoPonyz) : 1/11/2010 2:57:51 PM GMT
You can add a check for proper message
regards peter
it will: turn Clockwise till it meet the condition (89<angle<91) --> move straight --> (if angle>91) --> turn anti-Clockwise --> move straight.
I would like my robot to move within the angle and so if it is greater den 91, turn anti-clockwise to lesser than 91 before moving off again.
However, my robot output is: Turn clockwise -> meet cond (89<angle<91) -> go straight -> angle>91 -> STILL Clockwise.
I am not sure where got have gone wrong, whether it is my placement of subroutine or even the codes itself. I tried placing my Anticlockwise at other places too but din work.
The attachments are the flow of the terminal output, start from movement 1 --> movement 2
static void moveStraight() {
System.out.println("move straight");
pwmR.update ( 171, 2304 ) ; //A-CW < 173 < CW
pwmL.update ( 175, 2304 ) ; //move Straight
pwmR.start () ;
pwmL.start () ;
CPU.delay(100);
pwmR.stop () ;
pwmL.stop () ;
if (angle/100 > 91) turnAntiClockwise ();
}
static void turnClockwise() {
System.out.println("turnClockwise");
pwmR.update ( 175, 2304 ) ; //A-CW < 173 < CW
pwmL.update ( 175, 2304 ) ; //turn CW
pwmR.start () ;
pwmL.start () ;
CPU.delay(100);
pwmR.stop () ;
pwmL.stop () ;
}
static void turnAntiClockwise() {
System.out.println("turnAntiClockwise");
pwmR.update ( 171, 2304 ) ; //A-CW < 173 < CW
pwmL.update ( 171, 2304 ) ; //turn CW
pwmR.start () ;
pwmL.start () ;
CPU.delay(100);
pwmR.stop () ;
pwmL.stop () ;
}
static void main() {
Format.printf("StarGazer test program\n");
Format.printf("~^MapMode IDNum | Angle | X | Y | Height `");
while (true) {
response(); //get a full response, extract values and print response
//recreate response output from extracted values, should be identical to response
if ((angle/100 >= 89) && (angle/100 <= 91)) {
System.out.println ("Correct Angle");
moveStraight();
}
else {
System.out.println ("Turn Robot");
turnClockwise();
}
Format.printf("\nRecreate: ~^");
Format.printf("%c",(char)mode);
Format.printf("%d|",id);
if (angle >= 0) Format.printf("+");
Format.printf("%d.",angle/100);
Format.printf("%02d|",abs(angle)%100);
if (xpos >= 0) Format.printf("+");
Format.printf("%d.",xpos/100);
Format.printf("%02d|",abs(xpos)%100);
if (ypos >= 0) Format.printf("+");
Format.printf("%d.",ypos/100);
Format.printf("%02d|",abs(ypos)%100);
//if (LastValue >= 0) Format.printf("+");
Format.printf("%d.",height/100);
Format.printf("%02d`\n",abs(height)%100);
}
}
}