Home→Forums→MonoBrick Communication Library→Error: Wrong Number of Bytes received.
- This topic has 10 replies, 2 voices, and was last updated 10 years, 7 months ago by Anders Søborg.
-
AuthorPosts
-
February 24, 2014 at 12:03 #3992
Sumit GoyalParticipantHi Anders,
I am using the Monobrick Communication Library with Xamarin Studio. Everything works good except a small problem. I am reading the colorsensor in reflection mode in a loop for 10000 times. But the loop breaks in between at random loop counts(329,176,17, 620 etc.), with “Error: Wrong number of bytes received”. Do you have an idea about this?
Thanks in advance and have a nice day.
February 24, 2014 at 12:22 #3993
Sumit GoyalParticipantHey again,
I guess I solved it. May it had something to do with the cycle time of my loop and the frequency of the Ev3 brick to process request. I added a small delay in my loop and now it works just perfect, aleast for now. 🙂
:February 24, 2014 at 20:14 #3996
Anders SøborgKeymasterHi
Great to hear that. Thanks for posting that everything is ok…
Anders
February 25, 2014 at 09:32 #4002
Sumit GoyalParticipantHi again,
Unfortunately that does not solve the problem. But I tried programming the same code with the matlab. It has the same problem there. I am not sure of the reason.
March 1, 2014 at 19:30 #4010
Anders SøborgKeymasterHi
Then I think that a workaround would be to ignore this error when it occurs. Please post some code…
Anders
March 3, 2014 at 10:07 #4016
Sumit GoyalParticipantYa sure!
The code chunk is:
do {
Console.Write(“Loop:”+ i);
// Error comes here in the next statement
int CurrentReading = brick.Sensor1.Read();
Console.Write(” CSR: “+ CurrentReading);Error = SetPoint – CurrentReading;
Integral = 0.5 * Integral + Error;
Derivative = Error – PrevError;
PrevError = Error;Dgain = Derivative * Kd;
Igain = Integral * Ki;
Pgain = Error * Kp;
gain= Dgain+Igain+Pgain;Total= (Dgain+Igain+Pgain)*-1;
Total= Convert.ToInt16(Total);if(Total<-100)
Total= -100;
if(Total>100)
Total=100;spower = Convert.ToSByte(Total);
Console.Write(” spower:”+ spower);
brick.MotorB.On (spower);
brick.MotorC.On (spower);
i=i+1;Console.Write(” Power: ” + Total+”\n”);
// Thread.Sleep(30); helps, but does not solve
} while(i<1000);
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds/1000;
Console.Write(” Time: ” + elapsedMs);brick.MotorB.Off();
brick.MotorC.Off();
brick.MotorA.Off();
brick.Connection.Close();
}March 4, 2014 at 08:05 #4017
Sumit GoyalParticipantHi Anders!
I added a simple try and catch around. It avoids the error but the delay is too much for my program. My robot falls in that time delay. Did you get any clue.
March 4, 2014 at 14:55 #4019
Sumit GoyalParticipantHi Anders!
Creepy enough I tried the same task with Monobrick Firmware…and it has the same problem. The loop terminates anywhere in between. I really need to figure it out very soon. Please help.
March 4, 2014 at 18:47 #4021
Anders SøborgKeymasterHi
My robot falls in that time delay.
Are you trying to control a balancing robot using MonoBrick communication library?
Creepy enough I tried the same task with Monobrick Firmware…and it has the same problem. The loop terminates anywhere in between.
What do you mean it terminates? Does the reading return zero?
I think that the if this is the case there might be an issue with the kernel modules – since they are used in both the firmware and the communication library.
Anders
March 4, 2014 at 21:52 #4024
Sumit GoyalParticipantYes. I am trying to make a segway with the help of color sensor and a PID control.
Yes, I think it might be a problem with the kernel modules.March 4, 2014 at 22:11 #4025
Anders SøborgKeymasterHi
Yes. I am trying to make a segway with the help of color sensor and a PID control.
If you building/programming a robot that depends on a real-time control loop – don’t use the MonoBrick communication library….
Your system will never be “hard” real-time since you are communicating over either Bluetooth or WiFi…. in your case you need a fast response which you can not achieve. You have a very slow sample-rate and furthermore a sample-rate which you can not guarantee…Yes, I think it might be a problem with the kernel modules.
Please post your MonoBrick firmware code in the appropriate forum so the bug can be fixed…
Anders
-
AuthorPosts
You must be logged in to reply to this topic.
Follow