View unanswered posts | View active topics It is currently Tue Jul 29, 2014 2:50 am






Reply to topic  [ 8 posts ] 
Hi Technic Accel Sensor 
Author Message
Rookie

Joined: Wed Mar 19, 2014 10:39 am
Posts: 7
Post 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?


Wed Mar 19, 2014 11:14 am
Profile
Novice

Joined: Sat Aug 31, 2013 9:15 am
Posts: 97
Post 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?

_________________
Burning Lights Programming
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
Check out our team website at http://cof7468.weebly.com/.


Wed Mar 19, 2014 12:20 pm
Profile
Rookie

Joined: Wed Mar 19, 2014 10:39 am
Posts: 7
Post 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?


Wed Mar 19, 2014 12:35 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 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

_________________
| 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 19, 2014 12:50 pm
Profile WWW
Rookie

Joined: Wed Mar 19, 2014 10:39 am
Posts: 7
Post 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.


Wed Mar 19, 2014 1:05 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post 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 761 times ]

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

= 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 19, 2014 3:45 pm
Profile WWW
Rookie

Joined: Wed Mar 19, 2014 10:39 am
Posts: 7
Post Re: Hi Technic Accel Sensor
Thanks for your help. I did find that the accelerator was broken and obtained a replacement.


Thu Apr 10, 2014 11:50 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post Re: Hi Technic Accel Sensor
Glad to hear 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]


Fri Apr 11, 2014 2:48 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 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.