Page 3 of 7

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 21:47
by mightor
I just tested it with my ROBOTC test program for this specific sensor and it works fine. Do you still have your copy of ROBOTC somewhere? If you do, download my driver suite and try the DPRESS-test1.c program and tell me if it works for you. At least then you can rule out the sensor.

Oh and make sure it's 2.26.1

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 21:54
by HaWe
I don't use RobotC any more. Guess why.
But if your NXC program works for your sensor and not for mine, it's clear that my sensor is defective.

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 22:04
by mightor
It gave me a value around the same one as yours, it doesn't really vary that much.

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 22:14
by mightor
This should work:

Code: Select all

float DPRESS_VREF = 4.85;
int val;
float pressure;
float Vout = 0.0;

task main(){
  SetSensorType(S2, SENSOR_TYPE_TOUCH);
  SetSensorMode(S2, SENSOR_MODE_RAW);

  while(true) {
    val = SensorRaw(S2);
    Vout = ((val * DPRESS_VREF) / 1023);
    pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;
    NumOut(0, LCD_LINE1, val);

    NumOut(0, LCD_LINE2, pressure);

    Wait(10);
  }
}
Your formula was all wrong. This is taken directly from my ROBOTC driver (the math) and I get identical values to what I am seeing in ROBOTC.

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 09:37
by HaWe
Thanx!
But I had only read the raw values, the calulated values by the formula I had not observed at all.
With your program the values are not shown correctly (overlapping numbers)


With your latest program (enhanced output) I get (plugged to the pin on the back)
no press....full press
37 (33) ... 80
-1.0 (-2.1)..10.4

after some minutes:
37 ... 100
-1.0...15.7

- But again the range of the RAW values seems far too narrow (difference of just about 40-100 of all 0-1023)
- What kind of physical unit is the calculated float pressure value? it should be hPa or bar (=kg/cm2).

Code: Select all

#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
float DPRESS_VREF = 4.85;
int val;
float pressure;
float Vout = 0.0;

task main(){
  SetSensorType(S2, SENSOR_TYPE_TOUCH);
  SetSensorMode(S2, SENSOR_MODE_RAW);
  while(true) {
     val = SensorRaw(S2);

     Vout = ((val * DPRESS_VREF) / 1023);
     pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;

     printf1(0, LCD_LINE1, "%5d", val);
     printf1(0, LCD_LINE2, "%5.1f", pressure);
     Wait(10);
  }
}

(aside from this, your "2-line formula"
Vout = ((val * DPRESS_VREF) / 1023);
pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;
is unnecessarily complicated: DPRESS_VREF "kürzt sich heraus" ("shorts out"? don't know the English term) if you substitute Vout of the 1st equation into the 2nd) :

pressure= ((val/1023) - 0.04) / 0.00369
<=>
pressure= ((val/1023) - 0.04) * 271

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 11:28
by mightor
You can optimise when you get it working, any time before then is unnecessary.

This from my driver: It's for the 250kPa sensor. There's a 500kPa sensor as well.

Code: Select all

/**
 * Read the pressure in kiloPascals\n
 * Note: This function is for the dPressure 250
 * @param link the dPressure Sensor port number
 * @param pressure the pressure in kiloPascals
 * @return true if no error occured, false if it did
 */
bool DPRESSreadPress250kPa(tSensors link, float &pressure) {
  float Vout = 0.0;

  int val = 0;

  // dPressure sensor type must absolutely be set to sensorAnalogInactive
  if (SensorType[link] != sensorAnalogInactive)
    return false;

  // Pressure is calculated using Vout = VS x (0.00369 x P + 0.04)
  // => P
  // Where Vs is assumed to be equal to around 4.85 on the NXT

  // Get raw sensor value
  val = SensorValue[link];

  // Calculate Vout
  Vout = ((val * DPRESS_VREF) / 1023);

  pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;
  return true;
}
This is for the 500kPa sensor:

Code: Select all

/**
 * Read the pressure in kiloPascals\n
 * Note: This function is for the dPressure 500
 * @param link the dPressure 500 Sensor port number
 * @param pressure the pressure in kiloPascals
 * @return true if no error occured, false if it did
 */
bool DPRESSreadPress500kPa(tSensors link, float &pressure) {
  float Vout = 0.0;

  int val = 0;

  // dPressure sensor type must absolutely be set to sensorAnalogInactive
  if (SensorType[link] != sensorAnalogInactive)
    return false;

  // Pressure is calculated using Vout = VS x (0.0018 x P + 0.04)
  // => P
  // Where Vs is assumed to be equal to around 4.85 on the NXT

  // Get raw sensor value
  val = SensorValue[link];

  // Calculate Vout
  Vout = ((val * DPRESS_VREF) / 1023);

  pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.0018;
  return true;
}

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 11:56
by HaWe
yes, I didn't want to optimize now, I only wanted to mention. The 2 different formulas (250 and 500 kPa) I already have got.
using the 500kPa driver, I get
RAW: 35...110
Pressure: -3.2...36.4

Code: Select all

#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
float DPRESS_VREF = 4.85;
int val;
float pressure;
float Vout = 0.0;

task main(){
  SetSensorType(S2, SENSOR_TYPE_TOUCH);
  SetSensorMode(S2, SENSOR_MODE_RAW);
  while(true) {
     val = SensorRaw(S2);
     Vout = ((val * DPRESS_VREF) / 1023);
     pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.0018;

     printf1(0, LCD_LINE1, "%5d", val);
     printf1(0, LCD_LINE2, "%5.1f", pressure);
     Wait(10);
  }
}

The point is actually now only the RAW value itself.
1) A range only from about 40 to 100 seems faulty to me. - Do you have a wider range with your equipment?
2) Having to use SENSOR_TYPE_TOUCH seems weird and unlogic to me: it's upside down compared to other analog raw inputs (1023...0 instead of 0...1023) - so why use Touch?
3) why doesn't it work if I'm using SENSOR_TYPE_LIGHT_INACTIVE or SENSOR_TYPE_LIGHT or SENSOR_TYPE_CUSTOM? Why isn't there sth like SENSOR_TYPE_ANALOG_STANDARD or however an unfaked "analog standard sensor" may be called by NXC?
So how actually is the correct Sensor Type? Touch intuitively seems to me that it may be the wrong approach...

