ROBOTC.net forums
http://robotc.net/forums/

Hi Technic Accel Sensor
http://robotc.net/forums/viewtopic.php?f=41&t=8268
Page 1 of 1

Author:  AlexJ [ Wed Mar 19, 2014 11:14 am ]
Post subject:  Hi Technic Accel Sensor

I'm fairly new to RobotC and am trying to get readings out of the HiTechnic Accel Sensor.

Since I need to get three different axis out of it, I was looking for pre-made code. Under Sample Programs -> NXT -> 3rd Party Sensors, I found this code:

hitechnic-accelerometer-test1.c

Code:
#pragma config(Sensor, S1,     HTAC,                sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
 * $Id: hitechnic-accelerometer-test1.c 133 2013-03-10 15:15:38Z xander $
 */

/**
 * hitechnic-accelerometer.h provides an API for the HiTechnic Acceleration Sensor.  This program
 * demonstrates how to use that API.
 *
 * Changelog:
 * - 0.1: Initial release
 * - 0.2: Make use of new API calls
 * - 0.3: Better comments
 * - 0.4: Fixed display line (thanks Dave)
 * - 0.5: Removed single axis functions, they're no longer in the driver\n
 *        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 3.59 AND HIGHER.

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

#include "drivers/hitechnic-accelerometer.h"

task main () {
  int _x_axis = 0;
  int _y_axis = 0;
  int _z_axis = 0;

  string _tmp;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Accel");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  while(bSoundActive) EndTimeSlice();

  while (true) {
    eraseDisplay();

    // Read all of the axes at once
    if (!HTACreadAllAxes(HTAC, _x_axis, _y_axis, _z_axis)) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayTextLine(0,"HTAC Test 1");

    // We can't provide more than 2 parameters to nxtDisplayTextLine(),
    // so we'll do in two steps using StringFormat()
    nxtDisplayTextLine(2, "   X    Y    Z");
    StringFormat(_tmp, "%4d %4d", _x_axis, _y_axis);
    nxtDisplayTextLine(3, "%s %4d", _tmp, _z_axis);

    wait1Msec(100);
  }
}

/*
 * $Id: hitechnic-accelerometer-test1.c 133 2013-03-10 15:15:38Z xander $
 */


The code complies, but it doesn't seem to do anything useful. It only looks like a program that outputs text to the screen.

I get the error message from line 55 whenever I run it. I don't know what "HTACredAllAxis()" does. When I comment that entire if-statement out, I only get a screen that reads off all vales as zeros.
I don't see where in the program any of the "_x_axis" "_y_axis" or "_z_axis" variables actually read in numbers.

This code also references "hitechnic-accelerometer.h", but I cannot find this library anywhere in my pre-installed files. I am wondering if that could be part of the problem, but since the code compiles, I assume the program got any information it needed about hitechnic-accelerometer.h.


Any help with this, or suggestions about writing my own code for the accelerometer?

Author:  BurningLights [ Wed Mar 19, 2014 12:20 pm ]
Post subject:  Re: Hi Technic Accel Sensor

AlexJ wrote:
The code complies, but it doesn't seem to do anything useful. It only looks like a program that outputs text to the screen.


That is correct. It is meant as a test program, so that you can see what kind of values you get from the sensor.

AlexJ wrote:
I get the error message from line 55 whenever I run it. I don't know what "HTACredAllAxis()" does. When I comment that entire if-statement out, I only get a screen that reads off all vales as zeros.
I don't see where in the program any of the "_x_axis" "_y_axis" or "_z_axis" variables actually read in numbers.


The axis variables get values put into them by HTACreadAllAxis(). That function gets the latest values from the accelerometer sensor and stores them into the variables you pass into it. The fact that you're always getting the error message means that something is wrong such that the NXT is not able to read from the sensor. Is your sensor plugged into port 1?

Author:  AlexJ [ Wed Mar 19, 2014 12:35 pm ]
Post subject:  Re: Hi Technic Accel Sensor

Yes, the sensor is plugged into port 1.

Sorry what I meant by "doesn't seem to do anything useful" was that I believed it ONLY outputted static text, not actual senor values.

I ran this program with the hi tech compass sensor. The program worked with that sensor (did not display an error message, and displayed values that changed).
(I know the values for the compass sensor would be nonsensical, but I wanted to see it if would run).

When I wrote my own program using just SensorRaw(S1) in an while loop, the accelerator gave a reading (1023.0), but it never changes when I move the sensor around, unlike with every other sensor. Is this because a senor with three outputs won't react well with SensorRaw() or is it an indication the sensor is broken? If so, how would I go about testing this?

Author:  mightor [ Wed Mar 19, 2014 12:50 pm ]
Post subject:  Re: Hi Technic Accel Sensor

The reason SensorRaw won't work is because the compass and accelerometer sensor are digital sensors, not analogue ones.

If you want to make sure it works, try it out with the standard LEGO environment. If it's not working there, the sensor may be broken.

= Xander

Author:  AlexJ [ Wed Mar 19, 2014 1:05 pm ]
Post subject:  Re: Hi Technic Accel Sensor

Sorry, I'm not sure what you mean by the 'standard lego environment'.

I did find "Try Me" files already installed on the mindstorms brick. It works for the compass and other sensors, but the file labeled "Accel" does not work.

Author:  mightor [ Wed Mar 19, 2014 3:45 pm ]
Post subject:  Re: Hi Technic Accel Sensor

I can assure you that the test program "Accel" works fine with a functional sensor. See the photo below:
Attachment:
2014-03-19 20.41.36-cropped.jpg
2014-03-19 20.41.36-cropped.jpg [ 110.63 KiB | Viewed 14138 times ]

Try using another cable, as short as possible and test again.

= Xander

Author:  AlexJ [ Thu Apr 10, 2014 11:50 pm ]
Post subject:  Re: Hi Technic Accel Sensor

Thanks for your help. I did find that the accelerator was broken and obtained a replacement.

Author:  mightor [ Fri Apr 11, 2014 2:48 am ]
Post subject:  Re: Hi Technic Accel Sensor

Glad to hear it!

= Xander

Author:  millahjovich [ Mon Jun 13, 2016 6:39 am ]
Post subject:  Re: Hi Technic Accel Sensor

The reason SensorRaw won't work is because the compass and accelerometer sensor are digital sensors, not analogue ones.

If you want to make sure it works, try it out with the standard LEGO environment. If it's not working there, the sensor may be broken.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/