Motors not responding

HomeForumsMonoBrick Communication LibraryMotors not responding

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5695
    Author Image
    Hoang Doan
    Participant

    Hello, I am testing 90 deg turn with the gyroscope and I have a problem with the motors’ response. When testing, the motors are reacting on the key presses and the gyro is reading. However, after first few movements, the motors don’t respond anymore (run), but the gyro is reading correctly. The block can be removed by manually spinning the vehicle (breaking the loop). Can you please check what might be the issue?

    Can it be related to this: http://www.monobrick.dk/forums/topic/error-wrong-number-of-bytes-received/ ?

    Thank you very much.

    `
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using MonoBrick.EV3;

    namespace TestEV3
    {
    class Program
    {

    static void Main(string[] args)
    {
    int degParser(string str)
    {
    string[] defString = str.Split(‘ ‘);
    int convDeg = int.Parse(defString[0]);

    return convDeg;
    }

    var ev3 = new Brick<Sensor, Sensor, Sensor, Sensor>(“usb”);

    try
    {
    ev3.Connection.Open();
    ev3.Vehicle.LeftPort = MotorPort.OutA;
    ev3.Vehicle.RightPort = MotorPort.OutD;
    ev3.Sensor4 = new GyroSensor(GyroMode.Angle);

    sbyte speed = 30;
    ConsoleKeyInfo cki;
    Console.WriteLine(“Press T to quit”);

    do
    {
    cki = Console.ReadKey(true); //press a key

    switch (cki.Key)
    {
    case ConsoleKey.W:
    ev3.Vehicle.Forward(speed);

    break;
    case ConsoleKey.S:
    ev3.Vehicle.Backward(speed);

    break;
    case ConsoleKey.D:

    ev3.MotorA.On(speed);
    int currentDegR = degParser(ev3.Sensor4.ReadAsString());

    while (true)
    {

    int deg = degParser(ev3.Sensor4.ReadAsString());
    int diff = deg – currentDegR;
    Console.WriteLine(currentDegR.ToString() + ” | ” + deg.ToString() + ” | ” + diff.ToString());

    if (diff >= 85)
    {
    Console.WriteLine(“STOP STOP STOP ————————————-“);
    ev3.MotorA.Off();
    break;
    }

    }

    break;
    case ConsoleKey.A:

    ev3.MotorD.On(speed);
    int currentDegL = degParser(ev3.Sensor4.ReadAsString());

    while (true)
    {
    int deg = degParser(ev3.Sensor4.ReadAsString());
    int diff = currentDegL – deg;
    Console.WriteLine(currentDegL.ToString() + ” | ” + deg.ToString() + ” | ” + diff.ToString());

    if (diff >= 85)
    {
    ev3.MotorD.Off();
    Console.WriteLine(“STOP STOP STOP ————————————-“);
    break;
    }
    }

    break;
    case ConsoleKey.Spacebar:
    ev3.Vehicle.Off();
    break;

    case ConsoleKey.B:
    Console.WriteLine(ev3.Sensor4.ReadAsString());
    break;
    }
    } while (cki.Key != ConsoleKey.T);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.StackTrace);
    Console.WriteLine(“Error: ” + e.Message);
    Console.WriteLine(“Press any key to end…”);
    Console.ReadKey();
    }
    finally
    {
    ev3.Connection.Close();
    }

    }
    }
    }

    • This topic was modified 4 years, 7 months ago by Author ImageHoang Doan.
    • This topic was modified 4 years, 7 months ago by Author ImageHoang Doan.
    • This topic was modified 4 years, 7 months ago by Author ImageHoang Doan.
    #5699
    Author Image
    Hoang Doan
    Participant

    I think it is a problem with the USB communication library. I have just tested on Bluetooth and it is working just fine.

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

You must be logged in to reply to this topic.

Posted in

Make a donation