larsjep / monoev3 Goto Github PK
View Code? Open in Web Editor NEWLego mindstorms EV3 C# library
Home Page: http://www.monobrick.dk/software/ev3firmware/
Lego mindstorms EV3 C# library
Home Page: http://www.monobrick.dk/software/ev3firmware/
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);
}
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 ();
}
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);
Also add forum support
Rename MonoBrick to MonoBrick Communication library
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:
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");
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.