Programming

@MeteorD

this goes in the code

import edu.wpi.first.wpilibj.WPI_TalonSRX motor = new WPI_TalonSRX(port#)

but what if using VictorSPX?

WPI also has Victor SPX check here
http://www.ctr-electronics.com/downloads/api/java/html/classcom_1_1ctre_1_1phoenix_1_1motorcontrol_1_1can_1_1_w_p_i___victor_s_p_x.html

Aaron, I think the bigger issue is you are not following our recommended process.
Since you reported you are using a VicSPX on CAN-bus, I strongly recommend you follow these procedures from top to bottom…
https://phoenix-documentation.readthedocs.io/en/latest/ch05a_CppJava.html

It’s not clear if you have confirmed

  • device shows up in Tuner
  • device has been updated with correct firmware
  • API has been installed correctly
  • API has been selected correctly in a new 2020 VS project.

Instead it seems like you jumped right to coding without performing the hardware bring-up steps.

If you can test drive the motor via Tuner first, then you are in good shape to create a VictorSPX object and drive it from code.
This example uses TalonSRX, so change it to VictorSPX (or WPI_VictorSPX if using WPI features).
https://phoenix-documentation.readthedocs.io/en/latest/ch13_MC.html#java-sample-driving-code

2 Likes

Anything in the 2 documents that mention about the TalonSRX can just be replaced with VictorSPX correct?

Yes or no? I dont have internet currently.

Assuming that you followed the instructions in the phoenix documentation that used the offline installation, then it doesn’t matter if you are online when you do this build.

Except for the attached encoder things which don’t apply to the Victor.

Phoenix Tuner. Do i need the robot for this task?

Device?

Added to the Github after doing the recommended process of install offline libraries and got the Phoenix.json automatically.

What’s the difference between a regular VictorSPX and WPI_VictorSPX? Any pros of one over another?

We use victor on PWM and CAN, and there are differences when you are setting the parameters.

import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PWMVictorSPX;
Joystick stick;
PWMVictorSPX MI1;
VictorSPX Intake;
stick = new Joystick(0);
MI1 = new PWMVictorSPX(0);
Intake=new VictorSPX(6);
final double speed=stick.getY();
final double giro=stick.getX();
final double pza=stick.getRawAxis(4);
MI1.setSpeed( -speed + giro);
Intake.set(ControlMode.PercentOutput, pza);

looking back on the product manual (page 9-11), when should i have done the brake/coast with them?

Yes, you need to be connected to the robot to see devices in Phoenix Tuner

Device in this context refers to the VictorSPX. It’s worth noting that it will ONLY show up if it’s connected to your CAN network, NOT if it’s connected by PWM.

I’m not sure what you did, but your code doesn’t follow the wpilib template (or even the standard gradle java project layout). Please create a new project using vscode and the wpilib plugin (ctrl+shift+P -> “WPILib: Create New Project”), then copy your code into it replacing identically named files (so you know you’re in the correct directory). In short, all of your code (*.java files) will be under src/main/java

WPI_VictorSPX is the class you should use if you need to make use of WPILib-specific functionality (for example, this class implements Sendable, so that you can send the entire object to SmartDashboard/Shuffleboard and it will know how to display it without you doing anything else). If you don’t NEED that functionality, you’re free to use the VictorSPX class instead. I personally recommend just using the WPI_ prefixed one for simplicity.

Looking at your drivetrain code on github, if you want to use VictorSPXs over CAN then you need to

  • change everywhere that you use CAN and replace it with VictorSPX
  • change your import to import com.ctre.phoenix.motorcontrol.can.VictorSPX;
  • import com.ctre.phoenix.motorcontrol.ControlMode;
  • change your calls to setSpeed(output) to
leftBack.set(ControlMode.PercentOutput, someSpeed); // runs leftBack at `someSpeed` (-1 to 1)

and as ozrien said above, please verify the following

What i did was just make my own folders and files in a workspace… using last year’s code format as a ‘template’

Guess it’s back to square 1 for a while…

You’ll definitely want to make sure you’re following the correct project format (or know what exactly you’re doing with a custom format). Take a look at the example projects provided by WPILib.

Aaron,

I feel you need a little more hands on help than you are getting. Have your mentor find another team in your area to give you about three to four hours of hands on time with their programmers. You are very close to getting things working but some one on one time with a programming mentor from another team will help you out greatly.

-Jim

1 Like

I personally do not have that time as I normally do programming work either at home or during study hall. Through weekdays, I can only stay afterschool for about 1 hour and i’d have to leave. Saturdays are never a solid schedule. Sundays I’m free all day but meetings start late and end early.

I would love to be able to do some live hands-on with someone who has better experience than I do.

OK,

At the next meeting ask for complete control of the robot, it is yours for the hour. If you can move it to a room without any distractions that will be the best. You, and the robot alone so you can focus.

You need to have the Phoenix Tuner on your laptop. If you don’t, get it from:
http://www.ctr-electronics.com/hro.html#product_tabs_technical_resources

Connect your laptop up to the Roborio using the USB cable and run the Phoenix Tuner. From the first page hit ‘Run Temporary Diagnostic Server’. Then wait a bit until the bottom status message says it’s finished, click on the CAN devices tab.

Take a snapshot of that tab and show it to this thread.

-Jim

@Aaron_Li In addition to what @ozrien said about following the documentation for our (CTRE) devices, I also want to point you to WPILib’s documentation for java projects in general:

https://docs.wpilib.org/en/latest/

You should follow that for getting started, installing, and creating a project. Do this first. That should help avoid some of the confusion you’re encountering with creating/deploying/running projects. Then follow our documentation for your Victor SPXs.

2 Likes

@everyone in this thread: My apologies for misunderstanding the procedure. I’m going to get this through, then see what’s next.

I assume don’t do the Tuner yet either?