PDA

View Full Version : HELP!


Asheron
01-31-2007, 08:25 AM
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.

Thank you.!

whytheheckme
01-31-2007, 08:52 AM
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....

Kingofl337
01-31-2007, 09:01 AM
Also, open the help file and start at "Getting Started" there are a bunch of tutorials that show you how to write code for your robot and examples.

You may want to check out the online window as well it will show you how things move.

whytheheckme
01-31-2007, 09:21 AM
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.

Jacob

Asheron
01-31-2007, 09:35 AM
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.

whytheheckme
01-31-2007, 09:46 AM
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:

http://www2.usfirst.org/2007comp_1735_temp/Drawings/2007_FRC_ROBOT_POWER_DISTRIBUTION_DIAGRAM.pdf

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.)





Theres a problem, so far it looks to me like the team hasn't assembled a robot or a board. I do know what the parts are and have seen both the on-bot control board and the joystick control board (for lack of better terminology).

Is there some program or emulator I can send the code to that acts and gives feedback like the robot to check it until the robot is done?

I saw the serial ports ( I work 9 hours a day and will be getting about 3 hours a day with the team) and I'm assuming these are the ports I should know to recieve from and output to based on whats connected to them.

I know our drivetrain is going to be two wheel drive in the back with cart wheels (no motors attached just 360 degree rotating wheels like a grocery cart) on the front. I noticed like 4 or 5 modes in Easy C, which one would work with a two wheel drive? Just the regular 2 WD arcade? or the 2 WD tank mode?

I'm not looking at the code right now, but from what you mentioned and what I saw in the program, psuedocode would look like:

char joystick_x_axis = joystick_x_input
char joystick_y_axis = joystick_y_input

while (1) // endless loop to check for conditions
{
check for joystick position

control motion.

set pmw1 =

}

To control motion, I guess I'd have to set the motor speeds based on joystick position, so if the joystick is leaning right (signaling a right turn), I should slow down the right wheel so the left wheel would take over?

Could you provide me an example of how to control motor speeds based on joystick input?

I'm thinking, I should set the wheel for a specific motor based on subtracting the joystick x position from the joystick y position, so that the motor on the outside of the turn would be spinning faster based on the joystick position, example of what I'm thinking:

Joystick position = 45 degrees northeast (signalling right turn)
and Max motor speed and joystick control both = 255 with the starting position or no motor speed = 127

So, I'd have the left wheel moving at 200 maybe and I'd take and subtract the x -axis value of, lets say, 180, so I'd do a calculation:

set pmw1 = joystick_y_axis // 200 which is y-axis, N/S, value

set pmw2 = joystick_y_axis - (joystick x-axis - 127) // subtract from the y axis the x axis minus the 0 point).



Let me know if that logic makes sense, if not, how should it go? I'm not in front of easyC right now, I can't install it on my work computer neither can I get in to remote control the PC its on.

--
Remember, if this post was helpful, good Rep is always good....

Asheron
01-31-2007, 10:28 AM
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.

whytheheckme
01-31-2007, 10:29 AM
No problem. I'd be happy to explain anything that needs explaining... I'm a 14 year old college student with a lot of time on his hands....


My next class isn't until 4:30 tonight.

Jacob

Kingofl337
01-31-2007, 01:49 PM
14 !? They just keep making them younger and younger!

Asheron
01-31-2007, 01:54 PM
Nickname Genius, child prodigy. I hope you don't hit the parties and go out drinking! It would stunt your growth!

whytheheckme
02-01-2007, 08:21 AM
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...


Ok,
It looks like both I and my student programmer understand how to make the robot move (although we didn't get it wired last night - a team should be taking care of that today). We also went through the tutorials and I explained what the code easyC was putting together does.

My next question: I believe we are going to be using the air compressor and pnuematics system to telescope our arm up and down. Does easyC have a control system already programmed to handle that, or should I be looking up how to do that on my own?

Kingofl337
02-01-2007, 08:32 AM
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.

whytheheckme
02-01-2007, 09:28 AM
OK.

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:

http://www2.usfirst.org/2007comp/other/2007%20FRC%20Pneumatics%20Manual.pdf

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.

Kingofl337
02-01-2007, 10:30 AM
This is not correct but close. The presure switch only needs to be called once. Good work though. :D

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
}
}

