Go to Post It's been said before--sports are fine and good, as long as you've got your priorities in the right order for you. - Billfred [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-02-2007, 21:10
Ianuser Ianuser is offline
Registered User
FRC #0570
 
Join Date: Feb 2007
Location: new york
Posts: 64
Ianuser is an unknown quantity at this point
Code for sensor still doesn't work

Hey, sorry about making a billion threads about this, but I'm trying to get your attention as quickly as possible since we don't have much time left. the code for my sensor does not work properly and I don't know where the problem(s) is(are). It is a metal detector that will sense a metal strip in a rope that is used in a winch system to lift the ringers. The metal strips will be placed in certain locations so that when the rope/metal strip passes the metal detector the motor will stop. If i want to keep going I simply press the trigger and it goes to the next level of the SPIDER. This is the code. Any help would be fantastic. If you have questions, please ask them so I can help you help me! THANKS!

In User_Routines.c:

Code:
void Default_Routine(void)
{
	int now;    //for mapping rc_dig_in04 to ON or OFF (sensor)
	int last; 	//for mapping rc_dig_in04 to ON or OFF (sensor)
	int now2; 	//for mapping p3_sw_trig to ON or OFF (reset p3_y)
	int last2;	//for mapping p3_sw_trig to ON or OFF (reset p3_y)
	int now3;	//for mapping p3_sw_aux1 to ON or OFF (reset counter)
	int last3;  //for mapping p3_sw_aux1 to ON or OFF (reset counter)
	int now4; 	//for mapping p3_sw_aux2 to ON or OFF (reset CAMERA)
	int last4;	//for mapping p3_sw_aux2 to ON or OFF (reset CAMERA)
		
	last = now;
	now = rc_dig_in04;

	last2 = now2;
	now2 = p3_sw_trig;

	last3 = now3;
	now3 = p3_sw_aux1;
blah blah blah...joystick mappings... THEN

CODE THAT RELATES TO SENSOR/FORKLIFT
Code:
 	if((now3 == 1) && (last3 == 0)) //p3_sw_aux1 sets counter to 0 in case forklift needs to be reset.
	{
		count = 0;
	}


	if((now2 == 1) && (last2 == 0)) //p3_sw_trig sets joystick 3 y-axis to forklift motor. Use after each level.
	{
		pwm03 = p3_y;
	}


	if((pwm03 < 125) || (pwm03 > 129))  //if py_3 is being used (forklift going up or down)
 	{
		if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, sends a signal...
		{
			count++; //Number of times tape passes through the sensor.
			Switch1_LED = 1; //Switch01 goes on when the tape passes the sensor.
		}
		else
		{
			Switch1_LED = 0;
		}

		switch(count) //for sensor module
		{
			case 1:			//if count = 1 then that just means that it passed through the first piece of tape which will be used to show that it is in full DOWN position.

				Relay2_green = 1;
				Relay2_red = 0;
				printf("count = 1");
				break;

			case 2:
		
				Relay2_green = 1;
				Relay2_red = 0;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it reaches 1st level of rack.
				printf("count = 2");
				break;
			
			case 3:
			
				Relay2_green = 1;
				Relay2_red = 0;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it reaches 2nd level.
				printf("count = 3");
				break;

			case 4:
					
				Relay2_green = 1;
				Relay2_red = 1;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it reaches top level.
				printf("count = 4");
				break;

			case 5:

				Relay2_green = 0;
				Relay2_red = 1;
				//pwm03 does not equal 127 because it must pass the tape in order to go beneath the top level.
				printf("count = 5");
				break;

			case 6:
			
				Relay2_green = 0;
				Relay2_red = 1;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it retreats to 2nd level.
				printf("count = 6");
				break;
			
			case 7:
			
				Relay2_green = 0;
				Relay2_red = 1;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it retreats to 1st level.
				printf("count = 7");
				break;

			case 8:
			
				Relay2_green = 0;
				Relay2_red = 0;
				pwm03 != p3_y;
				pwm03 = 127; //Motor stops when it retreats to ground level.
				printf("count = 8 but will reset now.");
				count = 0;
				break;


		}
	}
Thanks so much for your help.
  #2   Spotlight this post!  
Unread 14-02-2007, 09:44
buddy.smith buddy.smith is offline
Master Control
FRC #1795
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: atlanta
Posts: 20
buddy.smith is an unknown quantity at this point
Re: Code for sensor still doesn't work

Quote:
Originally Posted by Ianuser View Post
Code:
		pwm03 != p3_y;
This doesn't do anything. What are you trying to do?

That evaluates to "is pwm03 not equal to p3_y". The answer is ignored, so the statement has no effect.

What do you mean for it to do?

--buddy
  #3   Spotlight this post!  
Unread 14-02-2007, 10:06
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: Code for sensor still doesn't work

Ianuser,

While I haven't really taken a detailed look at your code, I believe you want to make all your now/last variables static (static int now; ). As they are written, they will lose their value when the Default_Routine exits as they are only temporary stack variables.

Mike
  #4   Spotlight this post!  
Unread 14-02-2007, 10:17
Jake M Jake M is offline
void* Jake;
FRC #1178 (DURT)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Missouri
Posts: 118
Jake M has a spectacular aura aboutJake M has a spectacular aura about
Re: Code for sensor still doesn't work

I think that you think the code is constantly making sure that pwm03 is equal to p3_y. In reality, it only does this once, at the beginning of your code,
Code:
	if((now2 == 1) && (last2 == 0)) //p3_sw_trig sets joystick 3 y-axis to forklift motor. Use after each level.
	{
		pwm03 = p3_y;
	}
Once you pass this statement, the value of pwm03 does not change, unless you change it yourself, by saying pwm03 = whatever; It may seem like the value of pwm03 is constantly being changed to fit p3_y, when you run the code in real time, on the RC, but that's only because that single statement pwm03 = p3_y is being executed about 256 times per second.

What I think you mean by the pwm03 != p3_y statements is "I don't want pwm03 to equal p3_y anymore. Instead, I want it to be 127." In C (in fact in most programming languages) this is completely unnecessary. All you have to do is say pwm03 = 127; and it will overwrite the previous value.

However, I don't think this is the problem with your code. My guess is this.....

That switch only triggers for a minute fraction of a second, when the tape passes in front of it. The only way your code will work is if at the exact moment that the switch triggers (when rc_dig_in04 is 1), your program has to be executing the exact line of code that assigns rc_dig_in04 to another variable. If this is not the case, which it won't be 99% of the time, rc_dig_in will be 0, and your other variable will be zero, even if the sensor detected the metal tape. What you need to do is trigger an interrupt when the sensor triggers. What this will do, is when the sensor triggers, it will stop all your other code, and go straight to the interrupt handler (which can be found in user_routines.c) and execute that code, while the sensor is still triggered. You can add your own code to the interrupt handler and it is there that you can set another variable to 1, saying that the sensor has triggered, and handle the stopping of the motor and all that, elsewhere (where it is now is fine).

Edit: Yes, static variables are also necessary. Remember, this code is not executing constantly, it is executing many times each second. Which means that Default_Routine() is being called and returning many times per second. Each time it does, all your now and last variables are being reset to zero.
__________________
Code:
void function(void)
 {
  function();
 }

Last edited by Jake M : 14-02-2007 at 10:20.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My Chicklet doesn't work r_is_for_ROSER Control System 6 26-02-2007 11:20
I had an idea for my sensor. Will it work? Ianuser Programming 1 12-02-2007 00:38
even simple autonomous code doesn't work?? colman77 Programming 4 17-02-2006 23:58
For anyone who doesn't get the camera code..... Jake M Programming 8 16-01-2006 18:56
sensor doesn't work PBoss Programming 7 29-01-2003 18:39


All times are GMT -5. The time now is 00:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi