Page 6 of 25

Re: wishlist for NXC

Posted: 19 Jan 2011, 14:52
by HaWe
indeed I was thinking of arrays of any type to be sorted, single dimensional arrays of integer as well as floats, maybe even 2-dim arrays of floats (= [x,y] coordinates, sorted to the x or the y value)
for this task having a function overloading surely would be helpful

I was asking because a qsort normally is already implemented in most of C libraries coming with the compilers, so I wouldn't have to try to write something like it on my own.

Re: wishlist for NXC

Posted: 19 Jan 2011, 15:54
by mightor
You would need a mechanism to create a pointer to a function that provides a comparison for the type in question. Otherwise there is no generic way of doing this.

- Xander

Re: wishlist for NXC

Posted: 19 Jan 2011, 16:25
by afanofosc
The enhanced NBC/NXC firmware does provide a way to sort a 1d array of any scalar type. It is exposed as the ArraySort NXC API function.

http://bricxcc.sourceforge.net/nbc/nxcd ... index.html

Search for ArraySort.

http://bricxcc.sourceforge.net/nbc/nxcd ... ample.html

John Hansen

Re: wishlist for NXC

Posted: 19 Jan 2011, 16:34
by HaWe
That's really great, thanks!
Even the ArrayOp is excellent ! :)
maybe you also wish to implement an ArrayMed and an OPARR_MED for the median? ;)

(edit: although it's simple, as it's just variant[(1+array_len)/2] of the sorted array (start counting at 1) or
variant[array_len/2] (start counting at 0))

Re: wishlist for NXC

Posted: 26 Jan 2011, 17:59
by HaWe
hi,
could we have a well working function for synched motor control which works less faulty than the current RotateMotorEx together with the current FW (OFW/EFW)?

e.g.

Code: Select all

void RotateMotorSync  ( // sync is always true!
  byte  output_0, // Master: targets absolute value
  byte  output_1, // Slave: targets relative value
  char  pwr,  
  long  angle,  
  char  turnpct,  
  bool  stop   
 ) 

Code: Select all

----------------- settings ----------------|------------- results ------------------ 
output_0, output_1, pwr angle turnpct stop | target_0 target_1 // comment 
OUT_A     OUT_B     75   400     100  true |   400       400    // 2nd: 100% = 400     
OUT_A     OUT_B     75   400    -100  true |   400      -400    // 2nd: -100% = -400
OUT_A     OUT_B     75   400       0  true |   400         0    // 2nd: 0% 0f 400 = 0
OUT_A     OUT_B     75   400      50  true |   400       200    // 2nd: 50% of 400 = 200
OUT_A     OUT_B     75   400     -30  true |   400      -120    // 2nd: -30% of 400 = -120 
OUT_A     OUT_B     75   400      -3  true |   400       -12    // 2nd: -3% of 400 = -12 

Re: wishlist for NXC

Posted: 26 Jan 2011, 20:36
by muntoo
Can we have a "ptr" alias for "unsigned long"?

Code: Select all

unsigned long addr = addressOf(??);
vs

Code: Select all

ptr addr = addressOf(??);

Re: wishlist for NXC

Posted: 26 Jan 2011, 22:28
by schodet
doc-helmut wrote:hi,
could we have a well working function for synched motor control which works less faulty than the current RotateMotorEx together with the current FW (OFW/EFW)?

Code: Select all

----------------- settings ----------------|------------- results ------------------ 
output_0, output_1, pwr angle turnpct stop | target_0 target_1 // comment 
OUT_A     OUT_B     75   400     100  true |   400       400    // 2nd: 100% = 400     
OUT_A     OUT_B     75   400    -100  true |   400      -400    // 2nd: -100% = -400
OUT_A     OUT_B     75   400       0  true |   400         0    // 2nd: 0% 0f 400 = 0
OUT_A     OUT_B     75   400      50  true |   400       200    // 2nd: 50% of 400 = 200
OUT_A     OUT_B     75   400     -30  true |   400      -120    // 2nd: -30% of 400 = -120 
OUT_A     OUT_B     75   400      -3  true |   400       -12    // 2nd: -3% of 400 = -12 
What would be different compared to starting both motor with a different speed and angle?

Re: wishlist for NXC

Posted: 27 Jan 2011, 09:08
by HaWe
the sync mode.
both motors run during the same time until they finally have reached their individual target concurrently,
i.e. with turnpct=100% the difference between both counters must not exceed more than e.g. 1 degree ever
and with small turnpcts it's simultaneously the proportional value +/-1:

Code: Select all

angle=400, turnpct=50
motor_0   0   50   100   150   200   250   300   350   400 // absolute
motor_1   0   25    50    75   100   125   150   175   200  // simultaneously proportionally +-1

Re: wishlist for NXC?

Posted: 29 Jan 2011, 14:25
by HaWe
afanofosc wrote:One thing I know Xander has wished for is support for overloaded functions so that you could write:

Code: Select all

int foobar(int x, int y) { return x+y; }
string foobar(string x, string y) {  return x + y; }
are there (hopefully) already any news about this subject?

Re: wishlist for NXC

Posted: 30 Jan 2011, 13:38
by HaWe
doc-helmut wrote:can we have more kinds of formatting parameters for FormatString or printf except %d or %f
...
hi,
I just observed that FomatNum already works in the 20101103 release with fmt="%x", "%04x" as well as with "%s" .
No idea why I couldn't make it work so far.
Unfortunately I still couldn't find a hint about fmt string parameters in the help (FormatNum topic).
Just e.g. "%9s" for flush right tabulator string formatting does not work, but I'm not sure if this is standard anyway.

Code: Select all

  
#define printf1( _x, _y, _format1, _value1) { \
  string sval1 = FormatNum(_format1, _value1); \
  TextOut(_x, _y, sval1); \
}

  printf1( 0,LCDline[0], "seed=%8d dc",RAND_SEED);
  printf1( 0,LCDline[1], "seed=%08x hx",RAND_SEED); // nums flush right
  printf1( 0,LCDline[2], "%9s", "press");  // strings flush left
  printf1( 0,LCDline[3], "%9s", "any");
  printf1( 0,LCDline[4], "%9s", "btn");
  printf1( 0,LCDline[5], "%9s", "to");
  printf1( 0,LCDline[6], "%9s", "continue");
But it's fine that fmt works already not only for numbers but also for strings. Now that it's possible to display both numbers and strings with one universal ANSI-like printf function! :)