ROBOTC.net forums
http://www.robotc.net/forums/

Encoder issues
http://www.robotc.net/forums/viewtopic.php?f=11&t=7838
Page 1 of 1

Author:  hembreek [ Fri Jan 31, 2014 4:15 pm ]
Post subject:  Encoder issues

I have a student working on a AGV and has to program it to travel back and forth. I have also required them to program in a kill switch and safety sensors. These sensors stop the vehicle if something crosses into it path. They are using an encoder to get it to travel the correct distance back and forth. The issue is when the sonar sensors stop the vehicle the encoder zero's out. Thus when the vehicle continues on the count is messed up. Any help? Program Attached. Any help would be greatly appreciated

Attachments:
AGV.c [1.03 KiB]
Downloaded 395 times

Author:  JohnWatson [ Mon Feb 03, 2014 11:25 am ]
Post subject:  Re: Encoder issues

The reason you are running into this is because the 'untilEncoderCounts' command automatically resets the encoder counts when it is called (pulled from the NatLang_Cortex.c include file):

Code:
void untilEncoderCounts(long distance = 360, tSensors sensorPort = dgtl1)
{
  SensorValue[sensorPort] = 0;

  while(abs(SensorValue[sensorPort]) < abs(distance)){wait1Msec(1);}
}


This particular task may be beyond the functionality of the Natural Language programming and could serve as a good introduction to true ROBOTC programming. You can create either a custom function without the 'SensorValue[sensorPort] = 0;' command (or equivalent), or add the while loop directly into the code:

Code:
while(1==1)
{
   startMotor(drive, 127);
   while(SensorValue[counter] > -11700);
        stopMotor(drive);


There are also other ways to perform this behavior and these are only two examples of how to do this.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/