Shop OBEX P1 Docs P2 Docs Learn Events
If...then...???? — Parallax Forums

If...then...????

ArchiverArchiver Posts: 46,084
edited 2001-04-24 04:12 in General Discussion
Matt-

I think you want to read the course values (integer parts) directly
into your word variables using the DEC modifier (see SERIN). Then
you can compare and do arithmetic on the values directly. I'm not
clear on how you're using an array, but I don't think you need one.

Anyway, assuming wp1 and tr1 will each have a value >= 0 and < 360,
you might do something like:

readGPS:
SERIN...[noparse][[/noparse]...,DEC wp1,...DEC tr1,...]
IF wp1 < tr1 THEN bearLeft
course_correction = wp1 - tr1
DEBUG CR,"Bear right ",DEC course_correction, " degrees"
GOTO readGPS

bearLeft:
course_correction = tr1 - wp1
DEBUG CR,"Bear left ",DEC course_correction, " degrees"
GOTO readGPS

You'll have to fill in the blanks on the SERIN instruction to
make it match your input stream.

Incidentally, you could use the tenths of a degree easily by just
storing your bearings as 0 <= course < 3600. Just keep the 10 x's
factor in mind. You can always artificially put the decimal back in
for display purposes or whatever. But...the tenths may be
meaningless anyway if the GPS doesn't really have that kind of
accuracy or tenths of a degree don't matter for your application
anyhow.


Regards,

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-24 04:12
    Just a quick question if someone could explain something. I am reading the serin data from a GPS data at 4800 baud.·I am only reading a couple things of information. Just my true couse 000.0 and true course to waypoint 000.0 again. I know I can only read the first three numbers and nothing past the decimal, well I can read it but any complicated math is out of the question. Basically all I want to do is subtract the waypoint from the true heading to get the difference. My problem is when the resulting number is negative and I am using a IF. THEN statement to issue commands and it is reading the variable as ascii and I can't figure out a way to IF.THEN an ascii variable.

    The variables are wp1 var word and tr1 var word, currently I am trying to use an array and cannot figure out how to subtract a whole array from another array. If I am totally off base somewhere in here please tell me so, I am just learning PBasic and this type of programming, I used to use basic a bit but never this way. Thanks for any help.

    Matt Klarich


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Do You Yahoo!?
    Yahoo! Auctions - buy the things you want at great prices
Sign In or Register to comment.