Thread: Using Sensors
View Single Post
  #9   Spotlight this post!  
Unread 13-12-2003, 23:15
GregT GregT is offline
Registered User
no team
 
Join Date: Jul 2001
Rookie Year: 2001
Location: FL
Posts: 400
GregT will become famous soon enough
Send a message via AIM to GregT
Re: Using Sensors

It's commented out because something didn't work right, but here's an example:


Code:
	'debug "Driving Forward!",cr
	
	'gyro_total = gyro_total + gyro_in
	'gyro_n = gyro_n + 1

	'if(gyro_n = gyro_sample) then
		
		
	'	buffer = gyro_total - (gyro_center * gyro_n)
	'	if(buffer > gyro_center) then
	'		left_target = FULLSPEED
	'		right_target = FULLSPEED - (buffer - gyro_center)
	'	endif
	'	if(buffer < gyro_center) then
	'		right_target = FULLSPEED		
	'		left_target = FULLSPEED - (buffer - gyro_center)
	'	endif
	'	if(buffer = gyro_center) then
	'		left_target = FULLSPEED
	'		right_target = FULLSPEED
	'	endif

'		'reset gyro vars
'		gyro_n = gyro_n + 1
'		gyro_total = gyro_total / gyro_n 'reset average for n=1
'	endif
The general idea was to take gyro_sample samples from the gyro, then use the average to see if the robot was heading straight or veering to one side. It would then correct by a constant * the difference between the desired and actual gyro readings (the constant is 1 in this code, that changed in later versions I can't seem to find anymore).

right_target and left_target are motor speeds, before being sent through a protective filter.

Keep in mind that this DIDNT WORK. I'm not sure why- I blamed it on the slow refresh of the RC, but it's much more likley due to my terrible programming

We ended up dropping the gyro entirely because it added complexity to a system that was working fine without it. I think that with some planning and the new RC strong programming teams could have a lot of fun with the gyro.

greg
__________________
The above was my opinion. I'm wrong a lot. I'm sarcastic a lot. Try not to take me too seriously.