Thread: CANJaguar
View Single Post
  #20   Spotlight this post!  
Unread 23-01-2012, 01:19
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 431
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: CANJaguar

Quote:
Originally Posted by kingkurry View Post
I just tried instantiating the jaguars without a slot number. This didn't work either. This is the code I have been trying. I have also tried all the code that I commented out, still without results

Code:
package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Jaguar;

public class RobotTemplate extends IterativeRobot {
    RobotDrive robot;
    Joystick left;
    Joystick right; 
    Jaguar leftFront;
    Jaguar leftRear;
    Jaguar rightFront;
    Jaguar rightRear;
    
    public void robotInit() {
        Jaguar leftFront = new Jaguar(1);
        Jaguar leftRear= new Jaguar(2);
        Jaguar rightFront= new Jaguar(3);
        Jaguar rightRear= new Jaguar(4);
        
        robot = new RobotDrive(leftFront,leftRear,rightFront,rightRear);
  
        //robot = new RobotDrive(1,2,3,4);
        left = new Joystick(1);
        right = new Joystick(2);
        System.out.println("RobotInit() completed.\n");
    }
I believe you have a scope problem.
You instantiate your jaguars as class variables (green lines), then create four new jaguar variables within the robotInit() method (red lines). You're not initializing the class variables as you may think. Basically you're telling the program that within the robotInit() class it should use the local copies of those Jag variables (red), instead of the ones the rest of the program knows about (green). Any reference to the Jag variables outside of the robotInit() method will refer to the ones that aren't initialized (green), and since they aren't initialized they won't be sending commands to any motor controllers.

Remove the "Jaguar" text thats highlighted red and that should fix your problem.

Read up on scope: http://sip.clarku.edu/tutorials/java/java.html#scope
__________________
http://team2168.org
Reply With Quote