go_away

Author Topic: Can anyone show me how to get data from this?  (Read 3242 times)

0 Members and 1 Guest are viewing this topic.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Can anyone show me how to get data from this?
« on: March 14, 2010, 10:19:14 AM »
http://www.radioshack.com/product/index.jsp?productId=2909788#tabsetBasic
its a accelerometer from radioshack and I dont know how to write custom code for sensors
could someone explain to me how to code for this sensor with the Axon? (also which pins go where on  the axon)
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: Can anyone show me how to get data from this?
« Reply #1 on: March 14, 2010, 10:34:01 AM »
Do you download and read the User's guide?
The outputs are explained and there is even sample code for the BASIC stamp. Use this code to learn what you need to do and then rewrite it for the Axon.
The Accel's outputs are digital so they can be connected to any digital input on the Axon. The acceleration is the ratio of the high to period of the output pulse as shown in figure 1 of user's guide. The code needs to time the the pulse period and the high pulse length then calculate the G if needed.


Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #2 on: March 14, 2010, 10:51:24 AM »
um, could you show me how to do what you just said? That was kinda my question
« Last Edit: March 14, 2010, 10:52:37 AM by dellagd »
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #3 on: March 14, 2010, 11:45:38 AM »
Code: [Select]
while( pin is high)
{
//increment counter
}
//do math as shown in users guide

You will need to know how many cycles are 10ms, I forgot how to calculate it but it is somewhere in the source code of the Axon and the $50 robot.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #4 on: March 14, 2010, 12:31:48 PM »
I'm sorry but I still dont really get what you mean. I dont see anything about "cycles" in the axon source code
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #5 on: March 14, 2010, 12:36:55 PM »
It's probably in the $50 source code (you should really do it  :P ), where it calculates how many processor commands take up a certain amount of time.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #6 on: March 14, 2010, 12:49:13 PM »
well since the ATmega640 is configured to go faster than the ATmega8 then why would it help to look in the $50 robot code?

PS I still dont get your little code bit up there anyway.
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: Can anyone show me how to get data from this?
« Reply #7 on: March 14, 2010, 12:53:49 PM »
I'm sorry but I still dont really get what you mean. I dont see anything about "cycles" in the axon source code

A 'cycle' is the length of time one instruction (assembler) takes to execute, also called an instruction cycle.
This time is dependent on the clock frequency set by the processor's XTAL (crystal).

Now look again at Figure 2 in the accelerometer's user's guide and the equation under the figure.
A(g) = ((T1 / T2) - 0.5) / 12.5%
The period time and the high pulse time are a ratio in the equation so the absolute times (in seconds) are not required (the units of time cancel). Just count the length of each and divide the time (count) of the high pulse by the time (count) of the period.
 

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #8 on: March 14, 2010, 05:36:38 PM »
I dont want to seem noobish, but could someone give me some actual code? I think it wold seem much clearer if I acually saw the code since you guys seem to know how to do this.
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #9 on: March 14, 2010, 06:27:25 PM »
here is kind of pseudocode:

Code: [Select]
int t1 = 0;
int t2 = 0;
while(bit_is_set(PIND,4)) //while pin is high....
t1++;                          //count how long it is high
while(!(bit_is_set(PIND,4)))  //while pin is low...
t2++;                              //count how long it is low
int acceleration = ((t1/t2) - .5)/.125;   //find acceleration

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #10 on: March 14, 2010, 07:00:13 PM »
ok thx a bunch razor!
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #11 on: March 14, 2010, 08:38:54 PM »
ok new question what is the difference from g-force, x tilt, and x input??
Quote
DEBUG CRSRXY, 0, 3
DEBUG "X Input... ",
DEC (xRaw / 1000), ".", DEC3 xRaw, " ms",
CLREOL, CR,
"G Force... ", (xmG.BIT15 * 13 + " "),
DEC (ABS xmG / 1000), ".", DEC3 (ABS xmG), " g",
CLREOL, CR,
"X Tilt.... ", (xTilt.BIT15 * 13 + " "),
DEC ABS xTilt, DegSym, CLREOL
DEBUG CRSRXY, 0, 7
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: Can anyone show me how to get data from this?
« Reply #12 on: March 14, 2010, 09:24:39 PM »
here is kind of pseudocode:

Code: [Select]
int t1 = 0;
int t2 = 0;
while(bit_is_set(PIND,4)) //while pin is high....
t1++;                          //count how long it is high
while(!(bit_is_set(PIND,4)))  //while pin is low...
t2++;                              //count how long it is low
int acceleration = ((t1/t2) - .5)/.125;   //find acceleration

t2 is counting how long the input is low but the equation in the user's guide is the length of the high pulse divided by the total length of the high plus the low (length of the period). So change the last line of code to:
int acceleration = ((t1/(t1+t2)) - .5)/.125;   //find acceleration

