loops - C# Saving integer to another method for the next use -


i'm working on program can transfer arm angles mindstorm robot while now. main problem @ moment robot motors don't know start point angle 0 degrees. had idea write algorithm that. problem can't loop cause robot trying suicide when getting commands @ 1 time. have idea save "old angle i" method. i'm not sure if best way it, wondering people should do. there way "save" in method without using loop ?

here code :

private void robotmove(int robotarmr) //robotarmright method     {          int = 0;         int k = robotarmr * 3; // real time angle *3 gear wheel         int j = k - i; // real time angle - old angle          += j;          int sign = math.sign(j);         // depends on sign if motor moving right or left         switch (sign)         {             case -1://motor right                      mcnxtbrick brick = new mcnxtbrick(nxtcommlinktype.usb, 0);                     mcnxtmotor motor = new mcnxtmotor();                     brick.motora = new mcnxtmotor();                     brick.connect();                     j *= -1;                     uint16 l = convert.touint16(j);                     brick.motora.run(20, l); // (power right 50, angle move or foward new angle)                     brick.disconnect();                     break;              case 1: //motor left                      mcnxtbrick brick2 = new mcnxtbrick(nxtcommlinktype.usb, 0);                     mcnxtmotor motor2 = new mcnxtmotor();                     brick2.motora = new mcnxtmotor();                     brick2.connect();                     uint16 l2 = convert.touint16(j);                     brick2.motora.run(-20, l2); // (power left 50, angle move or foward new angle                     brick2.disconnect();                              break;               case 0:                  break;          }     } 

thanks tipps :)

you create helper class saving global variables' values, public static ones, bellow:

public class myhelper {     public static int myval {get; set;} } 

and somewhere in main method, initial value

myhelper.myval = 0; 

and of course, can use anywhere, e.g.

myhelper.myval++; 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -