Simulate Your Robot in LabVIEW for FRC!
With LabVIEW, you can get a early start learning LabVIEW Robotics for the FIRST Robotics Competition by using Robot Simulation to program a predefined robot without having an RT (Real-Time) roboRIO target. This allows multiple developers to concurrently create and test LabVIEW code without requiring each developer to have access to the hardware. Programming is the same, except only the predefined Actuators and Sensors on the simulated robot are supported. By exploring the pre-built LabVIEW Robotics Simulation projects, you can discover aspects of LabVIEW Robotics applications and learn how to start your own LabVIEW Robotics Simulation project. The intent of the Simulations are to start learning LabVIEW for FIRST Robotics Competition, but you do have the ability to move simulation code to an RT roboRIO target and run on it on a real robot.
|Note If two windows open, one may be a generic Dashboard window. Close it. You should only have a window open that is similar to the one shown below.|
|Note By default, the robot's simulated camera is turned off, as this takes more of the computer's processing power. To turn on vision acquisition, see the section in this tutorial titled Enabling Vision in the Simulation.|
|Note For help navigating the FRC Simulation Viewer, see the section titled Using the Simulation Viewer.|
Aside from Teleoperation of the simulated robot using the joystick, there are several options in the FRC Simulation Viewer to help customize your simulation environment:
The simulated robots are predefined - they cannot be changed. But they are the same as real robots in that they have sensors and actuators attached. By default, each project includes code to drive and control the robot. Beyond that, you may add your own code to make use of additional sensors and actuators included on each robot. This section includes the following topics:
Adding Sensors & Actuators to the Simulation
Enabling Vision in the Simulation
Building the Simulation for the roboRIO
In the Learn LabVIEW: Mecanum Maze Simulation project, you will notice a file titled Robot Simulation Readme.html under My Computer. This file contains information on the sensors and actuators that are connected to the simulated robot. In order to take advantage of these on the simulated robot, you need to know which channel the sensors and actuators are on and how each is wired to the simulated robot.
The Robot Simulation Readme.html is unique to each project. When modifying a simulation project, check this file to ensure that you have selected the correct channel to communicate with a sensor or actuator. Below is a list for the Mecanum Maze Simulated Robot.
You will notice that the simulated robot includes a gyro. To add a gyro to the Maze Simulation, you can take advantage of some existing sample code and the Custom tab on the simulation dashboard. Once you get code working in simulated mode, the same code can be built for a real robot.
|Note The indicator on our dashboard has a range of 0 to 360, but the VI to read the gyro data returns a value between -180 and 180. To account for this, you can add some logic to shift the values.|
|Note In a similar way, you can add code to control the camera servo in Teleop.vi. If you are able to control the camera servo, as well as get information from the other sensors, you can start to modify your program to try to navigate the maze autonomously.|
By default, image acquisition is turned off in the Simulation, as it takes more of the CPU processing power to enable Vision. This section will cover how to enable Vision in the Mecanum Maze Project.
The FRC Simulation projects are intended to get a start with LabVIEW Robotics. You can utilize the Simulation projects to learn the basics behind programming and controlling a robot. Though not the main use of the Simulation projects, you do have the ability to develop code in simulation mode and then move the code to the roboRIO. This would only make sense if your physical robot had the same I/O as the simulated robot. This section will cover how to move the simulation projects to the roboRIO.
Open Robot Main.vi. At the bottom, we can see a Timing Sensor VI and the Simple Error Handler. Delete these VIs from the Block Diagram. The Timing Sensors.vi is used by our simulation to determine when our robot crosses the start and finish in the maze. If you open the VI, you will see that we create two sonar sensors to track when you cross the start and finish line. If you aren't simulating, you do not need these.
The Ball Shooter Simulation Project is another simulation project that has been created to help you get started with LabVIEW Robotics. In this section, you will open and run the Ball Shooter Simulation Project. After testing out the project, you will open and explore some of the code.
Similar to the Maze simulation, you will also need to create the dashboard project from the Getting Started window or by going to File>>New...>>Project>>Project From Wizard>>FRC Dashboard Project. Select the Dashboard for Ball Shooter Robot project.
Run Robot Main.vi and enable TeleOperated mode in the FRC Driver Station. The Simulation Viewer should now be open and you should be able to control the robot with your joystick.
Run Dashboard Main.vi. You should be able to view data being sent by the robot in the dashboard. Notice the different settings as well as the score section.
In this simulation, the goal is to score as many points as possible. On the wall of the simulation, you can see three different holes. The top, small hole is worth the most points, but is harder to hit. On the dashboard, this corresponds to the "High Hits". The middle, medium-sized hole is worth 25 points, and is denoted by "Middle Hits". The "Low Hits" refers to the lowest, largest hole and is worth the least amount of points. You receive bonus points for getting a ball in each hole. Try to score a few points by driving with a joystick and shooting using the joystick trigger (Button 1).
If there is not enough power behind your robot's shots, try adjusting Shooter Speed. Shooter Speed refers to the speed of the motors that launch the balls from our robot. Experiment to discover what control on the joystick adjusts Shooter Speed.
Notice the other controls on the dashboard. You do not have an infinite number of balls in your robot. When you get low, you must drive around and scoop up the balls using the chute in the front of your robot. Scoop Speed refers to the speed of the motors scooping the balls into your robot hopper.
Look more closely at the balls stored in your robot hopper. They should be moving slightly. This is because there is an agitator servo inside of the bin that continuously moves the balls. This ensures that balls do not get stuck, and that our robot can keep shooting. Try adjusting the Agitator Speed to see how the robot reacts.
When you are done controlling the robot, you can close the dashboard and the Simulation Viewer. Press the Finish button on the Robot Main.vi.
Open the Robot Main.vi Block Diagram. Earlier in the Maze robot code, you explored adding and periodically reading a gyroscope sensor in Periodic Tasks.vi. In this program Periodics Tasks.vi is used to control the scoop motors, read sonar and gyro sensors, and control the agitator servo every 100ms.
By contrast, the loop containing Teleop.vi runs every 20ms. Teleop.vi is good for robot control, such as writing values to move the robot. Double-click to open Teleop.vi. Notice how the code reads from Network Tables, and then passes the values to a VI or writes to a variable. In the dashboard project, the code writes the values to Network Tables so that the robot project can read the user values.
Return to Robot Main.vi. Similarly to the Maze Simulation, another robot and sensor have been incorporated into the project to keep track of scoring. Double-click to open scoring sensor.vi and inspect the code to keep track of scoring.
Though a bit more logic is involved in this code, notice that, based on distance from the sensor, the code uses a Case Structure to write updates to the target counters, and then adds the score. The code shown below also uses NT Write Number to pass values to the dashboard. The names low target and Score exactly match the terminal names on the diagram of Dashboard Main.vi.
hello, urgent help, how can i obtain x y coordinate colour detection(output) into an angle for ev3 robot.
basically i have a x y coordinate value that i obtained from a picture and i am trying to use a vision camera to control robot to move the the object.
as of now i am stuck, can anyone help me please
There is an Issue with the default ShootServo Values in the FRC 2020 simulator.
The default project sets the ShootServo value to 0 when the the control button is pressed and 85 when the control button is released.
After the simulator is running and the driver station is enabled the ShootServo is moved to the fully back position for both a value of 0 and 85.
Out testing showed that the values 7 and 17 should be used instead so the ShootServo works correctly.
The ShootServo value is set in Teleop and the following values should be replaced
0 to 7
85 to 17
If someone from ni sees this comment can you please fix this issue for future versions. It was difficult to figure out the problem and the ball shooter simulator is not very useful if this function does not work.
Further investigation of the simulator shows the agitator and camera servos are also not correct.
The agitator does a full rotation in 55 counts instead of the expected 360
The camera servo does a 90 deg rotation in 12 counts.