Go to Post As Frank said, when an FRC team hurts, we all hurt. - Hallry [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-10-2010, 14:55
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Lego NXT -- NXC blocking bluetooth IO

I've been working on a remote-controlled robot using Lego Mindstorms NXT, NXC, and Perl. It is working well for now, but it is polling the bluetooth device for new data.

In NXC, is there any way to do blocking IO on the bluetooth device?

Thank you for any help.
  #2   Spotlight this post!  
Unread 08-10-2010, 16:49
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Lego NXT -- NXC blocking bluetooth IO

It's been a while since I've used nxc, but couldn't you just put the bluetooth function in a while loop?
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
  #3   Spotlight this post!  
Unread 08-10-2010, 18:26
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Lego NXT -- NXC blocking bluetooth IO

That's what I have, but that is still polling, not blocking IO.

I suspect that the bluetooth chip itself has to be polled, so I probably have no choice but to keep polling it.

I do a Yield() in the loop (if no data has been returned yet), so I guess I've done the best I can.
  #4   Spotlight this post!  
Unread 08-10-2010, 19:37
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Lego NXT -- NXC blocking bluetooth IO

I believe that the NXC firmware is based on the LEGO FW, and the scheduling in that FW is done statically. The I/O drivers run once per millisecond and the VM is guaranteed to not be running during that period. This simplifies the protection mechanisms.

The user level code that meshes well with this is to poll and if not arrived, sleep 1 millisecond. There would be slightly less overhead if the BT driver had a notification mechanism, but it is pretty capable as long as there is a delay. A slightly better guess is to sleep the appropriate time based on the amount being transferred. Does yield in NXC take a parameter, or is there a better way to sleep a controlled amount?

Greg McKaskle
  #5   Spotlight this post!  
Unread 08-10-2010, 19:58
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Lego NXT -- NXC blocking bluetooth IO

There's a millisecond wait command, which I assume also yields the processor.

I have not changed the firmware (probably should've made it clearer). I am running version 1.05 (I know it's old, I have seen no reason to update).

I guess I'll just poll it, and change the wait to 1 millisecond, now that I know more.

Thanks for the info.
  #6   Spotlight this post!  
Unread 08-10-2010, 20:02
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Lego NXT -- NXC blocking bluetooth IO

I'm not sure when the LEGO FW was able to sleep efficiently, but I think it was 1.28 or so. Before that, the sleep may very well be a busy loop as well.

Greg McKaskle
  #7   Spotlight this post!  
Unread 09-10-2010, 09:04
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Lego NXT -- NXC blocking bluetooth IO

I spent a couple hours debugging an issue where threads would randomly crash on it. I thought it could be a race condition, but only two variables are shared between threads, and reads/writes are atomic (boolean).

I then found the -safecall option to nbc. This fixed it.

From now on, my code will have to grab a mutex just to run. I hope Wait() is multithread-safe, but if it isn't, I can write my own (I assume Acquire, Release, and Yield are threadsafe).

Thank you.

EDIT: It's been running fine for a while now, so I thinkk Wait() is threadsafe.

EDIT2:
I am running into another weird bug. If I run 4 threads (I don't know about numbers larger than four) and use a mutex (in only two of the threads), I get a delay in the bluetooth reception. The code doesn't slow down, but the controls run with a delay.

Last edited by flameout : 10-10-2010 at 01:03. Reason: Another issue
  #8   Spotlight this post!  
Unread 10-10-2010, 11:51
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Lego NXT -- NXC blocking bluetooth IO

I can't edit it, so I'll post that I've found the problem.

The fourth loop was pushing it just enough to make it take over 50 ms, so the messages were being buffered for some amount of time.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[FTC]: NXT bluetooth connectivity issue Team 288 FIRST Tech Challenge 3 26-11-2009 12:38
cant get NXT to connect to controller station via bluetooth cougarbotics FIRST Tech Challenge 5 04-12-2008 00:19
[FTC]: Bluetooth/NXT issues jbbjjbt FIRST Tech Challenge 5 23-10-2008 16:56
LEGO Unveils new LEGO Mindstorms NXT Robotics Toolset Danny Diaz Lego Mindstorm Discussion 21 25-05-2006 19:56
LEGO Unveils new LEGO Mindstorms NXT Robotics Toolset Danny Diaz FIRST Lego League 0 05-01-2006 01:56


All times are GMT -5. The time now is 23:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi