Error: Wrong Number of Bytes received.

HomeForumsMonoBrick Communication LibraryError: Wrong Number of Bytes received.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #3992
    Author Image
    Sumit Goyal
    Participant

    Hi 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.

    #3993
    Author Image
    Sumit Goyal
    Participant

    Hey 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. 🙂
    :

    #3996
    Author Image
    Anders Søborg
    Keymaster

    Hi

    Great to hear that. Thanks for posting that everything is ok…

    Anders

    #4002
    Author Image
    Sumit Goyal
    Participant

    Hi 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.

    #4010
    Author Image
    Anders Søborg
    Keymaster

    Hi

    Then I think that a workaround would be to ignore this error when it occurs. Please post some code…

    Anders

    #4016
    Author Image
    Sumit Goyal
    Participant

    Ya 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();
    }

    #4017
    Author Image
    Sumit Goyal
    Participant

    Hi 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.

    #4019
    Author Image
    Sumit Goyal
    Participant

    Hi 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.

    #4021
    Author Image
    Anders Søborg
    Keymaster

    Hi

    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

    #4024
    Author Image
    Sumit Goyal
    Participant

    Yes. 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.

    #4025
    Author Image
    Anders Søborg
    Keymaster

    Hi

    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

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Posted in

Make a donation