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

HomeForumsMonoBrick EV3 FirmwareMindsensors' GlideWheel sensor (and possibly other sensors from MS) doesn't work

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #4948
    Author Image
    Filip Kirschner
    Participant

    I submitted this to github as a bug as well.

    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:

    c#
    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");
    		}
    	}
    }
    
    #4949
    Author Image
    Anders Søborg
    Participant

    Hi there

    Try to read 8 bytes instead of four. I found that some sensors only supports read 8 bytes at a time. If this does not work try to read a single byte.

    /Anders

    #4950
    Author Image
    Anders Søborg
    Participant

    Hi there

    I just had a look at this code and it seems that he is using a readAndWrite. Have you tried this?

    /Anders

    #4952
    Author Image
    Andreas Boerzel
    Participant

    Hi Anders,
    thank you for your tip and I would like to try this, but I can’t find a corresponding method for

    if (!writeI2C(link, MSANG_I2CRequest, MSANG_I2CReply, 4))
    return -1;  

    in the UnixDevice class. I don’t have much unix knowledge, is there a corresponding method for ‘writeI2C’ in the Libc library available?

    Thanks,
    Andreas

    #4955
    Author Image
    Anders Søborg
    Keymaster

    No need to look in the UnixDevice class. In the I2c class there you will a WriteAndRead method.

    /Anders

    #4958
    Author Image
    Anders Søborg
    Participant

    Hi

    Did you get this working?

    /Anders

    #4960
    Author Image
    Andreas Boerzel
    Participant

    Unfortunately it does not work yet! The WriteAndRead-method of the I2CSensor class doesn’t work with the AbsoluteIMU sensor. It seems for me that the AbsoluteIMU sensor has a different command-structure. I also tried to port the LeJOS-implementation of the AbsoluteImuAgcMindSensor.java class to MonoBrick, but unfortunately the Libc lowlevel methods are not compatible with them of LeJOS. So I contacted the mindsensors support, but at the moment I’m helpless!

    #4961
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    Could you please post the code you used for WriteAndRead method what is your input to this function?

    /Anders

    #4962
    Author Image
    Anders Søborg
    Participant

    Hi there

    The folks over at mindsensors.com are kind enough to send me a sample for me to work with…keep me posted if you make any progress and I will do the same.

    /Anders

    #4967
    Author Image
    Andreas Boerzel
    Participant

    Hi,
    I have good news!
    At the weekend I updated my sd-card to the latest image and got the latest version from the master-branch, and now the AbsoluteIMU-ACG sensor works with the implementation I added in the tread How to use AbsoluteIMU-ACG sensor?.

    Maybe the problem was only that I used an old sd.card image?!

    #4974
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    Great. Now remember to add your code to the Github using a pull request..

    Anders

    #4975
    Author Image
    Andreas Boerzel
    Participant

    Hi!
    Yes of course, I will add the code! But I still need few days to refactor the code before I publish it.

    #4988
    Author Image
    Andreas Boerzel
    Participant

    Hi,
    I have implemented the sensor class AbsoluteIMU_ACGSensor.cs, that works with the Mindensors AbsoluteIMU-ACG sensor and created a pull request at Github. I also added a the test sample AbsoluteIMU_ACGSensorExample.cs.

    Andreas

    #4989
    Author Image
    Anders Søborg
    Keymaster

    Hi Andreas

    Great I will have a look at it when I get the time…

    Anders

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

You must be logged in to reply to this topic.

Posted in

Make a donation