wishlist for NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post 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.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: wishlist for NXC

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for NXC

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post 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))
Last edited by HaWe on 28 Jan 2011, 17:33, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post 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 
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for NXC

Post 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(??);
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: wishlist for NXC

Post 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?
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post 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
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC?

Post 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?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for NXC

Post 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! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests