![]() |
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
|
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 TANKCode:
#defien ARCADECode:
#ifdef TANKOur team is using code like this, which I will post here tonight as an example once I get to the meeting :D |
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?
|
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)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. |
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.
|
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... |
| All times are GMT -5. The time now is 00:56. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi