wishlist for BricxCC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
legoguyohman109
Posts: 3
Joined: 12 Aug 2011, 13:54

Re: wishlist for BricxCC

Post by legoguyohman109 »

Maybe it is a good idea to put in codes to control RCX with vision command, I am trying it much now but I don't have any idea how to do this.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for BricxCC

Post by HaWe »

as I already wrote in a different thread:
Vision Command (VC) is a stand-alone image processing program for USB cam control and RCX IR remote control, it's no add-on for NQC or RCX code or Bricxcc or anything, and there is no program interface from VC to NQC or RCX code or Bricxcc or anything. You would see this if you ever had started working with VC.

What you maybe wish is a image processing capability by BricxCC itself WITHOUT VC, but I doubt that BricxCC will be able to support image processing.

ps
maybe it's more clear to you by the following example:
Imagine you got a PC program called "OmniPage" which controls your USB scanner for optical character recognition (OCR) .
Your question now might be figurative,transposed:
can we put in BricxCC codes to control the RCX by OmniPage OCR with the USB scanner ?
(admittedly a poor example, because Omnipage actually has many interfaces to many different programs (such as Word), and VC got none)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for BricxCC

Post by afanofosc »

FYI, I uploaded a new test release of BricxCC/NBC. It has not been moved to the test_releases folder yet (tonight if I don't forget like I did yesterday) but it can be downloaded from the sourceforge mirrors here:

http://sourceforge.net/projects/bricxcc ... 111024.zip

In this build I have fixed a number of defects:

1. NBC keywords used as global variable names cause a compiler error. You should be able to use "mov", "index", or any other NBC keyword except possibly "dseg" - I just verified that it still cannot be used as a global variable. I will work on fixing it so that dseg can also be used as a global variable.

2. Double slashes (//) embedded in strings as part of an initializer for an array of strings causes a compiler error. E.g., string third[]={"a","b","http://www.fi",}; This works now.

3. Recent expression optimization changes broken the evaluation of bitwise AND and OR constant expressions such as 0x40 | 0x20. This defect is fixed.

4. The optimizer was causing float to integer assignments to sometimes be optimized out entirely so that the original floating point value was used in subsequent operations rather than its truncated version contained in the integer variable. The optimizer now checks that both variables in the mov operation are of the same type before it decides that it is safe to perform the optimization.

The standard NBC and NXC header files now include support for the Dexter Industries IMU sensor with official API functions as well as the HiTechnic Prototype board and an exciting new product coming soon from HiTechnic.

The test release also includes a new build of the enhanced NBC/NXC firmware version 1.31 which fixes a long standing defect that caused float to signed long operations to fail at the firmware level. This was seen in a number of cases in NXC programs when assigning between a float and a long, as shown in the code at this link: http://bricxcc.svn.sourceforge.net/view ... ti_bug.nxc

A new official release containing all the fixes and enhancements since 2011-03-15 when version 3.3.8.9 of BricxCC was released should be ready to go by the end of October.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for BricxCC

Post by HaWe »

what I already posted this morning (but the post has not been published):
DocHelmut alias Ford Prefect wrote:the compiler optimization is still defective as shown in a previous task.
This is the test code:

Code: Select all

          // Matrix algebra / arithmetics
// vers. 0.92t (HaWe+jch+splrc version)


#define MatrixMulS(_Out, _A, _s) asm { mul _Out, _A, _s }
#define MatrixDivS(_Out, _A, _s) asm { div _Out, _A, _s }

#define MatrixAdd(_Out, _A, _B) asm { add _Out, _A, _B }
#define MatrixSub(_Out, _A, _B) asm { sub _Out, _A, _B }

#define ArrayIndex(_out, _A, _i)   asm { index _out, _A, _i }
#define ArrayReplace(_A, _i, _new) asm { replace _A, _A, _i, _new }

#define BranchTest(_cmp, _lbl, _v1) asm{ brtst _cmp, _lbl, _v1 }
#define BranchComp(_cmp, _lbl, _v1, _v2) asm{ brcmp _cmp, _lbl, _v1, _v2 }


#define ArrayInit2D(array, tmp, init_val, dimx, dimy) { \
  ArrayInit(tmp, init_val, dimy);  \
  ArrayInit(array, tmp, dimx);     \
  ArrayInit(tmp,0,0);              \
}


void MatrixTransp(float A[][], float &C[][], int R, int S) {
   float tmp[], arr_temp[], val_temp;
   int s, r;
   ArrayInit(tmp, 0, R);
   ArrayInit(C, tmp, S);
   s = S;
   lbl_Trans_start_s:
   {
      s--;
      r = R;
      lbl_Trans_start_r:
      {
         r--;
         ArrayIndex(arr_temp, A, r);
         ArrayIndex(val_temp, arr_temp, s);
         ArrayReplace(tmp, r, val_temp);
      }
      BranchTest(GT, lbl_Trans_start_r, r);
      ArrayReplace(C, s, tmp);
   }
   BranchTest(GT, lbl_Trans_start_s, s);
}

                                               // N x M Matrix  *  M x K Matrix, OLD version
void MatrixMatrixMult_OLD(float A[][], float B[][], float &C[][], int N, int M, int K){
  int i, j, s;

  for (i=0; i<N; ++i) {
    for (j=0; j<K; ++j) {
       C[i][j]=0;
       for (s=0; s<M; ++s) {
         C[i][j]=C[i][j] + A[i][s]*B[s][j];
      }
    }
  }
}

                                               // N x M Matrix  *  M x K Matrix, NEW version
void MatrixMatrixMult(float A[][], float B[][], float &C[][], int N, int M, int K){
   float arr_temp[];
   //Set size of C
   ArrayInit( arr_temp, 0, K );
   ArrayInit( C, arr_temp, N );

lbl_Mult_start_i:   N--;   //Loop start
      //Speed up arrays
      float A_i[];
      float C_i[];
      ArrayIndex(A_i, A, N);
      ArrayIndex(C_i, C, N);

      int j = K;
lbl_Mult_start_j: j--;   //Second loop start
         float sum = 0;

         int s = M;
lbl_Mult_start_s: s--;   //Third loop start

            //sum += A_i[s]*B[s][j];
            float temp, sum_temp;
            ArrayIndex(sum_temp, A_i, s);
            ArrayIndex(arr_temp, B, s);
            ArrayIndex(temp, arr_temp, j);
            sum_temp *= temp;
            sum += sum_temp;
         asm { brtst GT, lbl_Mult_start_s, s }
         ArrayReplace(C_i, j, sum);
      asm { brtst GT, lbl_Mult_start_j, j }
      ArrayReplace(C, N, C_i);
     asm { brtst GT, lbl_Mult_start_i, N }
}



void MatrixRotate2DMath(float A[][], float &C[][], float angleDeg) {
   float tmp[], x, B[][];

   ArrayInit2D(C, tmp, 0, 2, 2);

   x=cosd(angleDeg);
   ArrayInit2D(B, tmp, x, 2, 2);
   x=sind(angleDeg);
   B[0][1]=-x;
   B[1][0]= x;

   MatrixMatrixMult(B, A, C, 2, 2, 2);
}


#define MatrixRotate2DGeo(A,C, d) MatrixRotate2DMath(A,C,-d)



float MatrixDet2x2(float A[][]) {               // Determinante 1x1, 2x2, 3x3
   float r0[], r1[], r2[], v00, v01, v02, v10, v11, v12, v20, v21, v22;

      r0 = A[0];
      r1 = A[1];
      return ( r0[0]*r1[1]- r0[1]*r1[0] );
}


float MatrixDet3x3(float A[][]) {               // Determinante  3x3
   float r0[], r1[], r2[], v00, v01, v02, v10, v11, v12, v20, v21, v22;

      r0 = A[0];
      r1 = A[1];
      r2 = A[2];
      v00 = r0[0]; v01 = r0[1]; v02 = r0[2];
      v10 = r1[0]; v11 = r1[1]; v12 = r1[2];
      v20 = r2[0]; v21 = r2[1]; v22 = r2[2];
      return (v00*v11*v22
             +v01*v12*v20
             +v02*v10*v21
             -v02*v11*v20
             -v01*v10*v22
             -v00*v12*v21);

}


void MatrixAdj2x2 (float A[][], float &C[][]) {  // Adjugate=Adjunkte 1x1, 2x2, 3x3
  float r0[], r1[], r2[], c0[], c1[], c2[], t0, t1, t2;

    ArrayIndex(r0, A, 0);
    ArrayIndex(r1, A, 1);
    ArrayIndex(t0, r1, 1);
    ArrayIndex(t1, r0, 1);
    asm { mul t1, t1, -1 }
    ArrayBuild(c0, t0, t1);
    ArrayIndex(t0, r1, 0);
    asm { mul t0, t0, -1 }
    ArrayIndex(t1, r0, 0);
    ArrayBuild(c1, t0, t1);
    ArrayBuild(C, c0, c1);

}


void MatrixAdj3x3 (float A[][], float &C[][]) {  // Adjugate=Adjunkte 1x1, 2x2, 3x3
  float r0[], r1[], r2[], c0[], c1[], c2[], t0, t1, t2;


    float v00, v01, v02, v10, v11, v12, v20, v21, v22;
    r0 = A[0]; r1 = A[1]; r2 = A[2];
    v00 = r0[0]; v01 = r0[1]; v02 = r0[2];
    v10 = r1[0]; v11 = r1[1]; v12 = r1[2];
    v20 = r2[0]; v21 = r2[1]; v22 = r2[2];

    t0 = v11*v22-v12*v21;
    t1 = v02*v21-v01*v22;
    t2 = v01*v12-v02*v11;
    ArrayBuild(c0, t0, t1, t2);

    t0 = v12*v20-v10*v22;
    t1 = v00*v22-v02*v20;
    t2 = v02*v10-v00*v12;
    ArrayBuild(c1, t0, t1, t2);

    t0 = v10*v21-v11*v20;
    t1 = v01*v20-v00*v21;
    t2 = v00*v11-v01*v10;
    ArrayBuild(c2, t0, t1, t2);

    ArrayBuild(C, c0, c1, c2);

}


bool MatrixInverse2x2(float A[][], float &C[][]) {
   float det;

   det=MatrixDet2x2(A);
   if (det==0) return 0;
   else {
     MatrixAdj2x2(A, C);
     C/=det;
     return 1;
   }
}


bool MatrixInverse3x3(float A[][], float &C[][]) {
   float det;

   det=MatrixDet3x3(A);
   if (det==0) return 0;
   else {
     MatrixAdj3x3(A, C);
     C/=det;
     return 1;
   }
}



void MatrixLinear(float A[][], float &C[], int R, int S) {
  int i=0, s, r;
  int dim=R*S;
  ArrayInit(C, 0, dim);
  for (s=0; s<S; ++s) {
    for (r=0; r<R; ++r) {
      C[i++]=A[r][s];
    }
  }
}


void SubMatrix(float A[][], float &C[][], int RS, int r, int s) {
  int i=0, j=0, x=0, y=0, dim_1;
  float tmp[];

  dim_1=RS-1;
  ArrayInit2D(C, tmp, 0, dim_1, dim_1);

  for (y=0; y<RS; ++y) {
    for (x=0; x<RS; ++x) {
      if ((x!=r)&&(y!=s))   {
         C[i][j]=A[x][y];
         ++i;
         if (i>=dim_1){
           i=0; ++j;
         }
      }
    }
  }
}


float MatrixMinor(float A[][], int RS, int r, int s) {
   float C[][];

   SubMatrix(A, C, RS, r, s);

   if(RS==3) {
     return MatrixDet2x2(C);
   }
   else
   if(RS==4) {
     return MatrixDet3x3(C);
   }
}


float MatrixCofactor(float A[][], int RS, int r, int s) {
   float x;

   return pow(-1, r+s)* MatrixMinor(A, RS, r, s);;
}


float MatrixDet4x4(float A[][])  {
   float det=0, x=0;
   int i, j=0, n0, max0=0, imax0, jmax0=0;

   for (j=0; j<4; ++j) {    // find column with most 0's: jmax0
     n0=0;
     for (i=0; i<4; ++i) {
       if (A[i][j]==0) ++n0;
     }
     if (max0<n0) {max0=n0; jmax0=j;}
   }

   for (i=0; i<4; ++i) {    // find row with most 0's: imax0
     n0=0;
     for (j=0; j<4; ++j) {
       if (A[i][j]==0) ++n0;
     }
     if (max0<n0) {max0=n0; imax0=i;}
   }


   if (jmax0>imax0) {
     for (i=0; i<4; ++i) {         // develop from jmax0
       if ( A[i][jmax0]!=0) {      // 0*?=0
          x=A[i][jmax0]*MatrixCofactor(A, 4, i, jmax0);
          det+=x;
       }
     }
     //TextOut(72,56,"j"); NumOut(80,56,jmax0); //debug
     return det;
   }
   else  {
     for (j=0; j<4; ++j) {         // develop from imax0
       if ( A[imax0][j]!=0) {      // 0*?=0
          x=A[imax0][j]*MatrixCofactor(A, 4, imax0, j);
          det+=x;
       }
     }
     //TextOut(72,56,"i"); NumOut(80,56,imax0); //debug
     return det;
   }
}


// speed test
long time0, runtime;

task main() {

  float A[][], B[][], C[][], x;
  float O[][], T[][], L[][], tmp[];;
  int loop;
  time0=CurrentTick();

for (loop=0; loop<100; ++loop)
{
  ArrayInit2D(A, tmp, 0, 2,2);
  ArrayInit2D(B, tmp, 0, 2,2);
  ArrayInit2D(C, tmp, 0, 2,2);

  ArrayInit2D(O, tmp, 0, 4,4);

  NumOut(0,56,loop);

  O[0][0]=0;   O[0][1]=0;   O[0][2]=8;   O[0][3]=22;
  O[1][0]=1;   O[1][1]=5;   O[1][2]=9;   O[1][3]=13;
  O[2][0]=2;   O[2][1]=6;   O[2][2]=10;  O[2][3]=14;
  O[3][0]=3;   O[3][1]=7;   O[3][2]=22;  O[3][3]=15;

  x=MatrixDet4x4(O);

  SubMatrix(O,T,4, 2,1);  // expanded to A[i][j]


  x=MatrixDet3x3(T);


  SubMatrix(T,C,3, 0,1);

  x=MatrixDet2x2(C);


  x=MatrixMinor(T, 3, 0,1);

  x=MatrixCofactor(T, 3, 0,1);


  A[0][0]=1;   A[0][1]=3;
  A[1][0]=2;   A[1][1]=4;

  x=10;
  B=A; B*=x;

  C=A; C+=B;

  MatrixAdj2x2(A,C);

  MatrixInverse2x2(A,C);

  MatrixInverse2x2(A,B);

  MatrixMatrixMult(A,B,C,2,2,2);


  A[0][0]=1;   A[0][1]=1;
  A[1][0]=1;   A[1][1]=0;


  MatrixRotate2DGeo(A,B,30);

  MatrixRotate2DGeo(A,C,90);

}
runtime=CurrentTick()-time0;
TextOut(0,40,"run time");
NumOut (0,32, runtime);   TextOut(72,32,"msec");


while(1);
}
This is the link to the Bricxcc Beta version (24.October 2011):
http://sourceforge.net/projects/bricxcc ... 111024.zip

This is the runtime behaviour of previous and current beta releases:

// stable release 2011-07-02:
// level 0: 9784
// level 1: 8462
// level 2: 7385
// level 3: 7385
// level 4: 7383

// intermedium release 2011-07-20:
// level 0: 9715
// level 1: 8470
// level 2: file error -1
// level 3: file error -1
// level 4: file error -1

// new release 2011-10-24
// level 0: 8780
// level 1: 7861
// level 2: file error -1
// level 3: file error -1
// level 4: file error -1

this shows that the 2011-07-02 version doesn't cause runtime errors by OL>=2 while later releases did and still do to my observation
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for BricxCC

Post by afanofosc »

Doc,

Can you try changing line 353 from

Code: Select all

  SubMatrix(T,C,3, 0,1);

  x=MatrixDet2x2(C);
to

Code: Select all

  SubMatrix(T,L,3, 0,1);

  x=MatrixDet2x2(L);
Let me know what happens.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: wishlist for BricxCC

Post by HaWe »

2 bricks of mine are busy being parallelized in chess calculations, and the 3rd is trying to perform the moves on a real chess board.
I will try ASAP.
(ps: or maybe you can do it by your own? You got my test code, you have my results, you have the idea, and you also have the current installation and fw version, it's a bit stressful and time consuming to always change the bricxcc installation and the fw on the bricks and all that back and forth...)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: wishlist for BricxCC

Post by afanofosc »

Doc, I already tried it and it makes the the File Error -1 go away in my testing. I'd like to know if you see the same results.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: wishlist for BricxCC

Post by mattallen37 »

John,

I wish BCC had a tool like a serial terminal... only it's for the NXT to write to. I don't know if you are familiar with ROBOTC, but I am thinking of something like the debug stream. It doesn't need to be anything fancy, I just want to write strings of various lengths to it, and have carriage return (either a special command, or an ASCII 13).

It would also be cool to have it support the RCX (a true serial terminal) so that I don't have to disconnect from the RCX (release the COM port) to open it in a "real" terminal. This certainly is not as high of a priority to me.

And then someday if you have loads of extra time, I would love Arduino support! The BCC IDE is the best I have ever used; the main advantage being that spaces are the same as blank areas and vice versa (I have no idea how to explain it, it's just awesome!), and hitting tab is the same as space (not the tab-space)! The Arduino IDE is very slow, buggy, and nasty to work with.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: wishlist for BricxCC

Post by mattallen37 »

I would like numbered lines for the editor windows. It seems this should be an option already, but I can't seem to find it anywhere.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: wishlist for BricxCC

Post by muntoo »

Code: Select all

Edit->Preferences->Options->Gutter->Line numbers
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests