Go to Post There is no such thing as "un-GP." - Tetraman [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 11-01-2008, 16:40
taggartbg taggartbg is offline
Registered User
FRC #1712 (Dawgma)
Team Role: Electrical
 
Join Date: May 2005
Rookie Year: 2006
Location: Lower Merion, PA
Posts: 38
taggartbg will become famous soon enoughtaggartbg will become famous soon enough
Send a message via AIM to taggartbg Send a message via MSN to taggartbg Send a message via Yahoo to taggartbg
SetPWM and our IR controls

Hey everybody,

So I got the IR board programmed, got it all wired up to interface with the bot, coded it all out, and nothing happens. I currently only have one of the pins on the board (pin 5) running into the Digital In/Out (signal pin 1). I'm trying to get this working on a two-motor tank-drive bot with the '07 microcontroller. Here is my IR code:

Quote:
void OperatorController (void )
{
unsigned char ir1;
unsigned char ir2;
unsigned char ir3;
unsigned char ir4;

while ( 1 ) //I'm pretty sure I need this while loop, yes?
{
Tank2 ( 1 , 2 , 2 , 2 , 1 , 2 , 0 , 1);
ir1 = GetDigitalInput ( 1 ); //this should return "1" if it is getting signal, yes?
ir2 = GetDigitalInput ( 2 );
ir3 = GetDigitalInput ( 3 );
ir4 = GetDigitalInput ( 4 );

if ( ir1 == 1) //turn left at half speed
{
SetPWM ( 1 , 65 );
SetPWM ( 2 , 192 );
continue; //do I need this?
}

else if ( ir2 == 1) //straight at half speed
{
SetPWM ( 1 , 192 );
SetPWM ( 2 , 192 );
continue; //do I need this?
}

else if ( ir3 == 1) //turn right at half speed
{
SetPWM ( 1 , 192 );
SetPWM ( 2 , 65 );
continue; //do I need this?
}

else if ( ir4 == 1) //backwards at half speed
{
SetPWM ( 1 , 65 );
SetPWM ( 2 , 65 );
continue; //do I need this?
}

else //all stop
{
SetPWM ( 1 , 127 );
SetPWM ( 2 , 127 );
continue; //again, do I need this?
}
}
}
After a few attempts and nothing happing on the bot, I decided to try this simple code to start picking peice by peice what works and what doesn't:

Quote:
void OperatorController (void )
{
while ( 1 )
{
SetPWM ( 1 , 192 );
SetPWM ( 2 , 192 );
}
}
In theory, that should make the motors start moving forward at half speed yes? Well it just sits there doing nothing.


I was hoping someone could identify what exactly I'm doing wrong, as I am getting zero results from my bot.

Thanks,
/Taggart, team 1712
  #2   Spotlight this post!  
Unread 11-01-2008, 18:02
ham90mack's Avatar
ham90mack ham90mack is offline
President of RIT FIRST
FRC #0073 (The Illumination)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Rochester, NY
Posts: 120
ham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really nice
Re: SetPWM and our IR controls

Whoa there! You should (under most circumstances) NEVER have a loop in the robot code! Especially an infinite one. The only place that should have an infinite loop is in the main method. What you should do is remove the infinite while loop in this function and put a call to this inside the Process_Data_From_Master_uP in user_routines.c between the calls to the Getdata and Putdata functions. After doing that, you should be able to debug your code.

And you don't need the continue statements there...

Wait, if you are using EasyC (and it seems that you are), then the call to this function should be placed wherever the data processing function is (once again, without an infinite while loop inside this function).
__________________
Old stuff:

FRC 2007 Strategy Solver. Version: 2.55. Progress: done.

Last edited by ham90mack : 11-01-2008 at 18:06. Reason: add a few comments
  #3   Spotlight this post!  
Unread 11-01-2008, 23:03
taggartbg taggartbg is offline
Registered User
FRC #1712 (Dawgma)
Team Role: Electrical
 
Join Date: May 2005
Rookie Year: 2006
Location: Lower Merion, PA
Posts: 38
taggartbg will become famous soon enoughtaggartbg will become famous soon enough
Send a message via AIM to taggartbg Send a message via MSN to taggartbg Send a message via Yahoo to taggartbg
Re: SetPWM and our IR controls

Ah, I saw an infinite while in some similar sample code; however, I guess that was a bad idea. So thanks

And just to clarify (i'm kind of new to this), the data processing function is the main function? If not, then i'm a bit confused.

And I am using easyC Pro for this.
  #4   Spotlight this post!  
Unread 11-01-2008, 23:20
Branden Ghena's Avatar
Branden Ghena Branden Ghena is offline
Previously: tawnos23
FRC #0240 (TEMPEST)
Team Role: College Student
 
Join Date: Nov 2005
Rookie Year: 2004
Location: Houghton, Michigan (MTU)
Posts: 303
Branden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura about
Re: SetPWM and our IR controls

I would check that the wheels are actually hooked up to pwms 1 and 2 (don't laugh I've done this), and whether the code is actually running, i.e. the the robot is in operator mode and is enabled.

You could also try a simpler loop
Quote:
void OperatorControl (void )
while(1)
{
printf("hello");
}
If you hook your computer up to the robot, and leave it attached when you run it, this should show something (make sure the terminal window isn't in GD mode)

Yes, the data processing function is the operator control mode where you put this code, and it is called automatically from Main(); so you should be good.

P.S. Also, I program in EasyC and have never had any problems with infinite loops for testing purposes.
__________________
Branden Ghena - Michigan Tech Student and Team 240 Alumnus
Working Towards: Electrical Engineering and Computer Engineering Double Major

"All we have to decide is what to do with the time that is given to us." - Gandalf

Last edited by Branden Ghena : 11-01-2008 at 23:24. Reason: I needed to add some info
  #5   Spotlight this post!  
Unread 12-01-2008, 02:32
laultima laultima is offline
Registered User
FRC #1458 (Danvillans)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2005
Location: Danville, CA
Posts: 87
laultima is on a distinguished road
Send a message via AIM to laultima
Re: SetPWM and our IR controls

Im pretty sure you only need the while(1) loop if your programming for the VEX controller, which has all the operator code inside of that loop. For programming the Innovation First RC you don't need the loop.

And on the electronics side of things, make sure the PWMs are the right ways in (black is the ground on both the RC and the spike/victor)

Hope this helps.

Edit: If you're still stuck, try taking out the continues out. Im not sure if theyre the problem, but you dont need them for if statements.
__________________
2007 Davis/Sacramento Regional Winner (100, 997, 1458)

2008 Davis/Sacramento Regional Gracious Professionalism Award Winner


Last edited by laultima : 12-01-2008 at 03:19. Reason: addition
  #6   Spotlight this post!  
Unread 12-01-2008, 10:27
ham90mack's Avatar
ham90mack ham90mack is offline
President of RIT FIRST
FRC #0073 (The Illumination)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Rochester, NY
Posts: 120
ham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really nice
Re: SetPWM and our IR controls

In Kevin's FRC code, before processing the data you must call the Getdata function first in order to get the inputs from the controller and place them within a structure. Then after processing the data, you must call Putdata in order to put your outputs to the controller from the output data structure. Maybe the SetPWM does the assembly calls to put the data directly to the controller instead of putting it into a structure that is not directly linked to the actual outputs... I don't know. I have never used the EasyC coding libraries before so I don't know how it appears to do things like that.
__________________
Old stuff:

FRC 2007 Strategy Solver. Version: 2.55. Progress: done.
  #7   Spotlight this post!  
Unread 12-01-2008, 10:57
Vanquish Vanquish is offline
Registered User
no team
 
Join Date: Jan 2008
Rookie Year: 1980
Location: Somewhere
Posts: 19
Vanquish is an unknown quantity at this point
Re: SetPWM and our IR controls

I'm also new to programming and I am using 2007 default code. I have never done an autonomous before so any help would be appreciated.

Would something ilke this work?

Quote:
void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;
digital_io_01 = digital_io_02 = digital_io_03 = digital_io_04 = INPUT;

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */
if(digital_io_01==1)
{
SetPWM ( 1 , 65 );
SetPWM ( 2 , 192 );
}

Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
  #8   Spotlight this post!  
Unread 12-01-2008, 11:23
ham90mack's Avatar
ham90mack ham90mack is offline
President of RIT FIRST
FRC #0073 (The Illumination)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Rochester, NY
Posts: 120
ham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really niceham90mack is just really nice
Re: SetPWM and our IR controls

It appears that that may work, except there is no such function as SetPWM in Kevin's code. Instead, use:
Code:
pwm01 = 65;
pwm02 = 192;
So your code appears to do one thing: if the first programmed IR signal is sent, drive forward forever (or spin forever, depending on how your motors are mounted). That sounds a little dangerous for a first test unless your robot is off the ground. I suggest having a signal to stop the robot as well.
__________________
Old stuff:

FRC 2007 Strategy Solver. Version: 2.55. Progress: done.
  #9   Spotlight this post!  
Unread 12-01-2008, 11:25
Vanquish Vanquish is offline
Registered User
no team
 
Join Date: Jan 2008
Rookie Year: 1980
Location: Somewhere
Posts: 19
Vanquish is an unknown quantity at this point
Re: SetPWM and our IR controls

Quote:
Originally Posted by ham90mack View Post
It appears that that may work, except there is no such function as SetPWM in Kevin's code. Instead, use:
Code:
pwm01 = 65;
pwm02 = 192;
So your code appears to do one thing: if the first programmed IR signal is sent, drive forward forever (or spin forever, depending on how your motors are mounted). That sounds a little dangerous for a first test unless your robot is off the ground. I suggest having a signal to stop the robot as well.
Yea, I realize that I just wanted to know if the format looked alright, thanks
  #10   Spotlight this post!  
Unread 12-01-2008, 14:27
itsme itsme is offline
Registered User
FRC #2217 (FOMH)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Israel
Posts: 86
itsme is an unknown quantity at this point
Re: SetPWM and our IR controls

taggartbg, This may sound obvious, but make sure the PWM cable is connected FROM the victor TO the RC on the PWM ports (ports 1 and 2).
Could be you connected it to a spike, and to the best of my knowledge, you can't put half speed when the motor is connected to a spike.
As said by others, you don't need the continue statement.
And in EasyC pro you do need an infinite loop but put it in the MAIN function (I'm doing it that way).
It's not good to put an infinite while loop in your own functions.
Just put a while(1) loop in MAIN function, and then drag and drop your OperatorController function into the loop and it should work properly.
__________________
2007 Israel Regional GM/Technion Rookie Allstars
Participated in 2007 Atlanta World Championships (Newton Division)
  #11   Spotlight this post!  
Unread 12-01-2008, 15:10
taggartbg taggartbg is offline
Registered User
FRC #1712 (Dawgma)
Team Role: Electrical
 
Join Date: May 2005
Rookie Year: 2006
Location: Lower Merion, PA
Posts: 38
taggartbg will become famous soon enoughtaggartbg will become famous soon enough
Send a message via AIM to taggartbg Send a message via MSN to taggartbg Send a message via Yahoo to taggartbg
Re: SetPWM and our IR controls

Hey guys, thanks for the help, I think i'm getting there; however, I'm still having some struggles.

I'm begining to think that I'm just doing something really simple wrong. Here is the process I undergo to test my code.

1) Code in easyC Pro in the OperatorControl function (I've also tried in Autonomous)
2) Power up robot
3) Hold down "prog" until the "Program Status" LED turns a solid orange
4) In easyC, I hit Build & Download
5) Once it is loaded, I power down the bot
6) When I power it back up, the code should automatically execute, yes?
  #12   Spotlight this post!  
Unread 12-01-2008, 15:17
Branden Ghena's Avatar
Branden Ghena Branden Ghena is offline
Previously: tawnos23
FRC #0240 (TEMPEST)
Team Role: College Student
 
Join Date: Nov 2005
Rookie Year: 2004
Location: Houghton, Michigan (MTU)
Posts: 303
Branden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura about
Re: SetPWM and our IR controls

Do you have a operator interface hooked up?
__________________
Branden Ghena - Michigan Tech Student and Team 240 Alumnus
Working Towards: Electrical Engineering and Computer Engineering Double Major

"All we have to decide is what to do with the time that is given to us." - Gandalf
  #13   Spotlight this post!  
Unread 12-01-2008, 15:24
itsme itsme is offline
Registered User
FRC #2217 (FOMH)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Israel
Posts: 86
itsme is an unknown quantity at this point
Re: SetPWM and our IR controls

Make sure you put your OperatorControl function inside the main function.
And I don't think you have to power down your robot, it should automaticly work well.
Make sure you are not programming in competition mode (when it's divided to 3 functions). 'Cause that way I don't think it can work (I think it only works when you are in a competition [when the competition port on the OI is connected]).
Just to the following:
1) Open a regular new EasyC pro project.
2) Make your OperatorControl function (in the user functions).
3) Drag and drop the OperatorControl function you just made into a while(1) loop in the main function.
4) Power up the robot.
5) Hold down "prog" until "Program Status" LED turns orange.
6) Press Build and Download in EasyC pro.
7) Now it should work

I suggest you first build and download a simple program (like putting your motor in half speed) and check if it works well.
Again, check if the PWM cables are connected to the victor that is connected to the motor you want to activate.
Hope it helped.
Team 2217
__________________
2007 Israel Regional GM/Technion Rookie Allstars
Participated in 2007 Atlanta World Championships (Newton Division)

Last edited by itsme : 12-01-2008 at 15:36.
  #14   Spotlight this post!  
Unread 12-01-2008, 15:29
laultima laultima is offline
Registered User
FRC #1458 (Danvillans)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2005
Location: Danville, CA
Posts: 87
laultima is on a distinguished road
Send a message via AIM to laultima
Re: SetPWM and our IR controls

Quote:
Originally Posted by tawnos23 View Post
Do you have a operator interface hooked up?
you do need the OI connected to the RC either by radio or tether before the code will run
__________________
2007 Davis/Sacramento Regional Winner (100, 997, 1458)

2008 Davis/Sacramento Regional Gracious Professionalism Award Winner

  #15   Spotlight this post!  
Unread 12-01-2008, 15:33
taggartbg taggartbg is offline
Registered User
FRC #1712 (Dawgma)
Team Role: Electrical
 
Join Date: May 2005
Rookie Year: 2006
Location: Lower Merion, PA
Posts: 38
taggartbg will become famous soon enoughtaggartbg will become famous soon enough
Send a message via AIM to taggartbg Send a message via MSN to taggartbg Send a message via Yahoo to taggartbg
Re: SetPWM and our IR controls

AHH! I've been creating competition projects ...I'll post back when I get a chance to create a standalone and try it out.

Thanks again.
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
help us program our controls dude_brd Programming 1 10-02-2007 12:02
need help on programing our controls dude_brd Programming 1 07-02-2007 18:42
FRC: Reset and Program Controls yanksrock777 General Forum 4 24-01-2007 22:37
Push Button and Switch Suppliers for OI controls Goldberg204 Control System 8 11-01-2007 15:27
pic: 383`s controls and driver Manoel Robot Showcase 13 03-03-2005 00:57


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

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