if the RAW issues once are resolved - :
4) If you once will calculate a "real pressure value" with your formulas (not-optimized): what physical unit will it have? (Starting from a negative value (-1.0 or -3.2) for "zero pressure" surely is wrong!) - EDIT - resolved:
The standard unit is kPa.
not to forget:
5) which of both is definetly the correct pin for the pressure hose? MiddleLeft or BackRight ? The Dexter documentation is really grottenschlecht.
Image
edit: it's clearly here to see: Image

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 15:03
by mightor
I fail to see how this document http://www.dexterindustries.com/files/d ... al_1.2.pdf is so hard to read.

Image

Secure tubing to the Sensor:
Gauge Pressure: The pressure-port on the sensor is the port on the capacitor-side of the plastic.
Gauge Vacuum: The vacuum-port on the sensor is the port opposite the capacitor-side of the sensor.

Apart from the mis-aligned "e" in the picture, it's about as clear as daylight.

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 15:37
by HaWe
I didn't find this picture - where have you found it? Thx anyway!

so ok, 5 is resolved - 1-4 remaining:
1) A range only from about 40 to 100 seems faulty to me. - Do you have a wider range with your equipment?
2) Having to use SENSOR_TYPE_TOUCH seems weird and unlogic to me: it's upside down compared to other analog raw inputs (1023...0 instead of 0...1023) - so why use Touch?
3) why doesn't it work if I'm using SENSOR_TYPE_LIGHT_INACTIVE or SENSOR_TYPE_LIGHT or SENSOR_TYPE_CUSTOM? Why isn't there sth like SENSOR_TYPE_ANALOG_STANDARD or however an unfaked "analog standard sensor" may be called by NXC?
So how actually is the correct Sensor Type? Touch intuitively seems to me that it may be the wrong approach...

if the RAW issues once are resolved - :
4) If you once will calculate a "real pressure value" with your formulas (not-optimized): what physical unit will it have? (Starting from a negative value (-1.0 or -3.2) for "zero pressure" surely is wrong!) - EDIT - resolved:
The standard unit is kPa.

Re: NXC: can't read Dexter pressure sensor values

Posted: 27 Feb 2011, 16:11
by mightor
The picture is in the user guide, which you can download from the Dexter Industries "downloads" page. I get the feeling you didn't spend all that much time researching this. If you spent less time complaining about the sensor and more time looking stuff up, you'd have less stuff to complain about.

The standard unit is kPa.

The range of the sensor is not relevant, the only relevant thing is, does it give you the correct result after you apply the conversion formula? Just because something doesn't "feel" right, doesn't mean it isn't. Channel your inner scientist and perform some objective tests, rather than relying on your gut feelings. Science doesn't rely on your gut, it relies on fact, everything else is irrelevant.

I have attached the official datasheet for the sensors.

- Xander