Go to Post When it all comes down to it, it's not gonna be the medal around your neck that makes the difference, but the memories that you think about when you look back on how you got there that makes the difference. - Beth Sweet [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-11-2011, 10:02
ssirovica's Avatar
ssirovica ssirovica is offline
Programming Captain
AKA: Sasha Sirovica
FRC #1458 (Red Ties)
Team Role: Programmer
 
Join Date: Sep 2011
Rookie Year: 2010
Location: Alamo
Posts: 26
ssirovica is an unknown quantity at this point
Sample Code

Hi everyone,

I just recently became the head programmer on my team , but would like some more example code, other than what can be found on the tutorials.

Any useful links or Google code pages?

Thanks,
Sasha Sirovica
__________________
Computers run on smoke. When you let the smoke out the computer stops working.
  #2   Spotlight this post!  
Unread 08-11-2011, 10:50
austin1743 austin1743 is offline
Head Programmer - Java
FRC #1743
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2009
Location: Pennsylvania
Posts: 56
austin1743 is an unknown quantity at this point
Re: Sample Code

Welcome to Programming, i am in the same position that you are,

I have been learning java programming for sometime (self-teaching). I wrote some java code that i pasted in this message bellow. Your welcome to check it out: If you got any questions on it let me know. I program commenting everything so that if someone else looks at it they can see what was done and a short explanation on most things.

The code is for a robot that uses mecanum (sorry about spelling on this one) drive. It is a little complicated to understand but working through that part still.

From what i understand i wrote the following code:

// things below this need to be imported first
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Dashboard;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import com.sun.squawk.util.MathUtils;


public class RobotTemplate extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
RobotDrive m_robotDrive;// robot will use PWM 1-4 for drive motors

//declears speed controllers
Victor leftFrontspeed = new Victor(4, 1);
Victor rightFrontspeed = new Victor(4, 2);
Victor leftBackspeed = new Victor(4,3);
Victor rightBackspeed = new Victor(4,4);
DriverStation driverStation; // driver station object
Dashboard dashboard;

// Declare variables for the two joysticks being used
Joystick js1; // joystick 1 (arcade stick or right tank stick)
Joystick js2; // joystick 2 (tank left stick)

public void robotInit() {
}

/**
* This function is called periodically during autonomous
*/
//public void autonomousPeriodic() {
// }

/**This function is called periodically during operator control
*/
public void teleopPeriodic() {
//leftspeed.set(js1.getY());
//rightspeed.set(js1.getY());

//is called when teloporated mode is enabled
double lf; //is what will be set to the left wheel speed
double rf; //is what will be set to the right wheel speed
double lb; // is what will be set to the left back wheel speed
double rb; // is what will be set to the left back wheel speed
double y = js1.getY(); //gets the value of the 1'st joystick's y axis
double x = js1.getX(); //gets the value of the 1'st joystick's x axis
y = y * Math.abs(y);//makes the y value quadratic
x = x * Math.abs(x);//makes the x value quadratic
x=-x;

//begins meckanum code which I do not understand but it works from what i understand
double magnitude =Math.sqrt(js1.getY()*js1.getY()+js1.getX()*js1.ge tX());
magnitude = magnitude*Math.sqrt(2);
double rotation = js1.getTwist();
double direction=MathUtils.atan2(x, y);
double dirInRad = (direction+45);
double sinD=Math.sin(dirInRad);
double cosD=Math.cos(dirInRad)*Math.sqrt(2);
lf=-sinD*magnitude+rotation;
rf=-cosD*magnitude-rotation;
lb=-cosD*magnitude+rotation;
rb=-sinD*magnitude-rotation;
//ends mecanum code

lf=y;
lb=y;
rb=y;
rf=y;

//runs function limit to ensure the speed of the motors is in exceptable range
//lf =limit(lf,1,-1);
//lb =limit(lb,1,-1);
// rf =limit(rf,1,-1);
// rb =limit(rb,1,-1);



/*magnitude = js1.getMagnitude();
direction = js1.getDirectionDegrees();
rotation = js1.getX();
driveRobot.mecanumDrive_Polar(magnitude, direction, rotation);
*/
//sets the motors speed
leftFrontspeed.set(lf);
leftBackspeed.set(lb);
rightFrontspeed.set(-rf);
rightBackspeed.set(-rb);

System.out.println("js1.y:"+js1.getY()+"\t js1.x:"+js1.getX()+"\t lf:"+lf+"\t rf:"+rf+"\t lb:"+lb+"\t rb:"+rb);

}
}
  #3   Spotlight this post!  
