View unanswered posts | View active topics It is currently Tue Jan 23, 2018 11:59 pm






Reply to topic  [ 7 posts ] 
Making GPS sensor talk to NXTBEE 
Author Message
Rookie

Joined: Tue Oct 22, 2013 11:00 am
Posts: 15
Location: Texas
Post Making GPS sensor talk to NXTBEE
We are running code on a robot using multiple sensors and needing to see if something is possible.

Using Dexter industries GPS and NXTBee radio

GPS creates longs for longitude and latitude

I am wanting to create either a string combining the word longitude and the longitude long

And then need to either be able to move through that string one character at a time or convert it to an array of characters.

For people who are familiar with Java - I am looking to see if something like stringname.charAt(location) will return a character

The same can obviously done going through an array of characters one index at a time

The NXTBee will send 1 character at time time easily enough and I can not find a way to send a number or a string as one piece.

Ideas???

Working with students on a tight timeline so any help will be appreciated


Thu Apr 23, 2015 10:29 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Making GPS sensor talk to NXTBEE
char strIndex(const string &sString, const short nIndex); may be the function you're looking for.
You can also "convert" the string to a char array by simply copying it with memcpy();
Code:
char array[100];
string foo = "hello world";
memcpy(&array[0], foo, strlen(foo) + 1));

Make sure the array is large enough to hold the string :)
= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Apr 23, 2015 10:38 am
Profile WWW
Rookie

Joined: Tue Oct 22, 2013 11:00 am
Posts: 15
Location: Texas
Post Re: Making GPS sensor talk to NXTBEE
Thanks for quick response - the string and char part I understand now.

Will Robot C let you copy a long into a string?


Thu Apr 23, 2015 12:06 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Making GPS sensor talk to NXTBEE
You mean convert it to ascii? sure, just use snprintf() :)

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Apr 23, 2015 12:14 pm
Profile WWW
Rookie

Joined: Tue Oct 22, 2013 11:00 am
Posts: 15
Location: Texas
Post Re: Making GPS sensor talk to NXTBEE
So I can copy a long into a string

task main()
{
string message;
long longitude = 10234161;
wait1Msec(1000);
snprintf(longitude, message); or did you mean sprintf(longitude, message);


}


Thu Apr 23, 2015 1:47 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Making GPS sensor talk to NXTBEE
snprintf(ppDest, nDestLength, pzFormatString, ...); is the call, you can also use sprintf, if you don't want to specify the max length of the receiving buffer:
Code:
task main()
{
  char msg[20];
  long longitude = 10234161;
  snprintf(msg, 20, "%d", longitude);
  writeDebugStreamLine(msg);
 
  string foo;
  sprintf(foo, "%d", longitude);
  writeDebugStreamLine(foo);
}

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Apr 23, 2015 3:59 pm
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Making GPS sensor talk to NXTBEE
Btw, do not cross post in multiple sub forums. I have deleted the other post.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Apr 23, 2015 4:01 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.