Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   A New Programmer (http://www.chiefdelphi.com/forums/showthread.php?t=62010)

Spartan151 18-01-2008 22:13

A New Programmer
 
1 Attachment(s)
Hi. I'm Sean, current leader of team 2065. We have no real programming abilities as of yet. However, after printing off a guide I found here, I have a somewhat decent understanding of how to write it....I think.
I wrote a test code based off of what was on the 12-page manual, and I would like someone who has some programming experience to take a look at it and comment on it. I need to know what I'm doing right and wrong.
The program I have written is a code for autonomous mode. The actions encompass the following:

drive forward for 3 seconds
turn left for half a second
drive foward for one and a half seconds
turn left again for half a second
drive forward for three seconds
turn left for half a second
drive forward for one second
stop until the remaining time is up.

Please, comments are greatly appreciated.

Note: I deliberately left it as a .txt file for easy access.

Laaba 80 18-01-2008 22:17

Re: A New Programmer
 
Looks pretty good for the first time. One thing though, once you find out it works, you will want to make it go faster, because right now it is going a little under half speed, and I'm assuming this is code to race around the track, so you will want to go fast. Nice job, if you have other questions, let me know.
Joey

Spartan151 18-01-2008 22:31

Re: A New Programmer
 
Thank you. I chose small numbers because I just wanted to do a test, and I do intend to increase those numbers once I'm sure that I did it right. I know I'll have to do some checking on the right motor, because for some reason it seems a little laggier than the left motor on our robot.
There'll be a bunch of fine tuning involved, but from your standpoint, what would be a good number for some good speeds? We'll be going for every possible option that we can.
There'll be a lot of testing come Tuesday (That's when our materials for the tower and arm come in) to see whether or not it works.

Okay. Here's a question. Our team's computer both has EasyCPro and the Compiler, but how exactly do I go extracting the default, editing the code, and putting it back in the RC?

Laaba 80 18-01-2008 22:40

Re: A New Programmer
 
Im not sure with Easy C, I use MP Lab. I'll tell you how its done in MP Lab, and hopefully you can figure Easy C out. In the Kit, you got some serial cables. plug the red cable into the robot controller and the operator interface with the joysticks. It says TEATHER where you put that in. Take the black cable and plug into the robot controller. I cant remember what the port says, but I'm guessing it says something like PROGRAM. If you are using a newer laptop you may run into some problems connecting to the computer because they dont have serial ports any more, let me know if that is your case. When everything is turned on press and hold the PROG button on the robot controller until some lights turn yellow. Open up the compiler, open up the hex file that you just built and download into the robot. Hopefully that helped. If there is any thing else let me know and I'll do my best to help.
Joey

Spartan151 18-01-2008 22:45

Re: A New Programmer
 
Thanks very much. I'll keep you updated as to how it progresses.

So, I can use MPLab to extract the default code and edit it, correct?

Laaba 80 18-01-2008 22:46

Re: A New Programmer
 
Ok, Good Luck
Joey

RyanCahoon 20-01-2008 05:56

Re: A New Programmer
 
Quote:

Originally Posted by Spartan151 (Post 681199)
So, I can use MPLab to extract the default code and edit it, correct?

You'll need to get the default code from the IFI website here.

- Once you've extracted all the files, open the FrcCode.mcw file. It should load MPLAB.
- You should see two windows, the Project Browser and the Output window. In the Project Browser, double click on user_routines_fast.c
- Scroll down to the User_Autonomous_Code function. Insert the autonomous code you written after the line that reads
Code:

/* Add your own autonomous code here. */
- Follow the directions here on how to download your code to your robot.

Good luck
--Ryan

P.S.: Remember to check your semicolons!

paulcd2000 20-01-2008 11:26

Re: A New Programmer
 
Quote:

Originally Posted by Spartan151 (Post 681182)
I know I'll have to do some checking on the right motor, because for some reason it seems a little laggier than the left motor on our robot.

THat's usually the case. It happens (to us anyway) because the motor on the right wheel is turned around. The motors don't run the same speeds forwards an backwards, so when the left is running full fwd and the right full bwd, they're in the same direction, but the speeds are off slightly. It doesn't change a lot if ur moving slowly, since the system has a lot of friction, but when you gear up the speeds, the robot doesn't go anywhere near straight (speaking from personal experience in a narrow hallway)

Alan Anderson 20-01-2008 16:58

Re: A New Programmer
 
Quote:

Originally Posted by paulcd2000 (Post 682067)
It happens (to us anyway) because the motor on the right wheel is turned around. The motors don't run the same speeds forwards an backwards, so when the left is running full fwd and the right full bwd, they're in the same direction, but the speeds are off slightly.

The CIM motors don't have significant bias. They'll run the same speed in both directions. If you're reversing the motor direction for the other side of the robot by swapping the wires, the speeds should match well.

However, the Victor speed controllers do appear to have an asymmetric response around the defined neutral value of 127. If you're accounting for the need to reverse the motor direction in code, you'll probably notice this. When we tested things last year, true neutral seemed to be closer to 132.

marccenter 20-01-2008 20:10

Re: A New Programmer
 
Looking at your code, I would recommend that you replace some of your absolute numbers with Calibration
values for future ease of Use. That way,you can change one Calibration value at the top of your program and it
changes all the values in your program saving you valuable editing time and the possibility of an editing bo-bo. For Example, if Fwd is > 127 for pwm outputs, try something Like Fwd_Low = 150 ; Fwd_Med = 170 ;Fwd_High = 190 , Similiarly, if
Rwd is < 127 how about Rev_Low = 104, Rev_Med = 84, and Rev_High = 64.

Spartan151 20-01-2008 22:03

Re: A New Programmer
 
Thanks for all the help guys. You've all been great. I'll be testing those things ASAP. Now, there are some other things I need help with, also. Our robot's claw is run by pneumatics. On our arm control, I need to program two buttons on the joystick (Or one to do both functions) to open and close the claw. How would I go about porgramming the buttons?

Spartan151 20-01-2008 22:08

Re: A New Programmer
 
Quote:

Originally Posted by marccenter (Post 682408)
Looking at your code, I would recommend that you replace some of your absolute numbers with Calibration
values for future ease of Use. That way,you can change one Calibration value at the top of your program and it
changes all the values in your program saving you valuable editing time and the possibility of an editing bo-bo. For Example, if Fwd is > 127 for pwm outputs, try something Like Fwd_Low = 150 ; Fwd_Med = 170 ;Fwd_High = 190 , Similiarly, if
Rwd is < 127 how about Rev_Low = 104, Rev_Med = 84, and Rev_High = 64.

Could you explain exactly what you mean? I'm having difficulty understanding, partly because the computer I'm using now doesn't have MPLAB and partly because I only understand autonomous programming to a degree.

blaxbb 20-01-2008 22:35

Re: A New Programmer
 
under ///*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/ or at the top of any .c file

to make it easier you should define your speeds so that you can update all of your speed values without changing every single one.

you can define your speeds once and call them multiple times
Code:

#define stop 127
#define forward 200
#define reverse 50

then instead of saying
Code:

pwm01 = 200;
pwm02 = 50;

you can say
Code:

pwm01 = forward;
pwm02 = reverse;

this makes it so much easier if you need to change a value quickly (at a competition)

Spartan151 21-01-2008 10:06

Re: A New Programmer
 
Okay. It's beginning to make sense now. I'll give it a shot.

Spartan151 21-01-2008 22:15

Re: A New Programmer
 
Okay. Once I get the basics done, I will need help programming the IR board functions, and programming the pneumatics for our claw to the arm joystick. I'll let you know when we get to that stage, but please, feel free to explain ahead of time. It'll help our team get a better understanding so there's no head-scratching later.

blaxbb 21-01-2008 23:09

Relays and IR Board
 
Quote:

Originally Posted by Spartan151 (Post 683237)
Okay. Once I get the basics done, I will need help programming the IR board functions, and programming the pneumatics for our claw to the arm joystick. I'll let you know when we get to that stage, but please, feel free to explain ahead of time. It'll help our team get a better understanding so there's no head-scratching later.

This is where the electronics and programming team/person has to work together.

The pneumatic cylinders are piped by solenoids (electronic valves,) which are controlled by a spike (relay.)

Relays don't use the analog 0-254 scale. They are essentially digital outputs that can be either forward, off, or reverse.

You map the relays the same way that you map speed controllers.

Code:

relay1_fwd = p1_sw_trig;
That would set relay1 to be forward every time your joystick 1 trigger is held.

IFI has a list of the joystick inputs here. pdf warning



As far as the IR, you need to read the digital input (1 or 0) and pass it through a conditional (if, else, switch) to execute a command.

Code:

if (rc_dig_in01 == 1) {
    pwm01 = pwm02 = 200;
    }
else {
    pwm01 = pwm02 = 127;
}

change rc_dig_in01 to match up with the digital input that was wired to your bot

the reference docs to wire and train the IR board are here. pdf warning

Spartan151 22-01-2008 19:30

Re: A New Programmer
 
Okay. Next question: Is it possible to program the joystick trigger to, when squeezed the first time, open the claw, and when pressed a second time, closes the claw?

Also, where do these code lines fit in at?

blaxbb 22-01-2008 23:21

Re: A New Programmer
 
Quote:

Originally Posted by Spartan151 (Post 683846)
Okay. Next question: Is it possible to program the joystick trigger to, when squeezed the first time, open the claw, and when pressed a second time, closes the claw?

Also, where do these code lines fit in at?

I've been trying to figure that out too, can anyone else fill in.

I'm pretty sure you would have to write a toggle function, but I'm not exactly sure how it should work.

Alan Anderson 22-01-2008 23:41

Re: A New Programmer
 
Examples of toggle functions are common on the Chief Delphi forums. Here's another:
Code:

  :
  :
  static char prev_trig = 0;
  static char toggle = 0;
  :
  if (p1_trig && !prev_trig)
  {
    toggle = !toggle;
  }
  prev_trig = p1_trig;
  :

This will switch toggle from 0 to 1, or vice versa, each time the port 1 joystick trigger is depressed. You can test its value to decide what to do next.

Jim E 23-01-2008 00:06

Re: A New Programmer
 
Hi,

You can try this, but I don't make any guarantee.

