mortezabarzkar / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Lego NXT HiTechnic color and compass sensor #193

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have written a function to read the HiTechnic compass sensor data

I have written a function to read the HiTechnic color sensor data

---
The code has to be added in 'Robotics.Lego/NXTBrick.cs'

Original issue reported on code.google.com by bartribb...@gmail.com on 29 Mar 2011 at 1:29

Attachments:

GoogleCodeExporter commented 8 years ago
I have a problem guy... When i paste and rebuild only HiTechnic Color sensor, I 
get a error message 

Error occured in NXT brick. Error code: 221

On line 1001 in NXTBrick.cs

Any solution in near time?

Original comment by jad...@gmail.com on 29 Mar 2011 at 3:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
still not working... There is my source code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Robotics.Lego;

namespace robotic_ridic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        NXTBrick kostka = new NXTBrick();
        int i;
        int r, g, b;
        NXTBrick.MotorState motorState = new NXTBrick.MotorState();

        private void Form1_Load(object sender, EventArgs e)
        {

            kostka.Connect("COM16");
            motorState.Power = 70;
            motorState.TurnRatio = 150;
            motorState.Mode = NXTBrick.MotorMode.On;
            motorState.Regulation = NXTBrick.MotorRegulationMode.Speed;            
            motorState.RunState = NXTBrick.MotorRunState.Running;
            motorState.TachoLimit = 0;
            kostka.SetSensorMode(NXTBrick.Sensor.Fourth, NXTBrick.SensorType.Lowspeed, NXTBrick.SensorMode.Raw);
            timer1.Start();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            kostka.SetSensorMode(NXTBrick.Sensor.Fourth, NXTBrick.SensorType.Lowspeed, NXTBrick.SensorMode.Raw);
            kostka.ReadHiTechnicColorSensor(NXTBrick.Sensor.Fourth, ref i, ref r, ref g, ref b);

            label1.Text = i.ToString();
            //if (i < 12)
            //{
            //    motorState.Power = 0;
            //    kostka.SetMotorState(NXTBrick.Motor.A, motorState);
            //    kostka.SetMotorState(NXTBrick.Motor.C, motorState);
            //}
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            motorState.Power = 0;
            kostka.SetMotorState(NXTBrick.Motor.A, motorState);
            kostka.SetMotorState(NXTBrick.Motor.C, motorState);
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString() == "w")
            {
                motorState.Power = 100;
                kostka.SetMotorState(NXTBrick.Motor.A, motorState);
                kostka.SetMotorState(NXTBrick.Motor.C, motorState);
            }
            else if (e.KeyChar.ToString() == "s")
            {
                motorState.Power = -100;
                kostka.SetMotorState(NXTBrick.Motor.A, motorState);
                kostka.SetMotorState(NXTBrick.Motor.C, motorState);
            }
            else if (e.KeyChar.ToString() == "a")
            {
                motorState.Power = -100;
                kostka.SetMotorState(NXTBrick.Motor.A, motorState);

            }
            else if (e.KeyChar.ToString() == "d")
            {
                motorState.Power = -100;
                kostka.SetMotorState(NXTBrick.Motor.C, motorState);

            }

        }

    }
}

I am using recompiled AForge.Robotics.Lego with your code... When i am use it 
as only a plain method in this code, i'm getting error 221 on this line: 
LsGetStatus(MySensor, out intReady);

Please help me with thi, because this is solution withou Lego Software 
dependency.

Original comment by jad...@gmail.com on 29 Mar 2011 at 6:34

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Oh thank you very much, i test it tomorrow... I going to bed...

Thanks...

Original comment by jad...@gmail.com on 29 Mar 2011 at 7:14

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Ok, and intColor, R,G and B is output, right?

Original comment by jad...@gmail.com on 31 Mar 2011 at 5:54

GoogleCodeExporter commented 8 years ago
yes indeed. Two reasons you can have problems as before.
- It is not the correct sensor attached to the port
- The firmware is not recent enough.

Original comment by bartribb...@gmail.com on 31 Mar 2011 at 10:00

GoogleCodeExporter commented 8 years ago
And did you mean this sensor?? 
http://www.active-robots.com/products/mindstorms4schools/nxt-accessories/lego-co
lour-sensor.jpg

Original comment by jad...@gmail.com on 31 Mar 2011 at 3:15

GoogleCodeExporter commented 8 years ago
No, the function says 'HiTechnic' color sensor.
http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NCO1038

I have a RGB Lego sensor as yours here at home now, so I let you know what 
function you have to use.

Original comment by bartribb...@gmail.com on 31 Mar 2011 at 3:50

GoogleCodeExporter commented 8 years ago
:-D oh my mistake sorry... And any solution for my RGB sensor?? I wanna use it 
to scan surfaces...

Original comment by jad...@gmail.com on 31 Mar 2011 at 3:51

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
If you want, I will help you... I am good in C#

Original comment by jad...@gmail.com on 31 Mar 2011 at 5:57

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Ok...

Original comment by jad...@gmail.com on 31 Mar 2011 at 6:16

GoogleCodeExporter commented 8 years ago
Just wanted to check the status of this code and testing before making any 
actions related to merging.

Does it work? If it requires any updated NXT firmware or something else, is it 
mentioned in XML documentation (so users could read it and don't bother with 
questions if they have different setup, version, etc)?

Original comment by andrew.k...@gmail.com on 4 Apr 2011 at 10:24

GoogleCodeExporter commented 8 years ago
The original code works, but I want to write more code to support extra sensors 
(Lego and HiTechnic) later this week, so maybe I better can send an update 
later this week before you integrate it.

I'll also write extra xml documentation.

First I want to learn how the subversion system works, what makes the 
implementation easier for you.

Original comment by bartribb...@gmail.com on 4 Apr 2011 at 1:50

GoogleCodeExporter commented 8 years ago
Any update on this?

Original comment by andrew.k...@gmail.com on 20 Apr 2011 at 6:22

GoogleCodeExporter commented 8 years ago
ReadHiTechnicColorSensor: ready
ReadHiTechnicCompassSensor: ready
ReadHiTechnicAccelerationTiltSensor: ready
ReadHiTechnicGyroSensor: ready
ReadHiTechnicIRSeeker2AC: ready, not tested yet
ReadHiTechnicIRSeeker2DC: ready, not tested yet
SetHiTechnicIRSeekerMode: To do

If this set of functions are ready I upload the code. Probably within 24 hours!

Original comment by bartribb...@gmail.com on 20 Apr 2011 at 7:36

GoogleCodeExporter commented 8 years ago
OK. If you aim to send patch file, then please update your copy, since there 
was recent change in the NXTBrick class.

Original comment by andrew.k...@gmail.com on 20 Apr 2011 at 8:18

GoogleCodeExporter commented 8 years ago
I added:
- Extra sensor modes
- ReadHiTechnicColorSensor
- ReadHiTechnicCompassSensor
- ReadHiTechnicAccelerationTiltSensor

Original comment by bartribb...@gmail.com on 21 Apr 2011 at 10:41

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 5 May 2011 at 12:28

GoogleCodeExporter commented 8 years ago
>> intAngle = Convert.ToInt32(ReadValues[0]) * 2 + 
Convert.ToInt32(ReadValues[1]);
Where did this come from?

should it be something like:
intAngle = ( Convert.ToInt32(ReadValues[0]) << 8 ) + 
Convert.ToInt32(ReadValues[1]);
or
intAngle = ( Convert.ToInt32(ReadValues[0]) * 256 ) + 
Convert.ToInt32(ReadValues[1]);

Never seen such strange conversion of 2 bytes into ushort. Is it according to 
HiTechnic docs?

Original comment by andrew.k...@gmail.com on 6 May 2011 at 1:38

GoogleCodeExporter commented 8 years ago
NXTBrick class is extended with 3 extra method: ReadHiTechnicColorSensor(), 
ReadHiTechnicCompassSensor() and ReadHiTechnicAccelerationTiltSensor(), which 
read HiTechnic's color, compass and acceleration sensors.

Committed in revision 1454. Will be released in version 2.2.0.

NOTE: Status is set to Pending because would like to clarify comment #23.

Original comment by andrew.k...@gmail.com on 6 May 2011 at 2:02

GoogleCodeExporter commented 8 years ago
Heading = (two degree heading *2) + one degree adder.

Source: http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034

Original comment by bartribb...@gmail.com on 6 May 2011 at 2:52

GoogleCodeExporter commented 8 years ago
OK, seems to be fine. Hopefully you did a test ;)

Original comment by andrew.k...@gmail.com on 6 May 2011 at 3:03

GoogleCodeExporter commented 8 years ago
Yes, I did ;-).

Original comment by bartribb...@gmail.com on 7 May 2011 at 7:12

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 28 Jul 2011 at 9:45

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 10 Aug 2011 at 9:31