View unanswered posts | View active topics It is currently Thu Oct 02, 2014 8:28 am






Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Program copying 
Author Message
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Program copying
I copied the program hitechnic-gyro-test2.c.


#pragma config(Sensor, S1, HTGYRO, sensorAnalogInactive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*
* $Id: hitechnic-gyro-test2.c 123 2012-11-02 16:35:15Z xander $
*/

/**
* hitechnic-gyro.h provides an API for the HiTechnic Gyroscopic Sensor. This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
*
* 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.54 AND HIGHER.
* Xander Soldaat (xander_at_botbench.com)
* 06 April 2012
* version 0.1
*/

#include "drivers/hitechnic-gyro.h"

task main ()
{
float rotSpeed = 0;
float heading = 0;

// Calibrate the gyro, make sure you hold the sensor still
HTGYROstartCal(HTGYRO);

// Reset the timer.
time1[T1] = 0;

while (true)
{
// Wait until 20ms has passed
while (time1[T1] < 20)
wait1Msec(1);

// Reset the timer
time1[T1]=0;

// Read the current rotation speed
rotSpeed = HTGYROreadRot(HTGYRO);

// Calculate the new heading by adding the amount of degrees
// we've turned in the last 20ms
// If our current rate of rotation is 100 degrees/second,
// then we will have turned 100 * (20/1000) = 2 degrees since
// the last time we measured.
heading += rotSpeed * 0.02;

// Display our current heading on the screen
nxtDisplayCenteredBigTextLine(3, "%2.0f", heading);
}
}


I copied the program to a blank one and called t Gyro 1. When I compiled the orginal program, there were no errors. Then, when I compiled Gyro 1 it had errors:
**Severe*:Couldn't open '#include' file 'new folder/hitechnic-gyro.h'
**Error**:Undefined procedure 'HTGYROstartCal'.
**Error**:Too many parameters specified. Call to 'HTGYROstartCal'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.
**Error**:Undefined procedure 'HTGYROreadRot'.
**Error**:Too many parameters specified. Call to 'HTGYROreadRot'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.

I don't know why that happened. hitechnic-gyro-test2 is not in the same folder as drivers/hitechnic-gyro.h and neither is gyro 1. Someone please explain this.
Thanks


Mon Jan 14, 2013 3:01 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Program copying
Errors 2-5 are caused by the computer's not understanding of the incude file location. I got the dexter industries IMU and experienced similar problems. I fixed it by taking off the "drivers/" part of the file name. Hopefully this helps!.

Coder A

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Mon Jan 14, 2013 3:29 pm
Profile
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
Thanks but it didn't make it work. The errors are:
**Severe*:Couldn't open '#include' file 'hitechnic-gyro.h'
**Error**:Undefined procedure 'HTGYROstartCal'.
**Error**:Too many parameters specified. Call to 'HTGYROstartCal'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.
**Error**:Undefined procedure 'HTGYROreadRot'.
**Error**:Too many parameters specified. Call to 'HTGYROreadRot'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.
So not that much of a difference. Just to restate the problem, the same program is in sample program hitechnic-gyro-test2 as in Gyro 1 and Gyro 1 has errors. The program reads the degrees the gyro sensor is turning and then displays it on the NXT screen.


Mon Jan 14, 2013 8:20 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Program copying
Since you are running Xander's test program, you must have downloaded Xander's driver suite (which includes the test programs). In the same folder where the test programs are, there should be a "drivers" sub-folder. Make sure it's there. Inside that "drivers" sub-folder, you should be able to find the hitechnic-gyro.h file. If you can't find that sub-folder, that will be the problem.


Mon Jan 14, 2013 10:34 pm
Profile
Rookie

Joined: Thu Sep 13, 2012 9:43 am
Posts: 47
Post Re: Program copying
firecannons198 wrote:
Thanks but it didn't make it work. The errors are:
**Severe*:Couldn't open '#include' file 'hitechnic-gyro.h'
**Error**:Undefined procedure 'HTGYROstartCal'.
**Error**:Too many parameters specified. Call to 'HTGYROstartCal'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.
**Error**:Undefined procedure 'HTGYROreadRot'.
**Error**:Too many parameters specified. Call to 'HTGYROreadRot'. Parameter: 'N/A' is 'HTGYRO' of type 'tSensors'.
So not that much of a difference. Just to restate the problem, the same program is in sample program hitechnic-gyro-test2 as in Gyro 1 and Gyro 1 has errors. The program reads the degrees the gyro sensor is turning and then displays it on the NXT screen.


Did you install the Driver Suite as per Xander's instructions at http://botbench.com/blog/robotc-driver-suite/?
(You will need to ensure the include file locations are setup in View>Preferences>Detailed preferences>Compiler>Include directories, which is slightly different to Xanders tutorial but reflects changes to the newer version of RobotC)


Tue Jan 15, 2013 3:06 am
Profile
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
There was a drivers folder. I copied and pasted Gyro 1.c into the 3rd party sensors, which is the folder where hitechnic-gyro-test2.c was and tried to compile. There were errors. I also compied and pasted Gyro 1.c into the drivers folder and got the same result. I also copied and pasted the program from the hitechnic-gyro-test2.c into Gyro 1.c just to make sure. I looked at the link and it was kind of comfusing. I think we're making progress though.


Tue Jan 15, 2013 11:05 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Program copying
I'll update my driver suite howto today. I'll keep you posted.

= 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]


Mon Jan 21, 2013 2:03 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Program copying
This should help you.
http://botbench.com/blog/robotc-driver- ... ver-suite/

= 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]


Mon Jan 21, 2013 2:14 pm
Profile WWW
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
I compiled the Gyro 1 program with the same code as hitechnic-gyro-test2 and it compiled. I downloaded it and it did the same ting as hitechnic-gyro-test2! Thanks Xander! :D Anyway, now I'm trying to calibrate the gyro. Is the best way to change to offset changing all the 620s in the driver?


Mon Jan 21, 2013 11:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Program copying
No, the best way is to calibrate your gyro. The values are defaults, but if you run the calibration function, it will change those values. You'll have to do this every time you start your program.

= 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]


Tue Jan 22, 2013 3:45 am
Profile WWW
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
At first I was completely stumped but then I found this code:

// Offset Calibration
int offset = 0;
for (int i = 0; i <10; i ++) (
offset = offset + SensorValue (GyroSensor)
);
offset = offset/10;
nxtDisplayCenteredTextLine (4, "Offset:% d", offset);
wait1Msec (3000);

at
http://blog.electricbricks.com/en/2010/ ... giroscopo/

I changed the GyroSensor to HTGYRO and added it to hitechnic-gyro-test2. Now I have a calibrate gyro program! Now I will create amazing things.


Tue Jan 22, 2013 2:38 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Program copying
In hitechnic-gyro.h there's the following function:

Code:
/**
 * Calibrate the gyro by calculating the average offset of 5 raw readings.
 * @param link the HTGYRO port number
 * @return the new offset value for the gyro
 */
float HTGYROstartCal(tSensors link) {
  long _avgdata = 0;

  // Make sure the sensor is configured as type sensorRawValue
  if (SensorType[link] != sensorAnalogInactive) {
    SetSensorType(link, sensorAnalogInactive);
    wait1Msec(100);
  }

  // Take 50 readings and average them out
  for (int i = 0; i < 50; i++) {
    _avgdata += SensorValue[link];
    wait1Msec(5);
  }

  // Store new offset
  HTGYRO_offsets[link][0] = (_avgdata / 50.0);

  // Return new offset value
  return HTGYRO_offsets[link][0];
}


Did you try using that?

= 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]


Tue Jan 22, 2013 3:37 pm
Profile WWW
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
Well, in the program, it runs HTGYROstartCal. WIth HTGYROstartCal and the program clip in my last post, I acheived more accuracy with the Gyro than ever before. Still, I would like to make it more accurate. Would repeating HTGYROstartCal or the other calibrating program make the gyro more accurate?


Sat Jan 26, 2013 1:10 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Program copying
No, not likely. If you figure out what your drift rate is, and constantly compensate for that, you will probably gain extra accuracy.

= 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]


Sat Jan 26, 2013 4:11 am
Profile WWW
Rookie

Joined: Mon Jan 14, 2013 2:50 pm
Posts: 12
Post Re: Program copying
Well, the drift rate seems to be different every time. The Gryo seems to lose some accuracy when it is moved fast. I'll keep testing...


Sat Jan 26, 2013 8:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


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.