View unanswered posts | View active topics It is currently Mon Oct 20, 2014 1:22 am






Reply to topic  [ 3 posts ] 
[resolved:] crash if struct var are assigned to another 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post [resolved:] crash if struct var are assigned to another
a new bug in RobotC (1.10) when using structures:
if one struct variable is assigned to another struct variable then RobotC hangs up / crashes; program can't be stopped, NXT has to be rebootet!
function definition: line 115
function call: line 168
Code:
void outIdent(tNeuron &neur){     // Ausgabefunktion 1   [line 115]  >>>>>>>>>CAUSES CRASH !!!!!
  neur.out=neur.act;              // Ausgabe: Identitaet
}


if you comment out line 168 , there's no crash besides the faulty float assignments (see different threads)

Code:
// Neuronales Netz aus 1 Neuron
// LTU = Linear Threshold Unit oder
// Adaline = Adaptive linear element
// (c) Helmut W. 2008
// version 0.1.0


#define printXY nxtDisplayStringAt

//**********************************************************************
// Basisdeklarationen fuer Neuronale Netze
// spater ausgegliedert als Neurons.h
//**********************************************************************


const int nl0 = 20;    // max. Neuronen  Schicht (Layer) 0
const int nl1 =  7;    // max. Neuronen  Schicht (Layer) 1
const int nl2 =  7;    // max. Neuronen  Schicht (Layer) 2
const int nl3 =  2;    // max. Neuronen  Schicht (Layer) 3


const int nd = 20;     // max. Dendriten-Eingaenge
const float th = 0;    // Standard Schwellenwert (threshold)
float lbd = 0.2;       // Lern-Index / Faktor lambda

//**********************************************************************

typedef struct{
   float in[nd];    // Einzel-Input (Dendrit)
   float w[nd];     // Einzel-Wichtung (Dendrit)
   float tw[nd];    // Trainings-Wert fuer Wichtung
   float net;       // totaler Input
   float thr;       // Schwellenwert (threshold)
   float tthr;      // Trainingswert fuer Schwelle
   float act;       // errechneter Aktivierungswert
   float out;       // Output (Axon): 0 oder 1
} tNeuron;


tNeuron Neuron0[nl0];  // Neuronen-Schicht 0 = Eingabeschicht
tNeuron Neuron1[nl1];  // Neuronen-Schicht 1
tNeuron Neuron2[nl2];  // Neuronen-Schicht 2
tNeuron Neuron3[nl3];  // Neuronen-Schicht 3

//**********************************************************************

void ResetNeuron(tNeuron &neur){ // alles auf Null
   int d;

   for (d=0; d<nd; d++) {
      neur.in[d]=0;      // Einzel-Input (Dendrit)
     neur.w[d]=0;       // Einzel-Wichtung (Dendrit)
     neur.tw[d]=0;      // Trainings-Wert
   }
   neur.net=0;          // totaler Input
   neur.thr=th;         // Schwellenwert (threshold)
   neur.tthr=0;         // Traingswert fuer Schwelle)
   neur.act=0;          // errechneter Aktivierungswert
   neur.out=0;          // Output (Axon)

}

//**********************************************************************


void initAllNeurons(){              // alle Netz-Neuronen auf Null
   int n;

  for (n=0; n<nl0; n++) {           // Neuronen-Schicht 0
        ResetNeuron(Neuron0[n]);}
  for (n=0; n<nl1; n++) {           // Neuronen-Schicht 1
        ResetNeuron(Neuron1[n]);}
  for (n=0; n<nl2; n++) {           // Neuronen-Schicht 2
        ResetNeuron(Neuron2[n]);}
  for (n=0; n<nl3; n++) {           // Neuronen-Schicht 3
        ResetNeuron(Neuron3[n]);}
}

//**********************************************************************

void netPropag(tNeuron &neur){      // Propagierungsfunktion
  int j=0;                          // kalkuliert den Gesamt-Input (net)
  float s=0;

  for(j=0;j<nd;j++){
     s+= (neur.in[j]*neur.w[j]);     // gewichtete Summe
  }
  neur.net=s;
}

//**********************************************************************

void actThr_01(tNeuron &neur){      // Aktivierungsfunktion 1
   if (neur.net>=neur.thr)           // per Schwellwert thr (threshold)
      {neur.act=1;}                  // Fkt.-Wert: 0 oder 1 ab Schwelle
   else {neur.act=0;}
}


void actThrIdent(tNeuron &neur){    // Aktivierungsfunktion 2
   if (neur.net>=neur.thr)           // per Schwellwert thr (threshold)
     {neur.act=neur.net;}            // Fkt-Wert: 0 oder Identitaet ab Schwelle
     else {neur.act=0;}
}

void actFermi(tNeuron &neur){       // Aktivierungsfunktion 3
   float val;                        // Fermi-Fkt. (Logistisch, differenzierbar)
   float c=2.0;                      // c= Steilheit, bei c=1: Gerade
  val= (1/(1+(exp(-c*neur.net))));
  neur.act=val;
}

//**********************************************************************

void outIdent(tNeuron &neur){     // Ausgabefunktion 1   [line 115]  >>>>>>>>> CRASH !!!!!
  neur.out=neur.act;              // Ausgabe: Identitaet
}


void out_01(tNeuron &neur){       // Ausgabefunktion 2
   if (neur.act>0)  neur.out=1;    // Ausgabe: 0 oder aber 1 wenn >0
   else neur.out=0;
}

//**********************************************************************



void Pause() {
   while(true) wait1Msec(50);
}

task DisplayValues(){
   while(true) {
    printXY( 0,60, "LTU=Adaline");
    printXY( 0,50, "in(0 1)");
    printXY( 18,40, "%1.0f", Neuron0[0].in[0]);
    printXY( 30,40, "%1.0f", Neuron0[0].in[1]);
    printXY( 0,30, "net"); printXY(30,30,"%4.1f",Neuron0[0].net);
    printXY( 0,20, "act"); printXY(30,20,"%4.1f",Neuron0[0].act);
    printXY( 0,10, "OUT"); printXY(30,10,"%4.1f",Neuron0[0].out);
  }
  return;
}

void InitThisNeuronalNet(){
  Neuron0[0].w[0]=1;               // Wichtung fuer Input 0
  Neuron0[0].w[1]=1;               // Wichtung fuer Input 1
  Neuron0[0].thr=1.5;
}

task RefreshInputs(){  // Inputs sollen sehr schnell erfasst werden, daher als eigener Task
  while(true){
    Neuron0[0].in[0]=(float)SensorValue(0); // Input 0: Touch-Sensor an S1=0
    Neuron0[0].in[1]=(float)SensorValue(1); // Input 1: Touch-Sensor an S2=1
  }
  return;
}

task RefreshLayer(){
  while(true){
    netPropag(Neuron0[0]);      // gewichtete Summe ausrechnen
    actThr_01(Neuron0[0]);      // Aktivitaet ueber gesp. Schwellenwert bestimmen

    // ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // if you'll remove the following comment slashes, RobotC crashes !!!!!!!!

    outIdent(Neuron0[0]);    // Ausgang berechnen, hier per Identitaet [line 168] >>>> CRASH !!!
  }
  return;
}

task main(){
  SensorType(S1)=SensorTouch;
  SensorType(S2)=SensorTouch;

  InitAllNeurons();
  InitThisNeuronalNet();

  StartTask (DisplayValues);
  StartTask (RefreshInputs);
  StartTask (RefreshLayer);
  Pause();
}


_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Thu May 29, 2008 8:40 am, edited 1 time in total.



Sun Apr 20, 2008 7:49 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
anyone at home?
where is the support?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Apr 25, 2008 4:02 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
Reminder!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Apr 29, 2008 2:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.