This is correct.

void Initialize ( void )
{
InitPressureSwitch ( 7 , 1 ) ; (Input Port,Relay Port)
}

void OperatorControl ( void )
{
while ( 1 )
{
Arcade2 ( 1 , 1 , 1 , 2 , 1 , 2 , 0 , 1 ) ; // A nice little drive block
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
}
}

whytheheckme
02-01-2007, 12:50 PM
Ah, OK.

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?

Thanks,
Jacob

Kingofl337
02-01-2007, 06:37 PM
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.

whytheheckme
02-01-2007, 07:34 PM
Ah.... OK. I get it. It's like a Ronco product. Set it and forget it :p

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.)

Napping in class,
Jacob

Kingofl337
02-01-2007, 08:51 PM
Here is a start :)

http://www.chiefdelphi.com/forums/showthread.php?t=51451

whytheheckme
02-02-2007, 11:29 AM
Wow this stuff is sweet...

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.

Thank you,
Jacob

Kingofl337
02-02-2007, 11:35 AM
You can start right off writing code and you can drag the blocks into the code and it will type the functions for you.

almsfan21
02-06-2007, 10:54 PM
This thread is awesome! It's going to be a lifesaver..our programmer quit on us, today..with no code written. I've never written code before...so I guess I better learn quick. I'm sure I will have many questions come tommorow as well...thanks a lot guys!

Kingofl337
02-07-2007, 12:52 AM
Thats why we are here :) and what FIRST is about.

Asheron
02-07-2007, 08:07 AM
I appreciate you all very much. I'll have some more questions over the next few days as we really get down to business, get our arm built and I'll start having some questions. Please check back here once a day or so. I'll PM both of you a link to a diagram of what our arm will look like and could use some ideas on programming for it. I have a great start from what you've given me so far. Thanks again you two are both much appreciated and I'll be all the more prepared to mentor a team next year because of you.

almsfan21
02-07-2007, 12:30 PM
Ok, being in the same boat as Asheron, I need some help. I believe I have programmed the motors correctly. We also have a pneumatic system with a double solenoid, and that's all. I need to program the RC to work, (just to drive the bot for now)...how do I go about that? I also noticed today that our electrical guy put the PWMs for the motors on 2 and 4..will the code mentioned earlier in the thread still work? Thanks for all the help!

Asheron
02-07-2007, 07:39 PM
Where can I find the robot controller configuration sheets that tells me what the addresses of each of the potential inputs would be.

Kingofl337
02-07-2007, 10:16 PM
almsfan21: your best bet is to fire off the online window and then you can play with your motors and spikes without even writing any code. Then you can use the "RC Control" blocks to get things moving.

Asheron: Hit F5 or Click on the picture of the Hammer.

Asheron
02-13-2007, 12:49 PM
I have both robots moving on both teams; now working on hitting the spikes. I want to use a button on the controller for each spike first click to send positive out second click to send the ground out. We actually have 6 spikes and 3 victors. I also need to know how to program the window motor; I just want the Y axis active on it. How do i accomplish that. Its position is pwm3 on the controller board. I just want Y axis forward and reverse since its just a window motor.

I have a second joystick on port 2 to control that motor I'm starting to understand seriously whats going on now that I have some things plugged in; but... do I have to have all the controls in the user controller section? Or can I create different functions named different things outside of the main and have to call them? I'm lost with that. Should all code be inside that one while(1) loop?

sonicx059
02-13-2007, 08:27 PM
Also, open the help file and start at "Getting Started" there are a bunch of tutorials that show you how to write code for your robot and examples.

You may want to check out the online window as well it will show you how things move.
sorry but open this up from where?

BradAMiller
02-13-2007, 11:12 PM
sorry but open this up from where?

If you meant the online window, then hit "Build and download", then "Online window".

If you were asking about the examples and tutorials, then they are here:

C:\Program Files\Intelitek\easyC Pro\FRC\Projects