Blog Post

How to Use SD540C and CANLight with RoboRIO

How to Use SD540C and CANLight with RoboRIO

1652

We're excited to bring two new products to you this season: the SD540C motor controller and CANLight LED strip controller! This blog post will guide you though getting your first example program up and running.

 

Updating Your roboRIO

WPILib has some great documentation on setting up your roboRIO and development environment. Getting Started with the 2017 Control System is a great place to start. Make sure you have the latest Eclipse plugins and the 2017 image on your roboRIO before continuing. If you're using LabVIEW instead of Java/C++ in Eclipse, take a look at How to Use SD540C and CANLight with LabVIEW instead.

 

Installing the Library

This process has been made very simple for the 2017 season. Check your home user directory (C:/Users/username) and look for a wpilib folder. The WPILib Eclipse plugins should automatically download and create this folder when you launch Eclipse. If you see a popup in Eclipse that says installing Java, this is it downloading the current WPILib Java library.

Inside the wpilib folder you should see a folder named "user". Download the mindsensors FRC library, unzip it, and copy the user folder here to the corresponding folder you found earlier. Your user folder should contain a cpp and java folder.

 

The mindsensors Configuration Tool

The mindsensors Configuration Tool can be used to change the parameters of your SD540C and CANLight devices. For the SD540C this includes changing the ID, name, limit switch settings, invertedness, and stop behavior. For the CANLight it also features a live-updating color test mode. The mindsensors Configuration Tool will also allow you to update firmware. Read more on how to download and use this tool on our blog post.

 

Running an Example Program

Go ahead and open up Eclipse! Or, if you already have it open and just installed the mindsensors library, restart Eclipse.

Press Ctrl+N or click File → New → Other…. Open the WPILib Robot Java/C++ Development folder in the window that appears, and double-click Robot Java/C++ Project.

On the following screen give your project a name and select Iterative Robot for the project type. You may be asked for your team number. If you need to change this you can do so in Window → Preferences → WPILib Preferences.

Open your new project, then src folder, the org.usfirst.frc.team####.robot package (if you're using Java), and double-click Robot.java (or .cpp). Replace this file with any of the examples you can find below. If you are working in Java, be sure to change the package declaration (line 1) to match your team number.

 

  • SD540C_BasicMovement.java, .cpp:
    The most basic program to make the SD540C move a motor. Import the CANSD540 package, create a CANSD540 field, instantiate it in robotInit(), and call .set(double speed) in autonomousInit(). You can use any value between -1.0 and 1.0.

  • SD540C_Joystick.java, .cpp:
    Very similar to before, but now we repeat these steps to add and instantiate a Joystick. In teleopPeriodic() we set the motor to the joystick's Y axis. The methods to get an axis from the joystick already return -1.0 to 1.0 so we don't need to scale it. We use teleopPeriodic() instead of teleopInit() because we want to keep setting the motor to the current joystick position, not just once when we start teleop.

  • SD540C_Coast.java, .cpp:
    Now we use teleopInit() to configure the SD540C at the beginning of teleop. We set the stop mode to coast instead of brake. Keep in mind that the SD540C will remember your settings even if it loses power. This is great if your robot's PDP hiccups in a competition, but you may want to set this back to brake in a different program. setVoltageRamp will ramp up the motor when it is set instead of instantly going to that value. 0 (default) will instantly start moving the motor at the new speed you set, while a larger value (up to 255) will give you a smoother change in speed. This can be useful to make the robot drive more gentle for rookies driving the bot for the first time.

  • SD540C_LimitSwitches.java, .cpp:
    The SD540C has built-in support for limit switches. This program gives you an example of how to use them. More detail is given in its comments.

  • CANLight_BasicColor.java, .cpp:
    As with BasicMovement before, this is the simplest way to set the CANLight to a color. Here we set the color right as the robot is initialized instead of waiting for autonomous.

  • CANLight_Demo.java, .cpp:
    This walks you though all of the methods provided in the CANLight library. It also introduces the concept of the CANLight's color memory bank.

  • CANLight_CustomFlashes.java, .cpp:
    If you want to use some more involved flashing patterns, this gives you an example of how you might do so. Uncomment only the method you want to try out in autonomousInit().

  • CANLight_MatchAlliance.java, .cpp:
    This program will change the lights' color to match your robot's alliance. You can change your team's position in the bottom-middle of the driver station, labeled Team Station.

 

Conclusion

We hope you have fun using these devices! You can find a full list of available methods in the Java and C++ documentation. If you want to link the Javadoc in Eclipse for convenience, we have a blog post on that. Feel free to post in the mindsensors.com forum if you need help, or Chief Delphi if you are new to FRC. Good luck in the 2017 season!

Comments (0)

No comments at this moment
Please Login to add your comments

Featured Posts

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more

Poll

  • What do you use to program your FRC Robot?
    Total: