Proggindor

Code Explanation

progemon-1.jpg

Progémon are programs created by Proggindor, FRC Team 1884's Programming Team.

Starting Progémon

These Progémon are the 'main' of our code; they are immediately called and are the brains of the operation.

Griffins Robot VI

It is easier to split Griffins Robot VI, our main 'main' program, into three parts: Camera, Joystick Control and Sensors

Camera Code:

This part of the code is for the camera. It tracks two colors. Right now these colors are set for Pink and Green, corresponding to the trailer target's colors. You can track other colors by changing the Hue values. It uses two servos to move the camera. You can make it track one color before another. The optimal settings for brightness is 80, Servo sleep 20 milliseconds, and milliseconds to wait 100. The IP for the camera is 192.168.0.90 for the Axis network Cam 206. The code is split into two parts; the first is Camera Code (to find the target) and the other deals with the camera servos. Gimbal Track is to search for the colors and camera display. During camera display, the camera will not search; you just see what the camera sees. It is during Gimbal track that the camera searches for the enemy target's colors.

Camera Code Link:http://www.mediafire.com/?linuymzyziy

Joystick Drive Control

Joystick Drive Left/Right Code:

This is the code for the Joysticks(Left and Right) for driving in Tank Drive. First outside the while loop you must open the joystick then define which USB it goes too from the Joystick Get Sub VI from WI Robotics Library. Also connect it to a Joystick drive ref. Then inside the while loop you have to define the axes of the joysticks from the Joystick Get Axes Sub VI from WI Robotics Library. In our code made the axes 127 because 127 is full forward on the joystick and full backwards is -127. You must also give the WI Robotics Get Joystick Axis VI a axis. Outside the while loop you have to Close the Joystick with the Close Joystick Sub VI WI Robotics Library. The values for the motor power is given by the left and right joystick. In this section of the code left joystick value is multiplied by drive power and then that is inputed into Drive Tank left axes value same is done for the right joystick.

Joystick Third Joystick Code:

This is the code to control the tower for our 2009 robot. This was our third Joystick in our drive control set-up. First (outside the while loop), you must open the joystick and define which USB it goes to from the Joystick Get Sub VI from WI Robotics Library. Also connect it to a Joystick dev ref. Then inside the while loop we use a Get Joystick Sub VI and from the buttons ouput we ouput a cluster to represent the buttons. On our particular joystick there are 6 Buttons.

  • Button 1(Trigger): Shooter roller foward
  • Button 2(Middle Button): Shooter roller backward
  • Button 5(Right Side Button):Tower on
  • Button 6(Left Side Button):Tower off

There is also an axes cluster to control the throttle for the amount power given to the Tower. Full foward is -1 and Full backwards is 1 this is because on the motors -1 is foward while positive is backwards. Tower Speed is given by the power of the lift and sweeper. Both lift and sweep have the same amount of power. Lift and sweep are initalized at -1

Sensors

Code for Gyro

For the 2009 gyro, which is analogue, we first open the Gyro and define the slot and AI of the gyro. Then we reset the gyro to get zero on the counter. After this (inside the while loop), we set gyro gain to 0.0125. Next we use the Sub VI Gyro Get Angle. We feed angle to theta (see Theta for more information). After that, we graph the resulting data on waveform graphs. For Angular Rate we feed the number directly into the graph without using any Sub VIs beforehand. Finally (outside the while loop), we close the gyro.

Code for Ultrasonic

Our 2009 Ultrasonic is analog. We first open the Ultrasonic with the Analog open Sub VI and then feed it the Slot and AI which it goes into. Then (inside the while loop), we get the analog value with the Get Value Analog Sub VI and we graph the value which is recorded in volts. We also give the Ultrasonic milliseconds to wait. Outside the while loop, we close the Ultrasonic with the Close Analog Sub VI

Accelerometer Code

First we open the Accelerometer for both X and Y we feed which Slot and AI it goes too. Then we set the centre of the Accelerometer, the centre for the accelerometer is 2.5 we do this for both X and Y. Then we set the gain of the accelerometer to one. Next we get acceleration and feed it in to two separate graphs one for X and one for Y. Finally outside the while loop we close the Accelerometer.

LEDs

This code is for the LEDs that are attached to the Driver Station. We only have two LEDs at the moment, one for 'Dump' and the other for 'Slipped'. We start with a cluster of 8 booleans (8 is the number of outputs on the DS) and change to an array. We add an element, 'Dump' AND the output of "angle in range.vi", inputting 'shoot a' and 'Servo Y', to the last element, or 7. We then add another element, the output of "Encoder Slippage," to 6. We then output the array to the DS, and put the cluster through the shift register.

Autonomous Independent.vi

This program is run automatically in autonomous mode where the robot is not controlled by any external forces. This code uses a state machine to process information. All throughout the loop, we search for a target, sent from the camera VI. Code for the autonomous period is stored in this VI, and must be capable of running without human control. This code will run during the 15-second autonomous period in matches.

State 1: Run and Hide

We execute the Run and Hide sub vi, when this vi terminates, we go to the Start Search State

State 2: Start Search

This state initializes variables to enter Search state. We aquire our target gyro and set required boolean values.

State 3: Search

This state rotates the robot 360 degrees. To do this, it initializes an angle 180 different from its current angle. When it reaches this point, it continues rotating until it is back in the starting position. If we do not find a target during this time, we go to the Dance state.

State 4: Dance

This state executes the sub vi Dance. During Dance, we always look for camera targets. If we ever see a target, we move to the Track state.

State 5: Track

This state tracks a visible robot. When the camera sees a target, the robot will turn in order to face the target. It will then move foward until it crashes into the robot, dumping its payload. If we ever lose the target and we aren’t rotating to face it, we go to the Start Search state.

Basic Robot Global.vi

The Bulbasaur of all Progémon, this is the the third of our 'main' programs, where all global variables are created.

Device References

  • Motor Control - Shooter
  • Motor Control - Sweeper
  • Motor Control - Lift
  • Robot Drive
  • Watchdog
  • Basket Roller

Booleans

  • stop dancing (control)
  • found target (indicator)
  • auto rot (indicator)
  • Dump (indicator)

Numbers(all indicators)

  • Servo X Position (DBL)
  • Servo Y (DBL)
  • Ultrasonic Value (I16)
  • Gyro Angle (DBL)
  • Gyro Rate (DBL)
  • Accel X (DBL)
  • shoot a (DBL)

Common Progémon

These Progémon are simple yet effective SubVI's that are common throughout the code, and could be reused next year.

angleinrange.VI

Checks whether the 'Robot Angle' in within the 'Range Threshold' of the 'Target Angle' First adds and subtracts the threshold from the 'Target Angle', using "Normalize Angle.VI". If the threshold and the target added together is greater than the threshold subtracted from the target, it checks the 'Robot Angle' is within the threshold. If that's false, then it compares the 'Robot Angle' is less than the added threshold or greater than the subtracted threshold. It outputs the boolean if it is in range.

inrange.jpg
hello this is……….

Crashed.VI

This SubVI determines whether the Robot has 'crashed' in to an object. It relies on the input from the 'Accelerometer' and another input from 'Threshold', and compares the two, so that, if the Accelerometer is greater than the threshold, 'Crashed' becomes true. Only when 'Reset' is true is 'Crashed' reset to false.

inrange1.jpg

distancethingy.VI

This poorly named VI converts encoder values to distance values. In essence, it multiplies by -1 if the input boolean 'Distance' is false and by 1 if true and multiplies it by 0 if 'Stopped?' is true, or it doesn't change. The input 'Distance' is for the encoder value and the output 'Distance to Add' is the reformatted encoder value to match distance.

distancethingy.jpg
…The great Jedi master…

Encoder Slippage.VI

This constitutes majority of our traction control. It receives input from 'Encoder' which is the Encoder value. It is divided by the time that has elapsed, or Total Tick Count minus 'Tick Count', or the last implementation's Total Tick Count. This becomes 'Slippage', and is compared to the previous 'Slippage' x 1.2, to see if there has been a slip by our wheels due to too much power. It outputs whether the 'Slippage' is greater than 1.2x previous 'Slippage'.

inrange-1.jpg
…of subVI icons…

Normalize Angle.VI

