IEnumerator Poll()
{
while (true)
{
string str = “r axis0.encoder.pos_estimate\n”;
byte data = System.Text.Encoding.ASCII.GetBytes(str);
SC.SendSerialMessage(data);
string str1 = "r axis1.encoder.pos_estimate\n";
byte[] data1 = System.Text.Encoding.ASCII.GetBytes(str1);
SC.SendSerialMessage(data1);
byte[] msg0 = ReadUntilEndMarker();
byte[] msg1 = ReadUntilEndMarker();
if (msg0 != null && msg1 != null)
{
String input0 = System.Text.Encoding.ASCII.GetString(msg0);
ang0 = float.Parse(input0);
ang0 = ang0 * 360 / Ratio;
String input1 = System.Text.Encoding.ASCII.GetString(msg1);
float ang1 = float.Parse(input1);
ang1 = ang1 * 360 / Ratio;
Debug.Log("Motor 0 Angle: " + ang0);
Debug.Log("Motor 1 Angle: " + ang1);
}
else
{
Debug.Log("Failed to read messages from the serial port");
}
yield return new WaitForSeconds(PollInterval);
}
}