AdvancedHMI Software
General Category => Support Questions => Topic started by: joko markono on May 22, 2023, 06:17:02 AM
-
Hi All,
I want to do a counting on number of turn on the rotational indicator on both direction.
For example, if my arrow has made twice clockwise turn, it will show 2 on my apps.
same for CCW. How can I do that on VB.net for this control?
-
Maybe something like this:
Private Sub RotationalIndicator1_ValueChanged(sender As Object, e As EventArgs) Handles RotationalIndicator1.ValueChanged
Dim turns As Single = RotationalIndicator1.Value / 360
RotationalIndicator1.Text = turns.ToString("0.0")
End Sub
-
I have tried that but that only true if the direction starts from 0,1,2,3.... 359
what if it starts like this, 0,359,358,357,356....1?
also if the value pass trough 0 again, then the no. of turn will turn back to zero.
-
The only way to make multiple continuous rotations is to keep going beyond 360
-
how to convert this to vb.net please?
it looks like C# and I used the converter but no luck.
int Start_Angle; // The first compass reading to mark our beginning rotation.
// signed int, will range 0 to 359
int Last_Angle; // preserve the value of the last reading.
// signed int, will range 0 to 359
int Current_Angle; // computed position for where we are now.
// signed int, will range -720 to +720
void Init_Rotation(int Current_Pos);
void Get_Rotation(int Current_Pos);
void main(void)
{
Init_Rotation(10);
Get_Rotation(20);
Init_Rotation(10);
Get_Rotation(350);
Init_Rotation(90);
Get_Rotation(271);
Init_Rotation(20);
Get_Rotation(10);
Init_Rotation(350);
Get_Rotation(10);
Init_Rotation(271);
Get_Rotation(90);
}
void Init_Rotation(int Current_Pos)
{
// set Start_Angle, Last_Angle,
// and Current_Angle to the current reading
Current_Angle = Last_Angle = Start_Angle = Current_Pos;
}
void Get_Rotation(int Current_Pos)
{
// will take the current reading,
// compute the Current_Angle,
// then update Last_Angle, and Current_Angle
int Delta;
// compute delta angle
Delta = Current_Pos - Last_Angle;
// put Delta into range of
// -180 <= angle <= 180
if (Delta > 180) Delta -= 360;
if (Delta < -180) Delta += 360;
// update Current_Angle
Current_Angle += Delta;
// update last reading with our current reading
Last_Angle = Current_Pos;
}
my main problem is that I don't quite understand this part:
void main(void)
{
Init_Rotation(10);
Get_Rotation(20);
Init_Rotation(10);
Get_Rotation(350);
Init_Rotation(90);
Get_Rotation(271);
Init_Rotation(20);
Get_Rotation(10);
Init_Rotation(350);
Get_Rotation(10);
Init_Rotation(271);
Get_Rotation(90);
}
what is does actually?
-
That code looks like somebody was testing certain values.
Maybe try the following code, it has not been tested by me and might need some corrections:
Dim Delta As Integer
Dim Last_Angle As Integer = 360
Dim Total_Turns As Single
Private Sub RotationalIndicator1_ValueChanged(sender As Object, e As EventArgs) Handles RotationalIndicator1.ValueChanged
Dim Current_Angle As Integer = RotationalIndicator1.Value
'* Determine Delta (CW or CCW)
If Current_Angle > 180 AndAlso Last_Angle = 360 Then
Delta = Last_Angle - Current_Angle
ElseIf Current_Angle <= 180 AndAlso Last_Angle = 360 Then
Delta = Current_Angle
Else
Delta = Current_Angle - Last_Angle
End If
Total_Turns = Total_Turns + ( Delta / 360 )
RotationalIndicator1.Text = Total_Turns.ToString("0.0")
If Current_Angle = 0 Then
Last_Angle = 360
Else
Last_Angle = Current_Angle
End If
End Sub
-
This is what I have for determine rotational direction:
0/360
90 270
180
CCW = ((Target>Current) AND (Target-Current < 180)) OR ((Current>Target) AND (Current-Target>=180))
CW = ((Target>Current) AND (Target-Current >= 180)) OR ((Current>Target) AND (Current-Target<180))
Say you are at 90, want to move to 180. My brain can easily tell that to move CCW for shortest distance, but for machine, it needs to do some calculation first.
-
That code looks like somebody was testing certain values.
Maybe try the following code, it has not been tested by me and might need some corrections:
Dim Delta As Integer
Dim Last_Angle As Integer = 360
Dim Total_Turns As Single
Private Sub RotationalIndicator1_ValueChanged(sender As Object, e As EventArgs) Handles RotationalIndicator1.ValueChanged
Dim Current_Angle As Integer = RotationalIndicator1.Value
'* Determine Delta (CW or CCW)
If Current_Angle > 180 AndAlso Last_Angle = 360 Then
Delta = Last_Angle - Current_Angle
ElseIf Current_Angle <= 180 AndAlso Last_Angle = 360 Then
Delta = Current_Angle
Else
Delta = Current_Angle - Last_Angle
End If
Total_Turns = Total_Turns + ( Delta / 360 )
RotationalIndicator1.Text = Total_Turns.ToString("0.0")
If Current_Angle = 0 Then
Last_Angle = 360
Else
Last_Angle = Current_Angle
End If
End Sub
I tried this and seems working but because I don't have the compass with me, I can't tell whether it is 100% working. my only concern is the indicator will not display 360, after 359, it will be 0 again. so, I can't tell if the code is fully correct until I got the physical compass later.