Normalize Angle is a widely used yet simple SubVI that makes sure the angles are between 0o and 360o. It takes the 'Raw Angle,' mods by 360, and outputs 'Normalized Angle'. Modulus means 'divide by and take the remainder' (ie 5%2 = 1, because 5/2 = 2 with 1 as the remainder).

inrange-2.jpg

turn.VI

This is the SubVI that makes the robot turn while moving forward at the same time. It inputs 'Strength', which is the deisred power to the motor and a boolean 'Right = true Left = false" which is quite self-explanatory. If it's right, 'Strength' is negated and passed on to the 'Left Motor' and 'Strength' is multiplied by -.5 which is 'Right Motor'. This means that the right motor moves forward with half the strength the left motor moves with, causing a right turn. The opposite values are given for turning left.

turn.jpg
…i have nothing else to say except..

Rare Progémon

Rare Progémon are SubVI's that are hardly utilized and are probably not usable next year.

dance.VI

This program is our automated random move program. Initially, it sets up the value of 'i', which is a random number between 0 and 2 initalized on the first call. Also, it sets 'set direction' to be true.

When 'set direction' is true, variables are initialized while the robot goes forward 'strength' value, which is an input. 'Random number' is the strength of a random number divided by 4. Also 'End Time' is initialized to 1 through 5 seconds. 'i' is incremented by 1 and 'set direction' equals false.

When 'set direction' is false, the robot turns in a random direction. The direction is dependant on 'i', as if it is even then it turns right and if it isn't then it turns left.

dance.jpg

..that his is actually useful writing btw, div blocks are really annoying, so the title keeps hitting left, and it doesnt seem to work

Run&Hide.VI

This step-by-step autonomous program instructs the robot to turn, go forward and turn. The degree and direction of the turns is determined by the binary input value, which is representative of switches.

  • 0 = Turn 45o right then -90o left
  • 1 = Turn 90o right then -95o left
  • 2 = Turn -45oleft then 90o right
  • 3 = Turn -90o left then 45o right
runandhidecopy.jpg
some of these icons suck and arent mine.

Between the two turns, the robot accelerates forward until it 'Crashes', then moves backwards.

The uses a stage case structure; what stage it is on is dependant of the 'Stage' number variable.

  • When 'Stage' = 0, the "true = left then right" initialize and the first turn angle is instantiated. Stage becomes 1.
  • In Stage 1 it turns, utilizing the "Angle in Range" and "Turn" Sub VIs to turn the desired amount, as dictated by the 'true = left then right' and the 'Position' U32 which is the switches value.
  • Stage 2 accelerates forward until the "Crashed" SubVI outputs true, based on the premise that the robot should stop when it hits the wall. The speed of the forward movement is determined by the input 'Strength'. Also, the 'Target Time' is initialized.
  • In Stage 3 'Left Axis' and 'Right Axis' is set to 'Strength', and the robot backs up for 500 seconds.** Also, the 90o turn angle is set.

**Note: Strength should be a positive number, therefore to move forward it is negated

  • In Stage 4 it turns just like Stage 1
  • In Stage 5 the motors are stopped

Legendary Progémon

Legendary Progémon are mythical SubVis that are hardly or never implemented but are still spoken of.

DuckCheckers.VI

Part of the 'Ancient Code' supposedly for a primitive 'Sitting Duck' code, its function has long been forgotten. Its name and icon will live long in the hearts of Proggindor, and legends tell us that only programmers have seen it, as it only appears every full moon. But that's only a legend, right?

Picture2.png
Yours truly, George Nishimura

The Button.VI

Stories of the button are vague and undetermined. They say that a bored programmer inadvertedly created a program that could potentially destroy the world if not 'executed'. Now he spends his day punching in numbers and pressing 'The Button' every 108 minutes, not knowing whether what he is doing is saving the world or wasting his life.

thebutton-1.jpg

This message has been approved by George Nishimura, and if you have found it and read through all of it well done. The SubVI Icons that I made are Encoder Slippage, Crashed, The Button, DuckCheckers and Run&Hide, although I did draw the theta of Normalize Angle. This pages has been composited by Freddy Rading and George Nishimura, a documentation of the work of Proggindor. Special Thanks goes to Omkar Joshi, for syntax help. And Jaroslav, for 'creating' the site.
Copyright © 2009 by FRC Team 1884

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License