Unread 08-11-2011, 10:52
EricH's Avatar
EricH EricH is offline
New year, new team
FRC #1197 (Torbots)
Team Role: Engineer
 
Join Date: Jan 2005
Rookie Year: 2003
Location: SoCal
Posts: 19,814
EricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond reputeEricH has a reputation beyond repute
Re: Sample Code

You might want to specify a language for the sample code to be in. If you're programming in C++ and the sample is in Labview, you won't be able to make head or tail of it.
__________________
Past teams:
2003-2007: FRC0330 BeachBots
2008: FRC1135 Shmoebotics
2012: FRC4046 Schroedinger's Dragons

"Rockets are tricky..."--Elon Musk

  #4   Spotlight this post!  
Unread 08-11-2011, 11:00
ebarker's Avatar
ebarker ebarker is offline
Registered User
AKA: Ed Barker
FRC #1311 (Kell Robotics)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Kennesaw GA
Posts: 1,437
ebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond reputeebarker has a reputation beyond repute
Re: Sample Code

Here are code samples that do a lot of random stuff in C++ and Java.

We use these files for training.

http://www.kellrobotics.org/files/so...MyProject.java

http://www.kellrobotics.org/files/software/MyRobot.cpp
__________________
Ed Barker
  #5   Spotlight this post!  
Unread 08-11-2011, 11:18
ssirovica's Avatar
ssirovica ssirovica is offline
Programming Captain
AKA: Sasha Sirovica
FRC #1458 (Red Ties)
Team Role: Programmer
 
Join Date: Sep 2011
Rookie Year: 2010
Location: Alamo
Posts: 26
ssirovica is an unknown quantity at this point
Re: Sample Code

Sorry, C++ would be great.
__________________
Computers run on smoke. When you let the smoke out the computer stops working.
  #6   Spotlight this post!  
Unread 08-11-2011, 12:07
Roger Roger is offline
Registered User
FRC #1153
 
Join Date: Jan 2006
Rookie Year: 1900
Location: Walpole MA
Posts: 688
Roger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond reputeRoger has a reputation beyond repute
Re: Sample Code

And to be complete, though not what was (finally) asked for, LabVIEW has many robot and non-robot examples available within the provided LabVIEW program. They show small bits of complete code for various parts of the robot that you can run on your robot (after changing to your address). I would assume the C++ and Java have similar.
Quote:
If you're programming in C++ and the sample is in Labview, you won't be able to make head or tail of it.
Should be "some people may not" (my highlighted words).
  #7   Spotlight this post!  
Unread 08-11-2011, 13:57
~Cory~'s Avatar
~Cory~ ~Cory~ is offline
Student
AKA: Cory Rypkema
FRC #0706
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Worcester MA
Posts: 216
~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold~Cory~ is a splendid one to behold
Re: Sample Code

I know I sound like a broken record but the main tools you will be using are ctrl-c ctrl-v Dont worry about learning programming. worry about learning solving the problem (i.e. make a usable robot). Many teams have posted their code from previous years, and you can copy and paste to get the problem done. Overtime, you will learn to solve problems on your own.

I can help you find some stuff, but you have to define the problem first. What are you most likely to be programming? A tank drive? holomonic? or do you want to focus on manipulators? or do you want to dive into Autonomous?
__________________
corin.rypkema.org
WPI Class of '17
'12 Dean's List Finalist, Mentor of 706 - Cyberhawks
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 18:52.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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