NXC: Keep Alive

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

NXC: Keep Alive

Post by fuzzball27 »

How does the Keep Alive function work in NXC? I looked it up in the .defs and poked around with it, but I couldn't figure it out. :?
fuzzball27 >>-->
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Keep Alive

Post by mattallen37 »

I don't know, but I am guessing it has to do with the shutoff timer that the NXT uses. Normally if you don't use the NXT for a set amount of time (10 minutes for example), then it shuts off. Pressing the buttons seems to reset the 10 minute timer, and probably that command does the same thing.

BTW, it is by no means limited to just a 10 minute timer with Lego FW.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: Keep Alive

Post by linusa »

Yep, exactly what mattallen37 said!
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: NXC: Keep Alive

Post by fuzzball27 »

Alright so I'm guessing if I did something like this would it do the job:

Code: Select all

task main () {
    while(true) {
        KeepAlive();
        Wait(10*6000);
    }
}
I wonder if receiving Remote BT firmware commands still works? (eg. Master sends "RemoteSetOutputState" to brick running "KeepAlive" Function.)
fuzzball27 >>-->
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: NXC: Keep Alive

Post by fuzzball27 »

Never mind! I found a better way to do it in the .defs "RemoteKeepAlive" :D
But I'm getting a strange error...
Here's my code segment:

Code: Select all

while (true) {
	Wait(6000*5)
	Acquire (BT_Mutex);
	RemoteKeepAlive(CONN_BT0);
	Release (BT_Mutex);
}
Here's the error:

Code: Select all

#Error: Preprocessor macro function does not match instance (__connectionSCDCWrite(_conn,__DCKeepAlivePacket,_result))
fuzzball27 >>-->
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: Keep Alive

Post by linusa »

fuzzball27 wrote: I wonder if receiving Remote BT firmware commands still works? (eg. Master sends "RemoteSetOutputState" to brick running "KeepAlive" Function.)
If by "remote BT firmware commands" you mean the "direct commands", then yes: This still works while RXE programs (produced by e.g. NXC or NXT-G) are running. This is true for all direct commands. And from my tests, the direct commands don't even afffect the running RXE's performance...


Btw, you don't really need the keep alive if you set the NXT's sleep timer / auto off to "never", then it stays always on...
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC: Keep Alive

Post by h-g-t »

I think that if you set the sleep timer value to 0 within the NXC program it never goes off.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: Keep Alive

Post by afanofosc »

fuzzball27 wrote:

Code: Select all

#Error: Preprocessor macro function does not match instance (__connectionSCDCWrite(_conn,__DCKeepAlivePacket,_result))
I believe that this has been fixed in one of the more recently posted test releases. The fix will be in the next official release as well. Once I get my boolean expression code generation up to par I should be about ready for an official release.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: Keep Alive

Post by afanofosc »

fuzzball27 wrote:How does the Keep Alive function work in NXC? I looked it up in the .defs and poked around with it, but I couldn't figure it out. :?
If you want to have an NXC program keep *this* brick awake regardless of its user-configured sleep timer value then you have your program call ResetSleepTimer() periodically (i.e., in a loop that executes throughout the lifespan of your program's execution). Or you can call SysKeepAlive. See the help for these two functions.

If you want to have an NXC program keep some other brick awake by sending it a direct command (KeepAlive) via Bluetooth then you have your program call RemoteKeepAlive. You do not use RemoteKeepAlive to keep *this* brick awake.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: NXC: Keep Alive

Post by fuzzball27 »

If you want to have an NXC program keep *this* brick awake regardless of its user-configured sleep timer...
My intention was to Keep a Separate brick alive.
fuzzball27 >>-->
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests