View unanswered posts | View active topics It is currently Mon Dec 16, 2019 9:14 am






Reply to topic  [ 8 posts ] 
EV3 - Hitechnic Colour Sensor Code Failures 
Author Message
Novice
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 62
Location: Tasmania, the Land Down Under, the Land Downunder!
Post EV3 - Hitechnic Colour Sensor Code Failures
Hi,

I'm having an issue with using a Hitechnic Colour Sensor on the EV3. I am getting the following error for the Red RGB Value:

Debug STream:
Code:
Red: 1077687276  Green:  28  Blue:   0


Code:
Code:
/**
* hitechnic-colour-v2.h provides an API for the HiTechnic Color V2 Sensor.  This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
* - 0.2: More comments
* - 0.3: Removed common.h from includes
*
* Credits:
* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER

* Xander Soldaat (xander_at_botbench.com)
* 20 February 2011
* version 0.3
*/

#include "hitechnic-colour-v2.h"

task main () {
   string _tmp;
   long Red, Green, Blue;
//   clearDebugStream();

   displayCenteredTextLine(0, "HiTechnic");
   displayCenteredBigTextLine(1, "Color V2");
   displayCenteredTextLine(3, "Test 1");
   displayCenteredTextLine(5, "Connect sensor");
   displayCenteredTextLine(6, "to S1");
   sleep(2000);

   // Create struct to hold sensor data
   tHTCS2 colorSensor;

   // Initialise and configure struct and port
   initSensor(&colorSensor, S1);

   eraseDisplay();
   while (true)
   {
      // Read the currently detected colour and RGB/HSV data from the sensor
      if (!readSensor(&colorSensor)) {
         displayTextLine(4, "ERROR!!");
         sleep(2000);
         stopAllTasks();
      }

      displayCenteredTextLine(0, "Color: %d", colorSensor.color);
      displayCenteredBigTextLine(1, "R  G  B");

      Red = colorSensor.red;
      Green = colorSensor.green;
      Blue = colorSensor.blue;

      eraseRect(0,10, 99, 41);
      fillRect( 0, 10, 30, 10 + (Red+1)/8);
      fillRect(35, 10, 65, 10 + (Green+1)/8);
      fillRect(70, 10, 99, 10 + (Blue+1)/8);
      stringFormat(_tmp, " %3d   %3d", Red, Green);
      displayTextLine(7, "%s   %3d", _tmp, Blue);

      writeDebugStreamLine("Red: %3d  Green: %3d  Blue: %3d", _tmp, colorSensor.red, colorSensor.green, colorSensor.blue);

      sleep(100);
   }
}


I've tried separate EV3's and Sensors with identical errors. I have current RobotC and 3rd Party Sensor releases.

Any ideas greatly appreciated....

_________________
regards

Ray (Sparra) Mc


Image


My Blog: www.LegoMindstormsRobots.com
Lot's of Robotic Projects with FREE Code and Instructions....


Last edited by sparramc on Fri Apr 10, 2015 8:50 am, edited 1 time in total.



