-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
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");
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels