mercredi 1 février 2017

For loop dependent on thread variables

My code may give some of you eye cancer, but please take a look:

for(V1=0;V1<4095;V1++){
send voltage signal to DAC
wait_ms(10);
    if(V1>1366){
        while(1){
          V2++;
          send voltage 2 signal to DAC channel 2;
          V1++;
          send voltage 1 signal to DAC channel 1;
          wait_ms(10);
              if(V1==4095){
               break;
              }
          }
    }
}

so when voltage 1 reaches 5V(1366), voltage 2 starts to increase along with voltage 1 until voltage 1 hits 12V(4095), and then they both stop. I type the exact same code but the conditions are angles measured in a previous thread, instead of V1.

thread* pThread=new Thread(angle_thread);
float angleY;
float angleX;
for(V1=0;V1<4095;V1++){
    send voltage signal to DAC
    wait_ms(10);
        if(angleY=something){
            while(1){
              V2++;
              send voltage 2 signal to DAC channel 2;
              V1++;
              send voltage 1 signal to DAC channel 1;
              wait_ms(10);
                  if(angleX=something){
                   break;
                  }
              }
        }
    }

What I want to happen is voltage 1 increases until angle Y is the desired angle, and then voltage 1&2 increase until angle X is the desired angle, and then the voltages stay at those values. What ends up happening is voltage 1 doesn't move until angle Y is the desired angle, and then it starts moving, and voltage 2 doesn't start at all.

Tldr, how do I control a loop using values that I got from a thread? They are declared globally. I hope my question makes sense

Aucun commentaire:

Enregistrer un commentaire