View Single Post
  #12   Spotlight this post!  
Unread 11-01-2007, 10:30
Matt Krass's Avatar
Matt Krass Matt Krass is offline
"Old" and Cranky. Get off my lawn!
AKA: Dark Ages
FRC #0263 (Sachem Aftershock)
Team Role: Mentor
 
Join Date: Oct 2002
Rookie Year: 2002
Location: Long Island, NY
Posts: 1,187
Matt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond repute
Send a message via AIM to Matt Krass
Re: What are we supposed to do!?!?!?!??!?!

There is a function in user_routines.c called Default_Routine(). This is basically your playground, this function runs about 38 times a second (26.2 milliseconds) and you put all your logic in here. Your OI data (joystick values, buttons pushed) is all available in aptly named variables (p1_y, p2_x, p2_sw_trig, etc) that you can check with if statements. For example to make the trigger on the joystick connected to Port 1 drive the robot forward and your motors are on pwm01 and pwm02 you might try this:

Code:
// in Default_Routine()
...
	if(p1_sw_trig) // If the trigger is pushed
	{
		pwm01 = 255; // Left motor full speed forward
		pwm02 = 0; // Right motor full reverse since it's likely facing the  opposite direction
	}
	else // Trigger is not pushed
	{
		pwm01 = 127; // Motor stopped;
		pwm02 = 127; // Motor stopped;
	}
Note this is not a recommend way to drive, you're better off mapping the pwm outputs to the joystick inputs like this:

Code:
...
pwm01 = p1_y;
That should be enough for you to get started, it's all just basic logic.
Good luck!
__________________
Matt Krass
If I suggest something to try and fix a problem, and you don't understand what I mean, please PM me!

I'm a FIRST relic of sorts, I remember when we used PBASIC and we got CH Flightsticks in the KoP. In my day we didn't have motorized carts, we pushed our robots uphill, both ways! (Houston 2003!)