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

I have a complicated autonomos problem I need help with.
http://robotc.net/forums/viewtopic.php?f=52&t=7286
Page 1 of 1

Author:  TNatty [ Thu Nov 14, 2013 11:18 am ]
Post subject:  I have a complicated autonomos problem I need help with.

I need my robot to move up until the IR sensor reaches a defined value then stop. I need that about of time to be taken as a value i can use to tell it how far it moves backwards. How could I do that?

Author:  JohnWatson [ Thu Nov 14, 2013 1:41 pm ]
Post subject:  Re: I have a complicated autonomos problem I need help with.

What code do you have so far? Please post what you have so far using the [code] tags and we'll be more than happy to take a look at with you.

Also, try listing the behaviors you want the robot to perform (move forward until IR sensor reaches a value, stop, record amount of time, move backwards for amount of time) and then slowly break each behavior down into smaller behaviors, which can then be broken down into individual lines of code. As always, make sure to start with your first behavior (move forward until IR sensor reaches a value) before moving on to the other behaviors.

Author:  TNatty [ Fri Nov 15, 2013 9:57 am ]
Post subject:  Re: I have a complicated autonomos problem I need help with.

#include"JoystickDriver.c"
#include"hitechnic-irseeker-v2.h"
#define IRSEEKER
#define s3

task main()
{
int IRSEEKER s3

hi; while (1 == 1)
{

if ((HTIRS2_AC_DIR) < 7)
{
motor[leftback] = 100;
motor[leftfront] = 100;
motor[rightfront] = -100;
motor[rightback] = -100;
}
if ((HTIRS2_AC_DIR) > 7)
{
motor[leftback] = -100;
motor[leftfront] = -100;
motor[rightfront] = 100;
motor[rightback] = 100;
}
else
{
motor[leftback] = 0;
motor[leftfront] = 0;
motor[rightfront] = 0;
motor[rightback] = 0;
}

}
}

Author:  cookthebook [ Fri Nov 15, 2013 11:43 pm ]
Post subject:  Re: I have a complicated autonomos problem I need help with.

First off, your else statement will be contradicting your first if statement, so you might want to look at my fix. Im just assuming that < 7 means to move forward here. Here's some code with timers that I would use, I'm not sure if it works since I've never actually used the timer function but it should be fine.
Code:
#include"JoystickDriver.c"
#include"hitechnic-irseeker-v2.h"
#define IRSEEKER
#define s3

int valTime;//Your int representing your time

task main()
{
int IRSEEKER s3

ClearTimer[T1];//Set T1 to 0

hi; while (1 == 1)
{
if ((HTIRS2_AC_DIR) < 7)
{
motor[leftback] = 100;
motor[leftfront] = 100;
motor[rightfront] = -100;
motor[rightback] = -100;

valeTime = time1[T1]; //When you exit the loop, valTime will equal the number of msecs you were in it
}
if ((HTIRS2_AC_DIR) > 7)
{
motor[leftback] = -100;
motor[leftfront] = -100;
motor[rightfront] = 100;
motor[rightback] = 100;
}
if((HTIRS_AC_DIR) == 7)//No conflicts
{
motor[leftback] = 0;
motor[leftfront] = 0;
motor[rightfront] = 0;
motor[rightback] = 0;
}

}
}


So the int valTime is constantly being updated to the built in timer T1 while the IRSeeker is < 7. The ClearTimer function will set T1 to 0, I'm just assuming you start off in the process you want to time. If not then just clear it right before you do this. Then you can just use valTime in a wait1msec function. Hopefully that helps.

p.s. - im not sure what your "hi;" does, but I will just assume its part of hitechnic-irseeker-v2.h which I don't use, I just use SensorValue for the IRSeeker.

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