I’m new to FRC, new to my team, just getting started with the program and have no idea where to begin so that we might be able to program a robot in 2 weeks (2 robots actually because I’m helping two teams).
I have not used EasyC before but I talked to the programming mentor from another team and he suggested both the program and these forums. Where should I start so that I can advise the teams on how to complete their programming in a serious time crunch.
What information do I need to read that you can link me to?
What are the basic things I need to know, and where can I find the stuff that will put me there.
Also, I need code examples; I have experience with coding in java and vb.net and a host of web based stuff, but none with C; I need to know what FRC C code should look like.
Finally, I heard that the kits come with a lot of working code examples from the start; because of time constraints I think I’ll have to use alot of these but the teams I’m working with are not the most organized and don’t know where all their kit information and tools are. Pleaes direct me to links where I can find backups of all the FIRST code samples and programming guides.
First off, welcome to the FIRST programming arena!
You should start by installing easyC on your computer, and making sure your COM port / USB-Serial adapter is working (You can check this out in device manager)
Then you can start coding.
easyC is set up so that when you make a new file, there are three blocks. Initilization, Autonoumous, and Operator Control. If you need help defining WHEN these occur, let me know.
You can put code in each of these block to occur during that time period. To start off with, open the Operator Control block by right clicking on it and hitting open.
Then you can put code inside of here. On the left under Program Flow, click and drag a while loop (If you know Java, you know what this is…) and put in 1 for the value to end up with a while(1) loop. This is like a while(true) loop in Java.
So now you have an endless loop. Anything you put inside this loop will occur over and over again forever. The idea is that each time this loop runs through, conditions are checked and stuff happens based on it. It would be a good idea to put some blocks on top to check to see if your E-Stop is enabled and to stop your motors if it is, but for right now, you just want to get something downloaded to your robot (I assume. I can create a follow-up post that gets into more detail.)
OK, so now you want to be able to drive the robot. On the left under RC Control (Or something like that, can’t remember off the top of my head) is the Aracade 2 Motor Block. Click and drag this block INSIDE your while loop. Then configure the correct PWMs based on your bot. Hint: Typically you need to invert 1 motor because 1 motor is ‘backwards’. If you did it the wrong way (you will find out later,) then just reverse them.
OK, so now you have a simple program. So you want to compile it. Click on the compile button in the toolbar above (A Stack of index cards with arrows on top of it (At least thats what I think it looks like…)). When thats done, click on the button to the right of that button to build and download it to your bot. Connect the serial cable to the Program port on your bot and press and hold the PROG button on the bot until the program state light turns orange. DO NOT CONTINUE TO HOLD DOWN THE PROG BUTTON!! This puts the controller into a funky state.
Ok, so now it should have downloaded your new program. MAKE SURE that your OI is off whenever you download a new program so that when it’s done downloading it doesnt just start excecuting. This can be dangerous because if you aren’t near the OI you can’t unplug it, or it could rip the laptop out of your hands. After the program is downloaded, disconnect the serial cable, and turn on the OI, keeping your hand on the power to the OI, should you need to disconnect it.
You probably need to trim your POTS now, because the joysticks that come with the kit usually aren’t trimmed, this can be done by turning the little dials on the top and side of the joystick until the motors stop humming/moving. Typically this is somewhere near the center position.
OK. This should be enough to get you started. Let me know when you are done with this, then give me some idea of the direction you want to go, and I can step through it with you.
Hope this help!,
Jacob
–
Remember, if this post was helpful, good Rep is always good…
Good point. The getting started manual built into easyC is very helpful, especailly when finding out more information about a particular block of code provided for you.
Thanks, I’ll take a look at both of those when I get back to the robotics lab this afternoon. I was wondering though if there were things available I could look at while at the office. I have my lunch break and a couple other low load times where it would be nice to have something to read over. I don’t have access to EasyC or the computer I’ll be working with while at work. I’ve done a few searches on these forms for beginners and newb coders but have returned no results.
OK cool.
I’m glad you are taking the initiative to do stuff, because I know a lot of people that wouldn’t even want to try.
Alright. I’m going to tackle the code first, and then I’ll look at your logistics.
In easyC, the 2WD Arcade block is REALLY easy. Once you place this block, it give you all of the options. It asks which port your joystick is on, which axis you want to use for both x and y, and which motors to control in which directions. No code involved. Its a GUI. This means you don’t have to initialize varibles, get values, etc. easyC does it all for you.
As far as logistics. A few years back there was a simulator, but that was for the old PBASIC chip, and there is no new C simulator. It should be easy enough to set up your computer to download code to. Here is a link to the pdf with the wiring diagram:
All you need from this diagram is a path from the battery to the comptuer for power. You obviously don’t need to hook up all of the spikes and victors and peripherals.
If you REALLY just want to get started, find a 12 volt transformer, cut whatever end is on it off, put spade connectors on the ends and hook it to the computer. This is NOT reccomended by FIRST, because it is not fused, but as long as it is a low amp power supply (i.e. <10 AMP max), it shouldn’t be a problem.
OK, so here is some background.
The RC needs to be connected to the OI. The OI is where you connect your joysticks, and the RC is where you connect your motors etc, (a.k.a. The Computer.) The easiest way to do this is with the TETHER cable (The red serial cable.) This will power the OI over the tether cable without requiring additional power to the OI via a 9v transformer.
The other way to connect them is over the radio. You can use serial cables to connect the proper radios to the RC and OI (they should be labeled as to which is which)…
You then plug your computer into the Program port. This is how programs are downloaded. You need to put the processor in program mode by pressing the PROG button until the Program State light turns orange.
You can leave the serial cable plugged into the Program port to get feedback on the computer through the Terminal in easyC, if you put in PrintToScreen statements in your code. Be careful that you have control of the robot in this situations as not to rip your laptop off the desk.
Your devices are then plugged into the RC. You can plug your Speed Controllers (The Victors) into the PWM ports using the Black/Red/White wires. The Victors have varible control over the motors.
I would reccommend that you build your power system as soon as possible. This means the Distribution Block, the Black Circuit Breaker Panel, your computer, and a few devices. I say this because if you power your speed controllers, you can watch the lights change color based on the output of the PWM going to it. This can be used as an indicator as far as your program working.
What did I leave out? I’m sure I left something out somewhere…
Let me know,
Jacob
BTW, can I post this on CD? Other teams may have the same question, and I put a bit of time putting this together (I don’t mind, in fact I love helping other teams, I would just like other teams to benefit.)
–
Remember, if this post was helpful, good Rep is always good…
Again thanks much, I’m looking at the diagram and I’ll do some considering over the next few hours and get back to you with questions. I don’t want to waste too much of your time with questions that might entirely too simple to answer myself once I have my hands on the robot.
Post it where-ever you’d like, I appreciate the help and if other teams are as far behind as ours, I’m sure they will also.
lol. I’m 6’ 1" and still going…
Got some back problems though…
Anyway, I sent this PM. I wanted to put it up here so others can enjoy.
OK. I’m glad that you are able to get your robot moving. This is the first step to a working robot (from a programming aspect. Even though on our team the programmers wind up getting the mechanical team out of the jamb more times than not :p. jk. not really.)
Anyway, pnuematics. You need to hook the pressure regulator somewhere in your 120psi system to hook back to the computer via a digital input. This is what tells the compressor to turn off. You need a little bit of code that checks the Nason (I think it’s Nason. Thats who made it last year. I haven’t looked at it this year,) and if it’s High (1) turn the compressor off. This means that your compressor needs to be on a relay. I think there is a block in easyC to put a Digital input directly to a varible, and then set the relay directly from a varible. There may be a more effecient way to do this. It must be done, check rule <R103>
Thats the compressor. All thats left are the pneumatic switches. These are simply attached to relays, and controlled via the computer. Remember that relays can do forward and reverse, and to always have that relay set in one of those positions, not off, because you have no idea what state the piston will be in if you do this.
You can control relays using built in blocks in easyC. If you need me to go into more detail, let me know, and I’ll boot up my programming laptop and walk you through it.
Hope this helps,
Jacob Komar
–
Remember, if this post helped, good Rep is always good…
easyC has a block called “Pressure Switch” in outputs drag it into initialize and specify the relay and input port and it will watch the compressor for you.
I’m going to explain how to setup a simple pneumatic system.
I’m assuming that your power system is completed (i.e. Your black circuit panel has power and you have some fuses in place.)
OK. So now you need hook up you electrical. You are going to need 2 relays to control one solenoid (1 for the compressor, 1 for the solenoid.) Put power to both relays form the circuit panel, and hook a black/red/white cable from each relay to a relay port on the RC. (1 and 2 are very convienent ports to use.) The air compressor can then be wired to one of the relays (Use relay 1, just for now.) Lets start off with a single solenoid valve (either the FESTO of the single SMC.) Wire this to the other relay (Relay 2.) The only thing left to wire is the pressure valve, which you can put into digital input 1. I don’t remember if this comes with a connector on it that fits directly onto the board. If not, you will have to make one. One wire needs to be connected to black, and the other to white. Red is not used in this application. By the way, I am assuming you are hooking up all of the wires in the correct orientation as noted on each device (i.e. V- means black, White to White on black/red/white cables, etc…)
OK, so now you can hook up your pneumatic system. It should look like page 11 of this:
Yes, you need all the regulators, yes you need all of the gauges, yes you need the tanks (at least 1), and yes you need the Nason. You have no choice on these things, so if all of that is too much weight, then you can forget pneumatics now.
All of that stuff just fits together with the supplied fittings and hose, along with a bit of teflon tape (essential.)
OK, so all thats left is your program. I attached a sample program written in easyC; It turns out there is a pressure switch block now available (I don’t remember that from the old version… Oh well, I don’t really use easyC all too often anyway…) For your convience I copied and pasted the code below so that you can at least view it now. I commented it. It is very simple.
#include “Main.h”
void OperatorControl ( void )
{
while ( 1 )
{
Arcade2 ( 1 , 1 , 1 , 2 , 1 , 2 , 0 , 1 ) ; // A nice little drive block
InitPressureSwitch ( 1 , 1 ) ; // This turns on and off your compressor
OIToRelay ( 1 , 1 , 2 , 1 ) ; // Switches the solenoid one way with the trigger
OIToRelay ( 1 , 2 , 2 , 2 ) ; // Switches the solenoid the other way with the thumb button
}
}
And that should be it. Let me know when you have more questions.
Jacob
> I’d like
> to make the time with the students as productive as possible, so if you can walk
> me through it while I’m at work and I can get the understanding. I’ll be bette
> prepared to help them. Next year’s first will go much smoother I believe
> because I’ll be involved from day one instead of mail in day - 20.
This is not correct but close. The presure switch only needs to be called once. Good work though.
void OperatorControl ( void )
{
while ( 1 )
{
Arcade2 ( 1 , 1 , 1 , 2 , 1 , 2 , 0 , 1 ) ; // A nice little drive block
InitPressureSwitch ( 1 , 1 ) ; // This turns on and off your compressor
OIToRelay ( 1 , 1 , 2 , 1 ) ; // Switches the solenoid one way with the trigger
OIToRelay ( 1 , 2 , 2 , 2 ) ; // Switches the solenoid the other way with the thumb button
}
}
Good catch. Thanks. I have never used this before… I don’t think it was available (right? or am I just dilutional?)… I’ve always done it manually in the loop…
Maybe you can tell me,
Why does the drive code need to be in the loop, but not this pressure code? It seems like it should check every time… Unless it is something like a header, where it just permanently assigns that digital input to the relay? Perhaps you can explain how this works?
The presure code has been in easyC since easyC for FRC last year.
The presure switch has a premade function that basicly monitors the switch and the turns off the compressor once it closes. Nothing ever changes always the same relay and same input and you normaly never want to stop checking. The function PresureSwitch function that you call basicly just enables a function and it runs in the background. Kind of a set and forget type thing. There are a bunch of functions like this in easyC like StartTimer, StartGyro, StartCamera, and all The Init functions only need to be called once.
The RXControl and GetXXX Functions need to be called every loop because the code needs to check for new data coming in from the sensors and OI.
Everytime it’s checked it updates the motors or variables.
While your example was not correct for the PresureSwitch, your concept was correct and it would have worked it just would have been turning on the function again and again.
Ah… OK. I get it. It’s like a Ronco product. Set it and forget it
OK… Leaving my lack of sleep behind, I had another question for the easyC guy. Are there any NEW functions in easyC PRO? (I probably deserve a RTFM for this one, but hey… I don’t have ALL the time in the world…) That was a function I didn’t know existed in the first place, just wondering if there were new ones (I don’t really use easyC, but it would be nice to know for helping people with problems.)
Kinda makes me wonder why we still use MPLab… :yikes:
I might write a parallel program in easyC, just to see how much less time it takes. It’s too bad you can’t just go right in and start typing code without clicking and dragging in code blocks. (At least that’s the way I understand it… I could be wrong; again, I don’t use easyC all too much.