|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Example code
ooo I had some problems with that darn tooth-sensor.
Can anyone please give some examples to deal with it? A real normal example. I am really desprate ![]() |
|
#2
|
||||
|
||||
|
Re: Example code
You need to post more info about what you have tried so we know where to start with advice. We found that the default encoder code from Kevin's site was enough to get it working so we could see tooth count interrupts.
|
|
#3
|
|||
|
|||
|
Re: Example code
Quote:
Quote:
C:\Program Files\Intelitek\easyC for FRC\Projects\Test Code\GEARTOOTHTEST.ECP Also make sure you download and install the newest version of EasyC to make sure the test code is up to date (look here). There were some problems with the earlier test code because the print statement wasn't formatted correctly, so the tooth count was being output in the bajillions. I'm not sure if it has been fixed yet, because our gear tooth counters are in the crate. But this will help you with testing it out. Remember the tooth count is output to a long variable, so the output must be formatted for a long variable. Also look in the Help section of EasyC. Look for gear tooth counter and it will tell you how to use it. Good luck! |
|
#4
|
|||
|
|||
|
Re: Example code
Sorry I really didn't give any details.
The sensor itself works fine. I need an example code which uses the gear-tooth sensor as a distance measure My idea: when the distance is X (found by the gear-tooth) the drive function stops the cart, the geear-tooth sensor "calibrates" to zero again and turns(I know how to do that) I tried some varients how to do that but the gear tooth sensor didn't "calibrate" to zero and the cart didn't turn. If someone think of an idea like this and can give an example how he did it I'll be glad |
|
#5
|
|||
|
|||
|
Re: Example code
Aha! Well that's a different story and pretty ez to do. There's a variety of ways to implement it but a simple way is to first figure out how many counts your sensor returns per inch (or foot or cm or whatever units you are using) then use this:
Code:
void driveTo ( double distance )
{
double d = 0;
int speed = 0;
d = GetGTSensor ( GTS_DIG_IO ) ;
d = d/ GEAR_COUNT_PER_INCH ;
while ( d < distance )
{
if ( (distance - d) < 12 )
{
speed = 127 + (distance - d) ;
}
else
{
speed = 175 ;
}
drivePID ( 127, speed ) ;
d = GetGTSensor ( GTS_DIG_IO ) ;
d = d/ GEAR_COUNT_PER_INCH ;
}
PresetGTSensor ( GTS_DIG_IO , 0 ) ;
Drive ( 127, 0 ) ;
}
Last edited by TubaMorg : 14-03-2006 at 15:05. |
|
#6
|
|||
|
|||
|
Re: Example code
Quote:
You are forggeting that the drive doesn't use values of pwm. to stop the robot I wiil write 0,0 (speed, direction) but that one was great. I will test it tomorrow. Can you or anyone else give another varient? TNX ahead. edit: d = GetGTSensor ( GTS_DIG_IO ) ; d = d/ GEAR_COUNT_PER_INCH ; d equales both of those lines? |
|
#7
|
|||
|
|||
|
Re: Example code
Quote:
Yes d equals both of those lines. The first line gets the absolute gear tooth count (which isn't distance), then the second line CHANGES d to equal the number of inches travelled. If you find any other problems be sure to post, because remember others are looking too, and we don't want to lead anyone astray! ![]() |
|
#8
|
|||
|
|||
|
Re: Example code
Yeah got it.
But doesn't the EasyC won't allow to do that. I mean let the 'd' to equale both things, but I'll try that today. Tnx anyway. |
|
#9
|
|||
|
|||
|
Re: Example code
Quote:
Actually EasyC (which is just a specialized GUI for 'C') does allow it, because I copied it directly from our EasyC code. All programming languages (that I am aware of) allow this type of variable manipulation. You should keep in mind that while assignments may LOOK like algebra, they really aren't. So statements like d = d/45 are perfectly valid, because you are assigning to d the value of the expression d/45. Also another misconception you might have is that all of the lines of code are evaluated simultaneously, which is not correct. Programs are always executed line by line. Which means that Code:
d = GetGTSensor ( GTS_DIG_IO ) ; Code:
d = d/ GEAR_COUNT_PER_INCH ; is executed. d DOES NOT equal both simultaneously, but it does equal the last value assigned to it. If you are still uncomfortable with this, you can easily change it like this: Code:
long temp_d; temp_d = GetGTSensor ( GTS_DIG_IO ) ; d = temp_d/ GEAR_COUNT_PER_INCH ; Code:
d = GetGTSensor ( GTS_DIG_IO )/ GEAR_COUNT_PER_INCH; Every single one of those results in the same output ![]() Last edited by TubaMorg : 15-03-2006 at 12:02. |
|
#10
|
|||
|
|||
|
Re: Example code
Yeah Yeah I got it tnx man. Works fine!@
|
|
#11
|
|||
|
|||
|
Re: Example code
Very good to hear!
A bad thing about this particular code, though, is that your robot can't do anything but drive until it reaches it's goal. If you need to evaluate other sensor data you should add the function calls to the while loop. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Out of the Box Camera Code | russell | Programming | 9 | 21-10-2009 05:28 |
| Problem with idata_user_routines.o? | Adrien | Programming | 3 | 12-02-2006 01:33 |
| Team THRUST - Kevin's Code and Camera Code Combine | Chris_Elston | Programming | 3 | 31-01-2005 22:28 |
| Sourceforge for Code Repository and other stuff | SilverStar | Programming | 9 | 15-01-2005 21:16 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |