Go to Post The only teams who have no chance of winning are those who believe they can't win. To quote the greatest athlete of our generation: "Limits like fears are often just an illusion." -- Michael Jordan - Karthik [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 12-02-2008, 16:51
captainking's Avatar
captainking captainking is offline
Level 85 Programmer
FRC #0168 (MIB)
Team Role: Programmer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: North Miami Beach
Posts: 41
captainking is an unknown quantity at this point
two drive styles

We have two robots this year, one driven by tank style and one driven by arcade style, and so we don't have to switch the code when we switch robots, we want to put the code for both robots under one file. we can't figure out how to get it to work, either one works, neither works, or both work but they start competing. How can we arrange the code so that it allows for both tank and arcade mode? We have arcade set to port 1 and tank set to ports 2 + 3
  #2   Spotlight this post!  
Unread 12-02-2008, 17:02
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: two drive styles

A very way to do this is preprocessor directives. Keep arcade set to 1 or 2 and have tank set to 1 and 2 (assuming those are the ports you have your joysticks plugged into). Then at the top of the file, type either

Code:
#define TANK
or

Code:
#defien ARCADE
Then, in your main code, put

Code:
#ifdef TANK
(put your tank code here)
#else
(put your arcade code here)
#endif
When you go to compile, if TANK is #defined, it will use your tank code. If you change #define TANK to #define ARCADE (or anything else for the matter), your arcade code will be used instead. This is done when the code is compiled, not as it is running. Therefore, to change which drive configuration you would like to use, simply change the #define up top.

Our team is using code like this, which I will post here tonight as an example once I get to the meeting
__________________
  #3   Spotlight this post!  
Unread 12-02-2008, 17:39
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: two drive styles

Preprocessor directives still require you to recompile the code for each robot. Here's what I've done in the past, and what I recommend doing, in order to control multiple robots with the same code:

First, make sure that your code is well isolated. Create a robot.c/robot.h file which defines all the robot functionality. It will have a functions like robot_drive_1(speed, turn), robot_set_arm_position(height), etc. This should be the ONLY place in all of the code which sets any PWM output values. (Even with only one robot, this will make adapting the code to changes in the design faster & easier.) Similarly, isolate all of your OI into one place. With one robot, I generally have a file, oi.h, where I will do things like: #define drive_x p1_x and #define drive_y p1_y, etc. With different OIs, you might want to handle that a little differently.

Second, make sure that your code can tell the difference between the two robots. The easiest way to do this is to make a jumper that shorts one of the digital inputs to ground. (i.e. connect the two outside pins, or the white and black wires from a pwm cable.) In robot.h you will have defined which pin this is (something like #define ROBOT1 rc_dig_in17).

Now you can do something in your code like this:
Code:
if (ROBOT1)
{
    robot_drive(oi_drive_left, oi_drive_right);
}
else
{
    robot_drive(oi_drive_speed+oi_drive_turn-127, oi_drive_speed-oi_drive_turn);
}
(Please note: the above is PSEUDO-CODE and may not actually compile, or work correctly if it does compile.)

Similarly, you could do this on the OI by wiring a jumper to close one of the unused pins (p4_sw_aux1 or similar) on a joystick input port. Look for this in the code to determine which OI you are using.

Personally, the height of doing this was in 2006, where we had four robots (two teams each with a competition robot and a practice robot based on the previous year's robot) and four OIs (two with steering wheels - each with their own bias, two with joysticks). I used two digital i/o pins on each robot and two joystick ports on each OI, and any OI could be used to drive any robot, all with the same code loaded onto each robot. For the record, I would not try to support so many different combinations again, but it can be done.
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion
  #4   Spotlight this post!  
Unread 12-02-2008, 18:21
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: two drive styles

While this can be done, the reason I used preprocessor directives instead was that when done with preprocessor directives, no unneeded code is compiled. Of course, if you do want to switch layouts during run or automatically detect a layout during run, the above method would work great.
__________________
  #5   Spotlight this post!  
Unread 14-02-2008, 14:09
RyanW RyanW is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2007
Location: MD
Posts: 40
RyanW has a spectacular aura aboutRyanW has a spectacular aura about
Re: two drive styles

Guys, he said EasyC!

You could put some sort of switch on the OI, to change from one to the other...if the switch is 1, drive in arcade mode or if it's 0 drive in tank, something like that...
  #6   Spotlight this post!  
Unread 12-02-2008, 17:33
captainking's Avatar
captainking captainking is offline
Level 85 Programmer
FRC #0168 (MIB)
Team Role: Programmer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: North Miami Beach
Posts: 41
captainking is an unknown quantity at this point
Re: two drive styles

thanks for the help, but how do we hardcode in easy c? We can only find premade blocks, so how can we make that code?
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
Controlling a Mecanum drive with two joysticks? Leav Technical Discussion 9 09-12-2007 19:11
Rendering & Lightening Styles rohit Inventor 2 07-03-2007 20:25
Will FIRST teams start using Web 2.0 styles? Michael Hill Website Design/Showcase 15 03-01-2007 02:52
Putting two and two together... Andy Grady General Forum 13 08-01-2004 18:29
How formal are your writing styles for the Chairman's award? Katy Chairman's Award 16 16-04-2003 20:07


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

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