Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Porting Talon SRX (http://www.chiefdelphi.com/forums/showthread.php?t=141635)

VaneRaklan 13-01-2016 14:12

Porting Talon SRX
 
So we are trying to program using CAN but for some reason everything that I try says that the CAN Talon is a null pointer. Is there a specific way of writing the ports for the CAN Talons?
(I would add my code to this post, but I forgot how to do that)

ozrien 13-01-2016 14:51

Re: Porting Talon SRX
 
It sounds like your creating the CANTalon variable, but not calling the new operator.

Take a look at section 3.2.3 in the Talon SRX Software Reference Manual. See the line that reads...
Code:

CANTalon customMotorDescript = new CANTalon(0);
It sounds like you are just doing
Code:

CANTalon customMotorDescript;
The number you pass into new CANTalon(x), is the device ID of the Talon. Use the web-based config to set the IDs of the Talons so that each one is unique (See section 2 in the Talon software reference manual).

ozrien 13-01-2016 15:02

Re: Porting Talon SRX
 
Link to get the Talon SRX Software reference manual...
http://www.ctr-electronics.com/contr...ical_resources

VaneRaklan 13-01-2016 15:35

Re: Porting Talon SRX
 
Like I said, If I knew how to add my code to a reply you could see what I am doing. I did, in fact, write it just like that. (CANTalon motorDescirption = new CANTalon(x)

Ether 13-01-2016 15:52

Re: Porting Talon SRX
 
Quote:

Originally Posted by VaneRaklan (Post 1522925)
Like I said, If I knew how to add my code to a reply you could see what I am doing.

Is there some reason why you can't just cut and paste the relevant portion(s)?



ozrien 13-01-2016 16:09

Re: Porting Talon SRX
 
Quote:

Originally Posted by VaneRaklan (Post 1522925)
Like I said, If I knew how to add my code to a reply you could see what I am doing. I did, in fact, write it just like that. (CANTalon motorDescirption = new CANTalon(x)

Well ok....but I have no way of knowing how you wrote it...

Ether is right, just copy/paste the important part. Or zip it up and email to support@crosstheroadelectronics.com, and I'll bounce it back to this thread.

VaneRaklan 13-01-2016 16:33

Re: Porting Talon SRX
 
public class RobotMap {

public static SpeedController frontLeft;
public static CANTalon frontRight;
public static CANTalon backLeft;
public static CANTalon backRight;
public static RobotDrive robotDrive;

public static void init(){
frontLeft = new CANTalon(3, 0);
// frontRight = new CANTalon(4);
// backLeft = new CANTalon(1);
// backRight = new CANTalon(0);

robotDrive = new RobotDrive(frontLeft, frontRight, backLeft, backRight);
robotDrive.setSafetyEnabled(false);


}
}

GeeTwo 13-01-2016 16:42

Re: Porting Talon SRX
 
Quote:

Originally Posted by VaneRaklan (Post 1522969)
Code:

public class RobotMap {

        public static SpeedController frontLeft;
        public static CANTalon frontRight;
        public static CANTalon backLeft;
        public static CANTalon backRight;
        public static RobotDrive robotDrive;
       
        public static void init(){
                frontLeft = new CANTalon(3, 0);
//                frontRight = new CANTalon(4);
//                backLeft = new CANTalon(1);
//                backRight = new CANTalon(0);
               
                robotDrive = new RobotDrive(frontLeft, frontRight, backLeft, backRight);
                robotDrive.setSafetyEnabled(false);
               
               
        }
}


The frontRight, backLeft, and backRight pointers are null because those constructor lines are commented out. This would likely cause a null pointer exception in the robotDrive constructor. Also, if you wrap your code in code tags (highlight the block and click the # symbol), it's easier to read.

VaneRaklan 13-01-2016 16:44

Re: Porting Talon SRX
 
I realize that they are commented out. Currently I am only calling on the single motor and it still says that it is a NullPointer

ozrien 13-01-2016 16:46

Re: Porting Talon SRX
 
Yep GeeTwo is right. frontRight is being created but you are not assigning it to a new'd object instance, so it stays null.

Remember frontRight is just a reference. In java you must assign to the return of a new operator to actually create the relevent object. If you put a breakpoint just before the NullException occurs and add frontRight to your watch list, you'll see it's null.

ozrien 13-01-2016 16:47

Re: Porting Talon SRX
 
Quote:

Originally Posted by VaneRaklan (Post 1522973)
I realize that they are commented out. Currently I am only calling on the single motor and it still says that it is a NullPointer

Yeah but robotDrive is still created and used, which uses all four underneath.

GeeTwo 13-01-2016 16:49

Re: Porting Talon SRX
 
Quote:

Originally Posted by VaneRaklan (Post 1522973)
I realize that they are commented out. Currently I am only calling on the single motor and it still says that it is a NullPointer

The null pointer exception is probably being thrown by the new RobotDrive() constructor, which has three null pointers. If you just want to test one motor, use a manipulator sample code rather than drive code.


All times are GMT -5. The time now is 09:17.

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