Now there is a second problem with this code. acceleration is an int and the math to calculate the acceleration requires floating point math.  t1/(t1+t2) is always less than 1 (it'll be a faction). Also 0.5 & 0.125 are less than 1. One could using floating point values but this takes up a lot more code space and execution time.

The easy way out of this is to multiple t1 by 100 and use the equation:
t1 = t1 *100;
int acceleration = ((t1/t2) - 50)*8;   // find acceleration * 100
The acceleration value is now greater than zero and is also 100 times the true 'G' value but is easy to deal with.

I see you are examining the BASIC code in the User's guide, good.
The code you posted is the output to a UART to display the data in a terminal program on a PC.
'x input' is x raw, the actual measured time of the high pulse. See the "Read_G_Force:" subroutine.
'g force' is the actual g calculated from the pulse width. See the "Read_G_Force:" subroutine.
'x tilt'  is the calculated tilt of the x-axis. See the "Read_Tilt:" subroutine.

Do notice the equation used in the "Read_G_Force:" subroutine. xRaw is 1000 times larger so that 500 is subtracted from it. The result is 1/1000 g per 1 value (exp: if xmG calc's to be 1000 this is 1g, if xmG calc's be be 50 then g = 0.05).



Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #13 on: March 15, 2010, 06:15:55 AM »
ok, I think I get this
Quote
xmG = ((xRaw / 10) - 500) * 8
(quote from the code)
but what about this wierd line
Quote
xRaw = xRaw */ Scale
(also from the code)
what the heck does "*/" mean?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: Can anyone show me how to get data from this?
« Reply #14 on: March 15, 2010, 08:43:32 AM »
From the PBASIC manual:
Quote
One way to deal with fractional numbers is to use the */ operator. It has the effect of
multiplying a value by a whole number and a fraction. This operator places the whole
number portion in the upper byte, multiplies the fractional part by 256 and places the
result in the lower byte.
For example, if multiplying value with 1.8, using the */ would mean 0.8 * 256 = 204.8 =
205 and therefore:
Upper byte : 01
Lower byte : CD

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #15 on: March 15, 2010, 11:18:37 AM »
so you use it if multiplying with floats basically?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,935
  • Helpful? 98
Re: Can anyone show me how to get data from this?
« Reply #16 on: March 15, 2010, 11:59:17 AM »
Quote
so you use it if multiplying with floats basically?
Yep, it does a very basic fixed point math (similar to a float).
Note that this operator is only available in PBASIC.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #17 on: March 15, 2010, 04:18:07 PM »
here is kind of pseudocode:

Code: [Select]
int t1 = 0;
int t2 = 0;
while(bit_is_set(PIND,4)) //while pin is high....
t1++;                          //count how long it is high
while(!(bit_is_set(PIND,4)))  //while pin is low...
t2++;                              //count how long it is low
int acceleration = ((t1/t2) - .5)/.125;   //find acceleration

in the part:

Quote
while(bit_is_set(PIND,4))

what is "bit_is_set"? I know you said it was psudocode, but how would I check to see if the pin is HIGH on the axon II?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #18 on: March 15, 2010, 04:29:36 PM »
bit is set is the actual code used to check if the pin is high (there are a variety of ways to do this, i just prefer bit is set)

in my example, i am checking D4. If you want C3, do (PINC,3). etc etc

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #19 on: March 15, 2010, 05:21:07 PM »
well when I use that code I get an error.
what header file is the "bit_is_set" function located in?
 here are the errors:

Quote
../experimental2.c: In function 'read_accelerometer':
../experimental2.c:20: error: 'PIND' undeclared (first use in this function)
../experimental2.c:20: error: (Each undeclared identifier is reported only once
../experimental2.c:20: error: for each function it appears in.)
make: *** [experimental2.o] Error 1
Build failed with 3 errors and 0 warnings...
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #20 on: March 15, 2010, 05:27:26 PM »
Assuming you have AVR GCC installed, include this:
<avr/sfr_defs.h>

Or if that does not work, you can just define it yourself (but may have redefine issues later on if it starts working)
Code: [Select]
#define bit_is_set ( sfr,
bit )    (_SFR_BYTE(sfr) & _BV(bit))

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #21 on: March 15, 2010, 06:17:25 PM »
I think that I know the problem
could this be it?

There is nothing listed here!
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #22 on: March 15, 2010, 06:41:19 PM »
Looks like you didn't set a device (mega168, mega640, etc etc)

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #23 on: March 15, 2010, 06:52:07 PM »
well, these are my settings...
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #24 on: March 15, 2010, 07:08:48 PM »
ok, I got it to appear, same problem... Is there another method for checking if the pin is HIGH?
do I have to declare what PIND is or something?
« Last Edit: March 16, 2010, 04:45:00 AM by dellagd »
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #25 on: March 16, 2010, 05:29:18 AM »
well, heres a screenshot of the configuration options, the I\O view, and the bit of code where bit_is_set is called. Anything you see wrong?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #26 on: March 16, 2010, 03:01:49 PM »
Check the makefile and see if the mega640 is selected.

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #27 on: March 16, 2010, 03:22:12 PM »
this is towards the top of the makefile :
Quote
## General Flags
PROJECT = experimental2
MCU = atmega640
TARGET = experimental2.elf
CC = avr-gcc.exe
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline dellagdTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 731
  • Helpful? 5
  • Come to the dark side... We have cookies!
Re: Can anyone show me how to get data from this?
« Reply #28 on: March 16, 2010, 04:15:35 PM »
ok I've switched to WebbotLib method, but all it does is give me haywire messages
code:
Quote
void read_accelerometer () {

   while(pin_is_high(F5)) //while pin is high....
   t1++;                          //count how long it is high
   while(pin_is_low(F5) )  //while pin is low...
   t2++;                              //count how long it is low
   acceleration = ((t1/(t1+t2)) -  500)* 8; 
   } //find acceleration



yes, I did initallize F5 as an input
is it possible that my accelerometer is faulty?
Innovation is a product of Failure, which leads to Success.

If I helped, +1 helpful pls

I Won!
3rd place! I'm taking $100

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Can anyone show me how to get data from this?
« Reply #29 on: March 17, 2010, 03:38:51 AM »
Is acceleration an unsigned long?

 


Get Your Ad Here