From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

FIRST Robotics Competition Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Safety Configuration Tutorial - LabVIEW for FRC

 

LabVIEW FRC 2019: Safety Configuration Tutorial

 

A common problem with complex projects is making sure that all of your code is executing when you expect it to. Problems can arise when tasks with high priority, long execution times, or frequent calls hog processing power on the roboRIO. This leads to what is known as "starvation" for the tasks that are not able to execute due to the processor being busy. In most cases this will simply slow the reaction time to your input from the joysticks and other devices. However, this can also cause the drive motors of your robot to stay on long after you try to stop them. To avoid any robotic catastrophes from this, you can implement safety features that check for task input starvation and automatically shut down potentially harmful operations.

 

There are built-in functions for the motors that allow easy implementation of safety checks. These functions are:

  • Robot Drive Safety Configuration
  • Motor Drive Safety Configuration
  • Relay Safety Configuration
  • PWM Safety Configuration
  • Solenoid Safety Configuration
  • Robot Drive Delay and Update Safety

 

In all of the Safety Configuration functions, you can enable and disable the safety checks while your programming is running and configure what timeout you think is appropriate. The functions keep a cache of all devices that have the safety enabled and will check if any of them have exceeded their time limit. If any has, all devices in the cache will be disabled and the robot will come to an immediate stop or have its relay/PWM/solenoid outputs turned off. The code below demonstrates how to use the Drive Safety Configuration functions to set a maximum time limit that the motors will receive no input before being shut off.

To use these VI’s to protect both your robot and yourself, follow these steps:

 

  1. Opening a new reference to a MotorControl, PWM, Relay, RobotDrive, or Solenoid creates a “safety reference” for that device in the background.
  2. Calling the Safety Config VI for the device allows you to enable or disable the safety feature for that device and to set a timeout value.
  3. The value written to that device must be updated at least every period of the timeout counter or the safety mechanism will interrupt its output. If the safety mechanism is triggered the following actions are taken for each type of device:
    1. MotorControl – stops the motor
    2. PWM – turns off PWM
    3. Relay – resets the relay to its default value
    4. RobotDrive – stops the motor
    5. Solenoid – resets the solenoid to its default value
  4. Ensure that the motor control reference and the “safety reference” are closed by calling the reference close VI.

 

NOTE: Only the RobotDrive Open VIs enable the safety feature by default. For other devices, the safety feature needs to be manually enabled by calling the Safety Config VI for that device.

 

When the MotorControlSafety VI is called it automatically creates a “safety reference” for that device. The MotorControlSafetyConfig VI is then used to enable the safety feature and set a timeout value of 100ms, set when calling the VI. Inside the While Loop, the MotorControlSetOutput VI is called repeatedly. If more than 100ms elapse between calls to the MotorControlSetOutput VI then the motor will be stopped until the MotorControlSetOutput VI is called again. At the end of the program, calling the MotorControlClose VI also closes the “safety reference”.

 

Here is an example of the Safety Config VI being used for MotorControl:

motorcontrol.png

 

To test the safety shut-off, try adding a Wait function to the loop that is longer than your timeout and watch the motors stop responding to your inputs! (Then delete that because we don’t want your robot shutting itself down whenever you start it).

 

Here is another example of how to integrate safety into the bigger picture of your robot system:

 

bigpicture.png

 

For safety reasons it is recommended that you always enable the safety feature for your MotorControl, PWM, Relay, RobotDrive, and Solenoid devices. However, if you prefer to use the Watchdog Vis to implement a safety mechanism in your code, those are also still available to you in the newer versions of LabVIEW FRC.

Dane S.
Product Support Engineer
National Instruments