Fri Apr 10, 2015 6:56 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: EV3 - Hitechnic Colour Sensor Code Failurs
Try replacing the readSensor() function with this one:
Code:
bool readSensor(tHTCS2Ptr htcs2Ptr)
{
  memset(htcs2Ptr->I2CData.request, 0, sizeof(htcs2Ptr->I2CData.request));

  if (htcs2Ptr->smux)
  {
    if (!HTSMUXreadPort(htcs2Ptr->smuxport, htcs2Ptr->I2CData.reply, 4, HTCS2_COLNUM_REG))
      return false;
  }
  else
  {
    // Read all of the data available on the sensor
    htcs2Ptr->I2CData.request[0] = 2;                    // Message size
    htcs2Ptr->I2CData.request[1] = htcs2Ptr->I2CData.address; // I2C Address
    htcs2Ptr->I2CData.request[2] = HTCS2_OFFSET + HTCS2_COLNUM_REG;
    htcs2Ptr->I2CData.replyLen = 4;
    htcs2Ptr->I2CData.requestLen = 2;

    if (!writeI2C(&htcs2Ptr->I2CData))
      return false;
  }

  // Populate the struct with the newly retrieved data
  htcs2Ptr->color = htcs2Ptr->I2CData.reply[0];
  htcs2Ptr->red    = (short)htcs2Ptr->I2CData.reply[1];
  htcs2Ptr->green = (short)htcs2Ptr->I2CData.reply[2];
  htcs2Ptr->blue   = (short)htcs2Ptr->I2CData.reply[3];
  RGBtoHSV(htcs2Ptr->red, htcs2Ptr->green, htcs2Ptr->blue, &htcs2Ptr->hue, &htcs2Ptr->saturation, &htcs2Ptr->value);

  return true;
}


= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 10, 2015 7:13 am
Profile WWW
Novice
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 62
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: EV3 - Hitechnic Colour Sensor Code Failurs
Hi Xander,

That code is exactly the same as what is in in my original "hitechnic-colour-v2.h" driver file.

Unfortunately I brought an EV3 home, but forgot to bring a HT Colour Sensor with me.

I currently have the majority of my EV3 gear down the road at Brixhibition, Launceston, Tasmania, for the weekend. I will test it in the morning again though.

The weird thing is that the sensor was reading the RGB Readings perfectly yesterday afternoon. Then last night when I went back to fine tune the code, the wheels fell off... And to make things worse I accidentally overwrote the earlier code before I realized what was happening.

I was also switch between different Robots, fine tuning them as well which didn't help either in a mad rush getting things organised..

_________________
regards

Ray (Sparra) Mc


Image


My Blog: www.LegoMindstormsRobots.com
Lot's of Robotic Projects with FREE Code and Instructions....


Fri Apr 10, 2015 8:50 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: EV3 - Hitechnic Colour Sensor Code Failures
The code is not the same, look more closely.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 10, 2015 9:06 am
Profile WWW
Novice
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 62
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: EV3 - Hitechnic Colour Sensor Code Failures
Will do. Sorry, long Day, and those-little-grey-cells of mine are protesting after today's workout...

_________________
regards

Ray (Sparra) Mc


Image


My Blog: www.LegoMindstormsRobots.com
Lot's of Robotic Projects with FREE Code and Instructions....


Fri Apr 10, 2015 9:13 am
Profile WWW
Novice
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 62
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: EV3 - Hitechnic Colour Sensor Code Failures
Hi Xander,

Still no luck. Please see attachments.


Attachments:
ColourTest2.c [1.87 KiB]
Downloaded 366 times
hitechnic-colour-v2.h [6.78 KiB]
Downloaded 415 times

_________________
regards

Ray (Sparra) Mc


Image


My Blog: www.LegoMindstormsRobots.com
Lot's of Robotic Projects with FREE Code and Instructions....
Fri Apr 10, 2015 8:45 pm
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: EV3 - Hitechnic Colour Sensor Code Failures
It's a bug in your code:
Code:
writeDebugStreamLine("Red: %3d  Green: %3d  Blue: %3d", _tmp, colorSensor.red, colorSensor.green, colorSensor.blue);

should be:
Code:
writeDebugStreamLine("Red: %3d  Green: %3d  Blue: %3d", colorSensor.red, colorSensor.green, colorSensor.blue);

You were printing out a string as a decimal.
= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Apr 11, 2015 1:22 am
Profile WWW
Novice
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 62
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: EV3 - Hitechnic Colour Sensor Code Failures
Thank you Xander.

I will give it a try..

_________________
regards

Ray (Sparra) Mc


Image


My Blog: www.LegoMindstormsRobots.com
Lot's of Robotic Projects with FREE Code and Instructions....


Wed Apr 15, 2015 12:26 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.