View unanswered posts | View active topics It is currently Fri Apr 18, 2014 6:14 pm






Reply to topic  [ 6 posts ] 
Help with Hi Technic Sensor Multiplexer - Status word 
Author Message
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Help with Hi Technic Sensor Multiplexer - Status word
Hi

We're using a driver that we wrote that comes from a modified version of Xander's code for our HiTechnic Sensor Multiplexer. The purpose of the driver is to make it more similar to the standard RobotC sensorValue array functionality. We're really close to getting it to work completely, but have a few more questions. We will be more than happy to post it once we get the final bugs out of it...

The first question relates to the way the multiplexer reports it's status. The driver code says that the following bits are used to indicate the following status within this word:

Bit 00 = Battery Fault
Bit 01 = Busy (Auto Detect in progress)
Bit 02 = SMUX is Halted
Bit 03 = SMUX has Error.

What we're seeing is that the Busy status is on most of the time. Does anyone know for sure that the Busy state indicates "AutoDetect" or could it just mean "Scanning In Progress"? The way we read the documentation indicates that the SMUX scans the four ports once it's put into run mode... could that run mode scanning be considered "Busy" too? Or is there a problem with the code?

The second question relates to the Compass Sensor with the SMUX. Whenever we activate a light sensor (on a different port on the same mux) the compass sensor reads incorrectly for a period of time (like 180 degrees off). Since we have to halt the SMUX in order to activate the sensor, when we restart it, is there something that we should do to keep the compass sensor reporting correctly?

Thanks in advance!


Wed Mar 31, 2010 3:18 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Help with Hi Technic Sensor Multiplexer - Status word
Since I have absolutely no idea what changes you've made to the driver, I can't really tell what is wrong with it. The busy status means that the sensor is scanning the sensors.

The status should read 0 when there are no issues and the SMUX is reading data from the sensors attached to it.

- 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]


Wed Mar 31, 2010 3:21 am
Profile WWW
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Help with Hi Technic Sensor Multiplexer - Status word
Hi Xander,

Sorry, actually, I wasn't asking about the code that I wrote. I was more wondering about the status that is returned from the I2C communication. In your driver the .status in the structure is written during the sending of commands. I'm wondering about the status that comes from word 21 on the SMUX.

<Snipped out a bunch of stuff written in error>
Alan

PS. Using your code (which is excellent by the way) is a bit more involved than what we're aiming for. Since we're only using simple sensors that return only simple single values, we wanted a simpler method of handling it from within the regular code. The routine I'm writing is just a scanner that reads the current values of the sensors attached to the MUX. It uses the functions from your common.h file to do that. (And yep, you get full credit in the new section and everywhere it makes sense to do so.


Wed Mar 31, 2010 3:38 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Help with Hi Technic Sensor Multiplexer - Status word
alanlevezu wrote:
In fact, when I read through the code, it (the .status in your structure) actually seemed to be written by two different things... and they appear to overwrite each other.


I keep track of the current state of the command sequence in the struct, this is not based on the status byte from register 0x21 :) It just allows me to make sure that specific commands have been issued before other ones. For example, in order for me to be able to read from the sensor, it needs to be in running mode, not busy or halted. Rather than issuing time consuming I2C commands all the time to request this info, I keep track of this info in a struct, one for each possible SMUX.

Code:
byte HTSMUXreadStatus(tSensors link) {
  memset(HTSMUX_I2CRequest, 0, sizeof(tByteArray));

  HTSMUX_I2CRequest.arr[0] = 2;               // Message size
  HTSMUX_I2CRequest.arr[1] = HTSMUX_I2C_ADDR; // I2C Address
  HTSMUX_I2CRequest.arr[2] = HTSMUX_STATUS;

  if (!writeI2C(link, HTSMUX_I2CRequest, 1))
    return -1;

  if (!readI2C(link, HTSMUX_I2CReply, 1))
    return -1;

  return HTSMUX_I2CReply.arr[0];
}


In the readStatus() function I don't update the struct at all. The only reason I have this function in here is for future enhancements :) I have some plans for the SMUX driver to handle additional error conditions.

Quote:
PS. Using your code (which is excellent by the way) is a bit more involved than what we're aiming for. Since we're only using simple sensors that return only simple single values, we wanted a simpler method of handling it from within the regular code. The routine I'm writing is just a scanner that reads the current values of the sensors attached to the MUX. It uses the functions from your common.h file to do that. (And yep, you get full credit in the new section and everywhere it makes sense to do so.


You could just use the HTSMUXreadAnalogue() and HTSMUXreadPort() calls, without all the other drivers. You should be careful when using asynchronous calls, btw, these functions are not thread safe.

Regards,
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]


Wed Mar 31, 2010 3:55 am
Profile WWW
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Help with Hi Technic Sensor Multiplexer - Status word
Yep... I screwed up in writing that you overwrote... I did that when re-doing your code... (I thought I cleared it out of the forum fast enough that you wouldn't see my mess-up... dang-it you're just too quick!

I'm sending you the code so you can take a look at it if you want (it's OK to just toss it into the garbage too).

There won't be any duplicate calls - I realized they weren't thread safe and build in some handlers to deal with that... All the 'external to the driver' calls should go through a different type of function that just sets flags and moves values from a buffered area.

Alan

PS - by the way... even though the MUX reports the battery is OK, when it gets low, the compass stops working... (That's the issue I noted as my second problem - Just needed a new battery.) I noted that the touch sensor reports different zero (non-pressed) values depending on the battery voltage as well - Maybe I'll use that as an indicator!


Wed Mar 31, 2010 4:32 am
Profile
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Hi Technic Sensor Multiplexer - Simplified Driver
I've attached the current version of my driver for the Sensor Multiplexer.

It is NOT intended to replace Xander's excellent driver, but is designed if you want something simple. In fact it only works with LEGO sensors and the Compass sensor. A lot of the code is based on Xander's driver functions and he gets the credit for doing all the research and work to make it possible.

The file "SMUX_Driver.c" file should be included at the top of your program (similar to the Tetrix Joystick.c file) and any sensors defined after that - the MUX is scanned automatically on a repeating basis, based on the sensors that are actually used.

The zip file has a readme and a sample program.


Attachments:
SMUX Simple Driver.zip [10.15 KiB]
Downloaded 344 times
Wed Mar 31, 2010 12:10 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.