Git Product home page Git Product logo

monoev3's People

Contributors

anderssoborg avatar andrewkostousov avatar b-straub avatar cs42 avatar larsjep avatar oberon00 avatar stepienj avatar stochholm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monoev3's Issues

Crash with invalid LCD pixel checks (fix included)

LCD screen size is 178x128 pixels, valid values MUST be 0-177/0-127, not 0-178/0-128!
Drawing a line/rectangle beyond screen limits no longer crashes.
MonoBrickFirmware.Display.EV3Lcd.cs

protected bool IsPixelInLcd(Point pixel)
{
  return (pixel.X >= 0) && (pixel.Y >= 0) && (pixel.X < width) && (pixel.Y < height);
}
protected bool IsPixelInLcd(int x, int y)
{
 return (x >= 0) && (y >= 0) && (x < width) && (y < height);
}

Same EV3 simulator: EV3MonoBrickSimulator.Stub.LcdStub.cs

// new help method
bool IsPixelInLcd(int x, int y)
{
 return (x >= 0) && (y >= 0) && (x < Width) && (y < Height);
}
public bool IsPixelSet(int x, int y)
{
 if (!IsPixelInLcd(x, y)) return false; // boundary check
 int index = GetIndex(x, y);
 return (Marshal.ReadInt32( IntPtr.Add (lcdBuffer.Pixels, index)) & 0x00ffffff) == 0x000000;
}
public void SetPixel(int x, int y)
{
 if (!IsPixelInLcd(x, y)) return; // boundary check

 int index = GetIndex(x, y);
 Int32 oldValue = Marshal.ReadInt32( IntPtr.Add (lcdBuffer.Pixels, index));
 Int32 newValue = (int)(oldValue & 0xff000000);
 Marshal.WriteInt32 (IntPtr.Add (lcdBuffer.Pixels, index), newValue);
}
public void ClearPixel(int x, int y)
{
 if (!IsPixelInLcd(x, y)) return; // boundary check
 int index = GetIndex(x, y);
 int backGroundValue = Marshal.ReadInt32( IntPtr.Add (backGroundPixBuffer.Pixels, index));
 int oldValue = Marshal.ReadInt32( IntPtr.Add (lcdBuffer.Pixels, index));
 int newValue = (int)(oldValue & 0xff000000) | (int)(backGroundValue & 0x00ffffff);
 Marshal.WriteInt32 (IntPtr.Add (lcdBuffer.Pixels, index), newValue);
}

Gyro sensor works only in port 1

When gyro sensor is connected to another port programs hangs in gyrosensor constructor.
Code to reproduce (sensor in port 2):

        public static void Main (string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent (false);
            GyroMode[] modes = {GyroMode.Angle, GyroMode.AngularVelocity};
            int modeIdx = 0;
            ButtonEvents buts = new ButtonEvents ();
            var gyro = new GyroSensor(SensorPort.In2, GyroMode.Angle);
            LcdConsole.WriteLine("Use gyro on port 2");
            LcdConsole.WriteLine("Up read value");
            LcdConsole.WriteLine("Down rotation count");
            LcdConsole.WriteLine("Left reset");
            LcdConsole.WriteLine("Enter change mode");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => { 
                terminateProgram.Set ();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine ("Gyro sensor: " + gyro.ReadAsString());
            };
            buts.EnterPressed += () => { 
                modeIdx = (modeIdx+1)%modes.Length;
                gyro.Mode = modes[modeIdx];
                LcdConsole.WriteLine("Mode: " + modes[modeIdx]);
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine ("Rotation count: " + gyro.RotationCount());
            };
            buts.LeftPressed += () => {
                LcdConsole.WriteLine ("Reset");
                gyro.Reset();
            };
            terminateProgram.WaitOne ();  
        }

Lcd.IsPixelSet() does not work properly.

To fix requires to change the first line of the function from
int index = (x / 8) + y * 23;
to
int index = (x / 8) + y * bytesPrLine

(see SetPixel for details);

Mindsensors' GlideWheel sensor (and possibly other sensors from MS) doesn't work

I implemented class for data collection from Mindsensors' GlideWheel, datasheet is here.

However, the ReadRegister(bool register, int length) is returns byte[] which consiststs of first byte containing register number equivalent to the first argument of ReadRegister() and the rest of bytes contain zeroes.

I suppose this is a monoev3 related bug since:

  • The physical sensor works in EV3 graphical SDK as expected
  • Other manufacturers' sensors work on tested EV3 as expected (tested with Hi-Technic Gyro and Lego Color sensor)
  • Other users are having this issue as well with other Mindsensors' sensors

Code including Main() for testing purposes follows:

using System;
using MonoBrickFirmware;
using MonoBrickFirmware.Display.Dialogs;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.Movement;
using MonoBrickFirmware.Sensors;
using System.Threading;
using System.Collections;
using MonoBrickFirmware.UserInput;

namespace MonoBrickHelloWorld
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            EventWaitHandle stopped = new ManualResetEvent (false);
            MindsensorsAngleSensor NewSensor = new MindsensorsAngleSensor(SensorPort.In1);
            HiTecGyroSensor gyro = new HiTecGyroSensor(SensorPort.In2);
            NewSensor.ResetAngle();
            ButtonEvents buts = new ButtonEvents ();

            buts.EscapePressed += () => { 
                stopped.Set ();
            };

            buts.EnterPressed += () => {
                LcdConsole.WriteLine(Convert.ToString(NewSensor.ReadAngle()));
                LcdConsole.WriteLine(Convert.ToString(gyro.ReadAngularAcceleration()));
            };

            stopped.WaitOne ();
        }
    }

    public class MindsensorsAngleSensor : I2CSensor
    {
        internal enum GlideWheelRegister : byte
        {
            ResetCommand = (byte)'r', Command = 0x41, Angle = 0x42, RAW = 0x46, RevolutionsPerMinute = 0x4A
        };

        public MindsensorsAngleSensor (SensorPort Port) : base (Port, (byte)0x30, I2CMode.LowSpeed9V)
        {
            base.Initialise();
        }

        private static int byte4toInt(byte[] b){
            return (int)b[0] + ((int)b[1] << 8) + ((int)b[2] << 16) + ((int)b[3] << 32); 
        }

        public void ResetAngle()
        {
            byte[] BytesToWrite = {(byte)0};
            BytesToWrite[0] = (byte)GlideWheelRegister.ResetCommand;
            WriteRegister((byte)GlideWheelRegister.Command, BytesToWrite);
            return;
        }

        public int ReadAngle ()
        {
            return byte4toInt(ReadRegister((byte)GlideWheelRegister.Angle, 4));
        }

        public int ReadRAW ()
        {
            return byte4toInt(ReadRegister((byte)GlideWheelRegister.RAW, 4));
        }

        public override string ReadAsString()
        {
            return("Angle: " + Convert.ToString(ReadAngle()) + " RAW: " + Convert.ToString(ReadRAW()));
        }

        public override string GetSensorName()
        {
            return "Mindsensors GlideWheel";
        }

        public override int NumberOfModes()
        {
            return 1;
        }

        public override void SelectNextMode()
        {
            return;
        }

        public override void SelectPreviousMode()
        {
            return;
        }

        public override string SelectedMode()
        {
            return ("Mode 1");
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.