View Full Version : What are we supposed to do!?!?!?!??!?!
Bomberofdoom
11-01-2007, 09:55
We've went over the code, looked a bit at the functions and other macro stuff.
But we don't have a clue what's going on there!:ahh:
What's with the PWMs?
Where's the parts with the engines moving?
What are we supposed to write?(as in, in the intilazation, what happens there, the autonomus, what do we use; in the free part, what needs to be modeled....
WHAT ARE WE SUPPOSED TO DO!?!?!:ahh:
(sorry, just totally desprate trying to understand what we need to do while we're being shouted at from every direction, being asked to start writing while we have no clue what to do).
If youre totally lost and havent programmed before, I'd suggest that you use the easyC, personally its not my favorite but it is easy to get started... you can find it in your KOP.
The 'pwm's are pulse width modulators, in effect they control the speed of motors. If you want more detailed explanation I'll be happy to give you one. From the programming interface the pwm drives are insanely easy to use, just remember that 127 is neutral, 254 is full forward, and 0 is full reverse. Everywhere in between is variable power output on the motors in forward and reverse directions.
hopefully that answers a few questions, if you have more, i'll be happy to answer them.
-Q
Bomberofdoom
11-01-2007, 10:12
Yes, I know about the PWM numbers of forward and backwards and I'm expirienced with C(even with Visual c++), but what am I supposed to do now? You say the drive system is easy, but I don't understand what am I supposed to look at that it shows that it's easy!
I've asked someone from another team in my country and from what I understood, he said that it is all written there.
But I don't see it! I only see that they put the values of p1_y(which is what?!?!) to pwm01 and all kind of other stuff, but I don't see anything with number values(mabye except with the leds). Is that where I'm supposed to write the engines part??
If your using MPLAB and you find yourself blown away, dazed and confused, I would heed the EASY-C recommendation. There are several Easy-C totorials included in the software and online.
Bomberofdoom
11-01-2007, 10:15
But we don't know what to do in EasyC. We're used to raw C code. These blocks are confusing(safe, but confusing).
Francis-134
11-01-2007, 10:18
But we don't know what to do in EasyC. We're used to raw C code. These blocks are confusing(safe, but confusing).
If you are at all confused by anything in easyC, simply press F1 on the keyboard and go to the help file. Similarly, there is a button on every block that will bring you directly to the help page about that block. Intelitek spent literally months writing the help file. It is extremely detailed about every function included in easyC Pro.
Yes, I know about the PWM numbers of forward and backwards and I'm expirienced with C(even with Visual c++), but what am I supposed to do now? You say the drive system is easy, but I don't understand what am I supposed to look at that it shows that it's easy!
I've asked someone from another team in my country and from what I understood, he said that it is all written there.
But I don't see it! I only see that they put the values of p1_y(which is what?!?!) to pwm01 and all kind of other stuff, but I don't see anything with number values(mabye except with the leds). Is that where I'm supposed to write the engines part??
p1_y -> Port 1's y-axis (Ie: The y-axis of the joystick plugged into port 1)
pwm01 -> this is the code representation of PWM01 on the RC
the code pwm01 = p1_y would map the y-axis of port 1's joystick to PWM output 1.
I recommend the RC Reference guide, found here. (http://ifirobotics.com/rc.shtml) Reading that should answer your questions.
Tom Bottiglieri
11-01-2007, 10:20
These power points taught me to program the robot 4 years ago. The code has changed a little since then but the concepts are still the same.
http://www.usfirst.org/community/frc/content.aspx?id=482
Watch all of them.
Hello, I am from team 2230 too.
We have a default code in our mplab program (like everyone else).
What are we supposed to change in it? It seem to be quite complete :rolleyes:
Bomberofdoom
11-01-2007, 10:27
We already went through the presentation of the C and it didn't give us the real help. It told us where to go but not specifically what to do(yes, write your autonoms code. But what values, varibles, functions etc. are we supposed to use in it?).
What really helped was the the RC reference guide, thx!
Remember that this program actually runs in a HUGE loop. In other words, the program runs through lots of times per second. Program will check the status of the Operator Interface and will adjust the values of the PWMs accordingly. This is how the robot is able to have variable speeds.
As for the PWMs, looks in user_routines.c and look around for the "pwm=xx;" where xx is a number or perhaps another variable like the value of the joysticks.
The default code provided by FIRST controls the Kitbot rather nicely. If hooked up correctly, the Kitbot can move with either 1 joystick or 2.
-----------------------------
The following explaination is based off of the code we used 2 years ago. I'm sorry if I get some things wrong and if I do, please correct me. It has been 2 years since I was a programmer.
void User_Initialization (void)
this is where you initialize the ports on the RC. In other words, you are setting those pins on the Robot Controller to do something, like be an output(gives out power) or input(receives a signal for a sensor).
void Default_Routine(void)
this is where the controls are at. Remember how I said that the program runs in a HUGE loop? Well this is part of that loop. This function looks at all the values of the Operator Interface (like the joystick values) and through some "if" and "else" statements, it can control the motor's speed.
---------------------------------------
Like Qbranch said, easyC is a good introduction to C programming. I think it is setup so there is an "operator control" section and "autonomous" section so it well orgranized.
Matt Krass
11-01-2007, 10:30
There is a function in user_routines.c called Default_Routine(). This is basically your playground, this function runs about 38 times a second (26.2 milliseconds) and you put all your logic in here. Your OI data (joystick values, buttons pushed) is all available in aptly named variables (p1_y, p2_x, p2_sw_trig, etc) that you can check with if statements. For example to make the trigger on the joystick connected to Port 1 drive the robot forward and your motors are on pwm01 and pwm02 you might try this:
// in Default_Routine()
...
if(p1_sw_trig) // If the trigger is pushed
{
pwm01 = 255; // Left motor full speed forward
pwm02 = 0; // Right motor full reverse since it's likely facing the opposite direction
}
else // Trigger is not pushed
{
pwm01 = 127; // Motor stopped;
pwm02 = 127; // Motor stopped;
}
Note this is not a recommend way to drive, you're better off mapping the pwm outputs to the joystick inputs like this:
...
pwm01 = p1_y;
That should be enough for you to get started, it's all just basic logic.
Good luck!
Bomberofdoom
11-01-2007, 10:31
Autonomous Mode means that the RC will ignore all data from the Operator Interface and it will not
require a link with the Operator Interface to execute code.
If you wish to run the Robot Controller exclusively in Autonomous Mode, one way to do this is to set
your team number to zero. This is done by setting the team number on your OI to zero, linking your OI
and RC by tether, and then disconnecting from tether. After your RC is reset it will be in Autonomous
Mode.
To exit Autonomous mode if your team number is zero, you must re-tether and change the team number
to anything but zero.
An additional method for getting into Autonomous Mode is described in the Operator Interface
Reference Guide in the “Competition Control LED” section. See the Programming Reference Guide for
details on how to program for Autonomous Mod
Where is the team number value?(which source file?)
Bomberofdoom
11-01-2007, 10:34
Ok, so I read about the joystick movment thing.
Do we need to build that code of if's? Do we need to make these macros to check the joystick axis status?
Actually, can't you make something that will simulate the master controllers used at FIRST? You can connect some switches to that 'competition' port on the top and run either autonomous or disable the robot. Not really sure what pins but it can be done.
bear24rw
11-01-2007, 10:39
The team number isnt set in the code, its setting in binary using the dipswitches..
Also, just try to get a copy of someones code (i would upload mine but i dont have it with me) and just look through it and try to learn it. Before last year I didnt have a clue what a #define statement was, i just read over the code from previous years over and over again and read all the programming papers on ifirobotics.com... now i knew the controller inside and out...
Good luck
Matt Krass
11-01-2007, 10:42
Ok, so I read about the joystick movment thing.
Do we need to build that code of if's? Do we need to make these macros to check the joystick axis status?
Every loop the controller updates the values in the P*_* variables, including axes and buttons. All you have to do is use logic on the values and set your pwm** variables.
Bomberofdoom
11-01-2007, 10:50
What do you mean by setting our own PWM** values?
Ok thanks alot for your help.
What do we have exactly in our code allready, and what should we use with it?
Joe Johnson
11-01-2007, 11:21
But we don't know what to do in EasyC. We're used to raw C code. These blocks are confusing(safe, but confusing).
I am not surprised that you are confused.
The Default code is a real mess in my opinion. It is a mix-mash of a bunch of legacy stuff from the early years of FIRST and a bunch of patches and band -aids applied to add new features and functions.
Here is the basic idea:
Inputs from the Operator Interface (OI) come from 4 ports -- they themselves are legacy 15 pin game ports from the early days of the IBM PC. Each port has switches and analog inputs.
The switches are defined this way: pN_sw_SWITCHNAME where N refers to the port number and SWITCHNAME refers to "top", "trig", "aux1" and "aux2" Depending on what brand joystick you use these switches will be available out of the box or not -- if not, and you need those switches, you will have to build a custom harness to get access to the switches. The default code has structures and aliases defined for you that allow you to treat these switches as either 1 or 0's
The analog inputs are defined this way:
pN_ANALOGNAME where N refers to the port number and ANALOGNAME
Refer to "X" "Y" "WHEEL" and "AUX" Again depending on what brand joystick you use these analog inputs will be available out of the box or not -- if not, and you need those inputs, you will have to build a custom harness to get access to the analog inputs (wiring in your own potentiometer for example). The default code has structures and aliases defined for you that allow you to treat these analog inputs as either a number between 0 and 255 -- with 127 being the nominal center position of the joystick.
You have similar naming conventions for inputs on the Robot Controller's analog and digital inputs.
The outputs on the RC are basically the PWM values 0-254 and relays (which are of the form rc_dig_outNN).
In order to control a motor, you just assign the PWM output to a value 0 = full rev, 127 = off, 254= full fwd. The default code simply maps joystick values from the OI to PWM outputs on the RC. It also has some example methods of mapping limit switches to particular PWM output so that the motor will turn off when an end of travel switch is made. If you know C and you know how to access the various inputs and outputs, you should be able to write code to let your robot do what ever you need it to do.
Good luck.
Joe J.
Mark Pierce
11-01-2007, 13:38
In preparing for some intro to programming sessions I held this year I spent some time looking for what you're after. I'm hoping to organize my thoughts into a white paper or something, but haven't had time to clean it up. Currently there are some of my notes on my website Marks programming page (http://s94932053.onlinehome.us/index.php?page=programming) which might help with some references to some resources.
Here's a quick sketch of how our team tries to approach programming:
First: Familiarization -Get the default code compiling, downloading, and the controllers talking to each other, try connecting a joystick and motor or two and see how things work.
Second: Functional Requirements - Identify what functions need to by done by the controller. Every team's program will handle some operator input, use some robot sensors such as limit switches, and drive some outputs. The basic joystick as input and drive train as output is in the default code because it is the most common to all teams.
Third: Design -Break these functions down into smaller pieces and identify those that can be easily handled, and those which you will need to do more research or find help for, such as camera, timers, or other sensors.
Fourth: Implement - Make a working copy of the default code. Cut out parts of the example code that you won't need. Define macros for your names of inputs and outputs. Declare functions or at least insert comments for those things you need to add. Then start coding.
The Default code is a real mess in my opinion.
I hope to have something ready soon (this weekend) showing how we are rearranging the default code into a framework to work from.
Run the default code first. After loading the code into the robot controller, open the terminal, if the statement "printf(..." is not commented out, it will print the values for the joysticks. You can add other variables (like switches) to the printf. Move the sticks and see what values change. Look at Default_Routine() like the other poster said.
Look at ifi_aliases.h for the possible variables you can read and set.
Autonomous mode is in user_routines_fast.c. Look at User_Autonomous_Code(). It runs in a loop so you have to have a state machine. After you get the robot going and a few things figured out, then search around for an example or post back here.
Note: The operator interface will not talk to the robot controller until you set the team number on the IO and tether it first.
Hope this helps,
Brian
Bomberofdoom
11-01-2007, 16:09
Thanks for the help guys.
I guess the only problem is right now is just trying to dycript those small macros, functions and other varibles and how they relate to the robot or OI.
But our Programming group all agreed that we've reached the begining point and we can probablly see the next step ahead(with minor help from you guys and Delphi).
Thanks again :D
Bomberofdoom
11-01-2007, 16:19
BTW, I find the previous codes some people sent very usefull. It'll also help me and the team to get some more work to do(I'm head of the programming team{and look how desperate I was}).
Please send any previous codes you can(with comments of course, so we may understand :D). We will really appreciate it.
robbekid
11-01-2007, 16:25
read kevins code, he has really well documented code, i am learning the programing this year as I am planning on helping with the programming from next year on wards, so i have been working with just decoding kevins FRC code.
bear24rw
12-01-2007, 16:30
read kevins code, he has really well documented code, i am learning the programing this year as I am planning on helping with the programming from next year on wards, so i have been working with just decoding kevins FRC code.
www.kevin.org/frc
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.