Differences programming ADXRS150EBs to BEI Gyrochips?

Hi, ;
first off…thanks to everyone that helped me w/ the whole gyro ;
situation…esp. Ken Wietcliffe thanks for sticking around on the thread ;
answering my questions.;
Now i have one more… I have finally programmed a test bot to work with the;
BEI gyrochip… we have finally found and ordered the ADXRS150EB chip but ;
we probably will only have hours to assemble it etc. and program it…;

my question is : are there any differnces between programming the two ;
different gyros…i wouldn’t expect any, but i heard that the ADXRS150EB ;
outputs at 40hz or something and that during user_routines_fast it maybe ;
too slow and therefore it would not be precise enought (as the program ;
would loop several times adding the same value);

I’m very confused as to how it may not work but i’m just making sure;

Thank You …;

Salik Team 701

error line #15 : syntax error :wink:

I believe Ken is competing in Pittsburgh this weekend, so you may not hear from him as often as usual (but I bet he’ll find time to get on-line).

You will need to take the ADXRS150 40 Hz sample rate into account when calculating your heading. Depending on how you’ve setup your gyro sampling for the old gyro, you’ll need to scale each gyro sample to average the over-sampling.
If you are using a timer to specify the gyro sample rate in the fast loop, for instance, and you are taking 100 samples per second then you might have the line:


gyro_sum += gyro_sample * 40 / 100;

Are you are flat-out sampling the gyro every time through the fast loop?

yes I am sampling the gyro every CPU cycle, do you know what the sample rate of the BEI Gyrochip is ? I assume it is 100hz … from the code u gave me? so i guess i could just divide by a larger constant… but given the simplicity of the code we are using i think it may work even with the lower sample rate…

its kinda like this
heading=heading + (127-gyrovalue)
then we divide heading by 439 to get a degree measure…
we are not doing any integrations

My BEI gyro spec sheet is at home and I don’t remember the exact update rate off-hand. I will check it when I get home. It’s on the same order as the ADXRS150, so you may not be far off when you swap them later. My code above takes gyro samples only when the clock tells it to (that’s the 100Hz), so I always know exactly how many samples per second I’ve collected. In real life I happen to be sampling our gyro at 250Hz, simply because it happens to be convenient.

With the method you’re using the fast loop will give you a raw number for heading that includes all your over-sampling, but you somewhat correct for it when you do your conversion to degrees. There is a larger error introduced because the loops are not at a constant, regular rate (probably in the neighborhood of 400 Hz), but you’ll have to judge if the added error is significant enough to affect how you use it in autonomous. If you’re only using it to turn towards the 10pt ball it only has to work once.

The method you’re using is more trial and error in finding the proper number to divide by to get degrees, so you’ll have to repeat your tests with the new chip (and each time you add a lot of code that changes the fast loop rate).

I would hope that conversion only occurs pre-compiling. There is no reason you can’t give it values in ‘gyro’ units.

yes…but it is just easier to keep it in degrees…
I have another question…is the CPU cycle time constant…NO??? thats not good…
btw in our autonomous we hit the 10pt ball then grab the goal and drive back w/ plow open

arrrrghh…using mentors comp…this is actually SALIK SYED not Doug G

It’s not the proc freq., it’s how long it takes to do the main loop.

The fast loop is variable because different things will happen each time through. Sometimes it’ll be executing more instructions than average, other times fewer instructions than average. For instance, if you have a few interrupts from clock timers or external sources, or if an event happens that your code decides to run a longer calculation on. Any of the conditional statements you have in your code mean that sometimes you’ll go down one branch and at other times you’ll choose a different branch through the code. This doesn’t even count the timing changes due to printfs or IFI library code. All these code variations add up to variable time through the fast loop. That’s why most of us use timers or the more dependable slow loop.

plus, ~26.2ms the Process_From_Master_uP() is called.

hey guys - this thread just showed up in the ‘new posts’ search for me - sorry I didnt get back sooner (we were at Pittsburg - made it to 2nd place [finalists])

couple things here - it doenst matter to you how fast the gyro chip samples and outputs its data, because it has an analog output and output filters, so the output changes smoothly from one update to the next - you cant ‘see’ the sample rate on the output unless your robot is oscillating back and forth faster than the gyro can undate (and trust me on this, our motors do not have any where NEAR the power required to make a 130 pound machine move back and forth at 40 or 100 Hz :^)

in fact, our bots have so much inertia, and we normally turn so slow that the difference between successive samples of the gyro will be fairly small - so it doesnt matter if you sample them at 38Hz (the loop frequency of the process_data_from_master_up function) or at 100Hz or more- if you sample it at 38Hz you are not going to ‘miss’ any data from the gyro.

The main difference between the old FIRST gyros and the AD chip is the degree/second rates - the old ones were +/-75° per second and the AD…150EB is +/-150° per second - that is the big thing you will have to change - when turning at the same rate the AD chip will put out a smaller signal, because you have to turn twice as fast to get a full scale output.

BTW - adding the signal to an accumulator IS integrating the signal - if you go through all the math, instead of degrees per second (the gyro output) you end up with degress * your sample rate

with the AD gyro turning at full scale for one second you will turn 150°. if you shift right the gyro output down to 8 bits, then If you sample it at 38Hz you will have 127*38 added to your accumulator - so 4572 represents a turn of 150°

divide it out and 1 degree is = 30.48 in the accumulator.

if you are sampling faster the conversion factor will be higher.

The other thing you have to be aware of is the zero point in the AD chips seems to be off more than they were with the old FIRST gyros - ours sits at 141 instead of 127 - I wrote a section of code to read the gyro when the bot is disabled, and average for 32 samples- this seems to be working but I also have gyroZero initalized to 141 incase this doesnt run for some reason - I put the gyroZero variable on the OI User byte so we can see it from the OI.


/* if disabled then average the gyro zero point*/
if (competition_mode==0)
{
	gyroAccum=gyroAccum+gyroData;	/*add data to accumulator*/
             aveCount=aveCount+1;
	if (aveCount==32)			/* then done with this */
	{
		gyroZero=gyroAccum>>5;	/*div by 32*/
		gyroAccum=0;		/*clear for next time*/
		aveCount=0;
	}
}

gyroAccum and aveCount are both initialized to zero on powerup.

ok - one last thing about fast and normal loop speeds - Innovation FIRST put the auton code in the user_routines_fast.c file, but I dont know why they did that - I think its misleading - from what I can see reading the default User_Autonomous_Code two things stand out:

  1. auton spins internally on a while loop - once you get into this function you dont exit until auton ends - so only the code ‘in here’ gets run in auton mode

  2. auton waits for statusflag.New_SPI_DATA before its body is executed - this is the 26.2mS (38 Hz) timing gate - so unless you add code outside that IF statement, its not going to run faster than 38Hz - so I dont know why people are thinking the auton code is running faster - unless you modify the default code, its not

in fact, we moved our auton code into the user_rountines.c file, so that I dont have to re-declare all the common variables as extern’s.

I think I missed something - let me post this and read the original questions again - if I did I will post again.

ok, there was one more thing - the accuracy of the 26.2ms loop timing.

there is a layer of SW over our code that we dont have access to, which controls the input and output data to the operator interface - our code is synch to that by the

if (statusflag.NEW_SPI_DATA)

statement - that flag will go active once every 26.2mS - which is whats gating the 38Hz loop frequency.

I have seen posts on CD where people have put oscilloscopes out output pins and measured the loop rate by toggling a digital output on each loop, and they have reported it is dead accurate - so consistant that you cant measure the difference from loop to loop.

As it was pointed out above, if you have a bunch of code after that, with conditional branches, then that code might be executing at different rates - to get around that I put the Get_analog statement for the gyro code right after the statusflag statement - at least that will be reading the gyros at consistant fixe intervals

but at the bottom of you code is were you output new values to the PWMs, which affect the motors - if this is not done at precise intervals then you are introducting some dither into your closed loop feedback loop

but to be honest, I dont think its enough to make a difference - it will average itself out over several cycles and you wont notice any adverse effects in the operation of the bot as a whole.

BTW - if anyone is wondering if this gyro stuff really works - our bot is designed to collect and deliver small balls as our primary function - so getting the release ball is critial to our team.

we use the gyro to run straight ahead in auton mode until the IR sensor sees the beacon 90° out to one side

then we drop our suctioncup arm down to the height of the release ball while backing up straight for a second, turn exactly 90° towards the release ball, move forwards for 2 seconds at 1/3 speed (knocking the release ball off) then back up for a second, turn towards our drivers exactly 90°, raise our arm, turn our front rollers on and move full speed towards the drivers to try and catch some of those 18 balls that are now all over the field.

How well does its work? we have a finalist trophy from Pittsburgh - we only missed the ball once in the elimination rounds - and I think the other teams robot was between us and the beacon, preventing our bot from detecting it - Not sure - wish I could see a video of the last round of the finals at pittsburgh to make sure thats what it was.

okay thanks for the help…thats basically what i suspected.
now… if 141 = neutral does 254 still equal 150 degs/ sec turning? if so than what is 0?

good question - obviously the full scale readings will be off

and Im willing to bet Analog Devices will tell you to fix that by adjusting the zero point on the output - I think there are resistors you can play with to make zero be = 2.5V - I havent looked into it

or it is possible its the analog inputs on the PIC chip that are a little off on zero - I havent played with it or done any testing - our bot seems to be good enough the way it is, so I havent spent anytime trying to make zero = 127.

Congats to Ken and your Team’s great performance this weekend. Thanks so much to all of you for your assistance with this gyro code. We were very far behind when we shipped the robot - we had no auto code tested at all - but now a few weeks later, we built a second (though very much different) robot and have an auto code worked out. WOW! I know this Thursday at Sac Regional will be a busy day of programming and testing!

Salik: What you are doing IS integration, just a Ken mentioned. Mostly we are taught that integration of acceleration is done by the sum of (adtdt) over a set of time limits. Your code is doing just that… summing up the accelerations where dt is the time of one program loop. Think of it as a sort of “numerical” integration. Take a numerical analysis course in college and you get to write many computer programs to solve all sorts of math problems.

Hopefully it the “chip” comes today so that we can start trying it out… Fun, Fun, Fun!!

haha…i have no idea what integration really means…i thought it was jus multiplying by time twice (or once to get speed) …but i figured wut i did wasn’t really integration… now i get it…the cpu cycle time…aha… :ahh:
i’m still in trig booohooohooo

ne ways we got the gyro today and hooked it up to a prototyping board…it was really easy, but the gyro has no output???
when i plug the pwm cable into the computer it reads 135 whether i shake it too and fro or what not i get a constant 135, if i unplug it says 255.
Now did i plug Signal to the right pin? is it RATEOUT that i should plug in to? (that is pin 2)

I think i’ll have fun at Sacramento :wink:
porting over code meant for a totally different robot into another one…
it will be interesting.

yes, rate out is the right one

there are also two power pins - pins 1 and 13 both need +5 volts

there are two gnd pins but the spec sheet says they are tied together on the little circuit board - pins 12 and 8, so either one can be used

you said PWM in your post - I take it you mean the analog input connector using a pwm cable?

also make sure you have the chip the right way - pin one has a square PCB pad, the rest have round pads on the top of the circuit board

and remember the driwing on the spec sheet is the top view - when you solder wires on the bottom side the pin numbering is a mirror image of the top side.

let us know if it works.

Yes i saw the one w/ a square solder is pin 1…and nothing burned or melted so i think that parts good,
I think the reason it wasn’t working was that i never put anything in pin 13, i’ll check tommorow and see what happnes, THanks!.

yep! that would do it. Pin 13 is the charge pump pin - that explains what you saw - it should be fine when you hit it with 5V on both pwr pins

cool! I like it when HW bugs make sense :^)