Toggle_gripper(current state)
{
int temp_state;
If ((p3_sw_trig==TRUE)&&( current _state== CLOSED)
temp_state=current_state;

else if (p3_sw_trig==TRUE)
temp_state=OPEN;

else if ((p3_sw_trig==FALSE)&&(current_state==OPEN))
temp_state=current_state;

else if ((p3_sw_trig==FALSE)
temp_state=CLOSED;

} return (temp_state);

In you Default _Routine, simply call the function:


pwm_state=Toggle_Gripper(current_pwm);
if (current_pwm<>pwm_state)
pwm=pwm_state;

I'm writing this off the cuff, you will need to correct the syntax and apply your own values for the pwm assignments, but it looks plausable. Good luck.

Spartan151 23-01-2008 09:12

Re: A New Programmer
 
Quote:

Originally Posted by Alan Anderson (Post 684061)
Examples of toggle functions are common on the Chief Delphi forums. Here's another:
Code:

  :
  :
  static char prev_trig = 0;
  static char toggle = 0;
  :
  if (p1_trig && !prev_trig)
  {
    toggle = !toggle;
  }
  prev_trig = p1_trig;
  :

This will switch toggle from 0 to 1, or vice versa, each time the port 1 joystick trigger is depressed. You can test its value to decide what to do next.

Okay. Taking this code, where do I write in the relay values, if they need to be written in? Or is that done with the previous code for the relay values?

Spartan151 23-01-2008 17:50

Re: A New Programmer
 
Okay. Here's another problem. I have the code written, but I keep getting a syntax error every time I try to build. How exactly do I run MPLAB? Also, where do those codes involving the toggling and pneumatics fit in?

blaxbb 23-01-2008 18:34

Re: A New Programmer
 
A syntax error means that typed something in your code wrong, forgot a semicolon, mistyped a variable, etc.

in MPLAB where it says syntax error
Code:

user_routines_fast.c:27:Error: syntax error
The number 27 after the file matches the line that the error is on.

Can you compile the default code?

brittanys 23-01-2008 19:00

Re: A New Programmer
 
Another general comment on your original bit of code...besides defining variables to use in place of direct values. You will want to include some sort of "deadband" into almost all of your drive code to account for the dynamic trim of the joysticks, prevent twitching/jerking, et cetera.

As somebody posted previously (sorry, I don't remember the name!), true neutral usually ends up at a value higher or lower than 127 (132 is quite common). To compensate for this fluctuation, we include a deadband of 6 in either direction, so "neutral" is really a range around 127.

Good luck! :]

Spartan151 23-01-2008 19:47

Re: A New Programmer
 
Haven't ied compliling the default code yet. I'll give it a shot. But as to the toggling.....I'm stumped as everyone on the team is. Yeah...we're gonna need a lot of help.

Spartan151 23-01-2008 22:25

Re: A New Programmer
 
This programming issue is putting us behind schedule, sadly. I just can't figure out where certain lines go. However, there may be a solution to it tomorrow, if we can get hold of Team 462. Got a lot more work to do. I'll be getting about 3 hours of sleep tonight, but our team doesn't back down from a challenge.

Laaba 80 23-01-2008 22:35

Re: A New Programmer
 
Quote:

Originally Posted by brittanys (Post 684563)
Another general comment on your original bit of code...besides defining variables to use in place of direct values. You will want to include some sort of "deadband" into almost all of your drive code to account for the dynamic trim of the joysticks, prevent twitching/jerking, et cetera.

As somebody posted previously (sorry, I don't remember the name!), true neutral usually ends up at a value higher or lower than 127 (132 is quite common). To compensate for this fluctuation, we include a deadband of 6 in either direction, so "neutral" is really a range around 127.

Good luck! :]

Make sure you do this! We just got our motors moving today and I didnt make the buffer zone yet so the motors were real jerky.
Joey

Spartan151 25-01-2008 12:05

Re: A New Programmer
 
Okay. I had someone walk me through the autonomous programming, and now I need to know how to put the OI in disabled mode so I can test the autonomous code WITHOUT SHUTTING DOWN THE PWM OUTPUTS. How would I go about doing that?

Alan Anderson 25-01-2008 13:08

Re: A New Programmer
 
Quote:

Originally Posted by Spartan151 (Post 685614)
Okay. I had someone walk me through the autonomous programming, and now I need to know how to put the OI in disabled mode so I can test the autonomous code WITHOUT SHUTTING DOWN THE PWM OUTPUTS. How would I go about doing that?

What you're asking for is probably not what you want. Putting the system in disabled mode will certainly shut down the PWMs, along with the relay outputs. That's the whole purpose of disabled mode.

I think what you want to know is how to put it in autonomous mode and have it actually provide outputs. For that, you need to connect to the competition port and close a switch between the proper pins. See the Competition Port Pinout Guide (it's on the OI section of the IFI Robotics web site).

Spartan151 25-01-2008 14:52

Re: A New Programmer
 
Quote:

Originally Posted by Alan Anderson (Post 685660)
What you're asking for is probably not what you want. Putting the system in disabled mode will certainly shut down the PWMs, along with the relay outputs. That's the whole purpose of disabled mode.

I think what you want to know is how to put it in autonomous mode and have it actually provide outputs. For that, you need to connect to the competition port and close a switch between the proper pins. See the Competition Port Pinout Guide (it's on the OI section of the IFI Robotics web site).

Okay. How would I go about closing the switch? What do I need?

Spartan151 28-01-2008 09:22

Re: A New Programmer
 
Quote:

Originally Posted by Spartan151 (Post 685750)
Okay. How would I go about closing the switch? What do I need?

Success! We figured it out! Now all I have to do is get the speeds adjusted.

paulcd2000 03-02-2008 15:24

Re: A New Programmer
 
one thing i find helpful when testing autonomous code is to put the robot up on blocks so you can run everything in ur lab while reading printfs


All times are GMT -5. The time now is 20:27.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi