Page 1 of 1

absoute position regulation from NBC

Posted: 02 Feb 2012, 08:40
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.

Re: absoute position regulation from NBC

Posted: 02 Feb 2012, 12:06
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.

Re: absoute position regulation from NBC

Posted: 02 Feb 2012, 13:28
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.

Re: absoute position regulation from NBC

Posted: 02 Feb 2012, 15:35
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.

Re: absoute position regulation from NBC

Posted: 02 Feb 2012, 19:17
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

Re: absoute position regulation from NBC

Posted: 03 Feb 2012, 07:41
by pepijndevos
Whehee, thanks.