absoute position regulation from NBC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

absoute position regulation from NBC

Post by pepijndevos »

Is it possible?

http://nxt-firmware.ni.fr.eu.org/change ... egulation/

That is the only documentation I can find about it, and it mentions the thing is implemented in NXC, and has only NXC examples, but says the "API is available in Bricxcc version 3.3.8.9 or NBC/NXC version 1.2.1 r4."

If it is in NXC, is there some sort of "not exactly C calling convention"?

I could as well use NXC of course, but it provides only a few abstractions I don't need, and not the ones I do need, so I didn't bother to learn the extra syntax.
-- Pepijn
http://studl.es Mindstorms Building Instructions
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: absoute position regulation from NBC

Post by spillerrec »

Everything you can do in NXC you can do in NBC, as NXC is simply converted to NBC. If you look at the NBC code the NXC compiler generates, you can figure out how to do it in NBC directly.
To view the generated NBC code, use BCC to compile and hit the F12 key when it is done. A window pops up with the NBC code.

So just try to replicate that, it shouldn't be too hard in most cases. (Though beware, some NXC functions which are not natively supported by the firmware can be large.)
You can also try to look in the header files which you can find in the NBC source code folder, though I'm not completely sure you can look up every function that way.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: absoute position regulation from NBC

Post by pepijndevos »

I don't use BCC, but browsing the help on NBC revealed an -nbc option, however, it generates 7000 lines of code for my 50 line NXC program, is all of that really sent to the NXT, or is there some option to see just the actual code?

However, it just seems to do some really complicated setout statement, which makes sense I guess.
-- Pepijn
http://studl.es Mindstorms Building Instructions
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: absoute position regulation from NBC

Post by spillerrec »

I don't use BCC either except for this because I find it more convenient. It filters out the "FILE at line ##" comments.
I think you are getting the unoptimized version of the NBC code which contains a copy of the NXT headers, which are rather large. You might be using the wrong option. I'm getting the best results with -L, but I might have a different version of NBC since I don't have the -nbc option.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: absoute position regulation from NBC

Post by afanofosc »

Code: Select all

inline void PosRegEnable(byte output, byte p = PID_3, byte i = PID_1, byte d = PID_1)
{
    SetOutput(output,
	       OutputModeField, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED,
	       RegModeField, OUT_REGMODE_POS,
	       RunStateField, OUT_RUNSTATE_RUNNING,
	       PowerField, 0,
	       TurnRatioField, 0,
	       RegPValueField, p, RegIValueField, i, RegDValueField, d,
	       UpdateFlagsField, UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+UF_UPDATE_RESET_COUNT);
    Wait(MS_2);
}
The NBC equivalent to this would be a setout opcode and a wait opcode

Code: Select all

inline void PosRegSetAngle(byte output, long angle)
{
    SetOutput(output,
	       TachoLimitField, angle,
	       UpdateFlagsField, UF_UPDATE_TACHO_LIMIT);
}
The NBC equivalent to this would be a setout opcode

Code: Select all

inline void PosRegAddAngle(byte output, long angle_add)
{
    long current_angle = GetOutput(output, TachoLimitField);
    SetOutput(output,
	       TachoLimitField, current_angle + angle_add,
	       UpdateFlagsField, UF_UPDATE_TACHO_LIMIT);
}
The NBC equivalent to this would be a getout opcode, an add opcode, and a setout opcode.

Code: Select all

inline void PosRegSetMax(byte output, byte max_speed, byte max_acceleration)
{
    SetOutput(output,
	       MaxSpeedField, max_speed,
	       MaxAccelerationField, max_acceleration,
	       UpdateFlagsField, UF_UPDATE_PID_VALUES);
    Wait(MS_2);
}
The NBC equivalent to this would be a setout opcode and a wait opcode.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

Re: absoute position regulation from NBC

Post by pepijndevos »

Whehee, thanks.
-- Pepijn
http://studl.es Mindstorms Building Instructions
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests