1 / 41

Introduction to Team 294 Programming Concepts

Introduction to Team 294 Programming Concepts. Ken Sterk 7/29/2007. Goals and Objective. To highlight the major software related physical components and programming elements used in a FRC robot To establish a basic understanding of the base FRC code

kelliw
Télécharger la présentation

Introduction to Team 294 Programming Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Team 294 Programming Concepts Ken Sterk 7/29/2007

  2. Goals and Objective • To highlight the major software related physical components and programming elements used in a FRC robot • To establish a basic understanding of the base FRC code • To understand the primary functions and algorithms used by team 294 • To develop familiarity with the software compilation process and the downloading process

  3. Software Elements • How do human commands actually get to robot? • Push joystick/Click button • ??? • Wheels move, Arm scores. • We win!!!!

  4. Software Elements cont. • Well not quite. Lets expand upon “???” • There are several major items between Pushing the joystick and getting the robot to move • The OI (operators interface) • The FRC robot controller • The Motor controllers and relays and sensors • Victors • Spikes • Encoders, potentiometers, etc

  5. Motors/pneumatics Sensor Operators Interface Radio Spike Robot Controller Victor The Robot Software Elements cont. • The Software interacts with all of these elements. Thus you can look at the robot sort of like this..

  6. Software Elements cont. • So now human commands get to the robot through the following path • Push joystick/Click button • Signals sent from OI to robot controller via radio • Robot controller • ??? (oh noes not again…) • Victors and spikes get signals and send power to motors and pneumatics • Wheels move… Arm scores… • We win!!!!

  7. Robot Controller • So what does the robot controller do? • Essentially it’s the brain of the entire robot. • The robot controller is simply a small microprocessor. • Using the inputs from it OI and readings from the sensors the robot controller will determine the commands to send the Victors and spikes based upon the algorithms and logic we have written. • It has multiple ports for communication and power

  8. PWM outputs Backup Battery Main Power Programming Port Tether port Radio Port Analog inputs Digital I/O Reset + Program buttons Robot Controller

  9. Operators Interface • That is the OI is an integrated piece of hardware that interprets signals received from analog/digital inputs such as Joysticks, buttons, toggle switches. • It has the ability to send data and receive data • Receive data such as our HUD (heads up display) or error data. • Sends joystick data, switch values, etc.

  10. Operators Interface cont. Competition Port Tether Port Radio Port Dashboard viewer port Port 3 Port 1 Port 2 Port 4 LED Display toggle Team # dipswitch Reset

  11. Victor 884 + Spike The Victor 884 is a speed controller used by the FRC robot controller board to command the motors to run • It gets a PWM command from the robot controller • Through its internal circuitry it generates a current to provide the motors based upon the input PWM value • The Spike is essentially a small switch that allows current to either pass in one direction or another. • It can be used to drive small motors in forward, reverse, or stop (brake).  • Or more commonly it is used to drive the solenoids we use in out pneumatic system to open or close valves.

  12. Sensors • There are several sensor types that have been used by team 294 in the past few years. • Briefly we have used: • Potentiometers • Simply a variable resistor that outputs a different voltage based upon what angular position it is at. • Used to measure our angular position based upon a reference position. • Encoders • Used to measure angular rotation, or angular rotational velocity. • Either magnetic or optical in construction, outputs a simple set of pulses per revolution. • Rate Gyro • Measures the angular rotational rate. • Useful for determining overall robot rotational rate • Camera • Obviously it’s a camera. It outputs relative angles of the object that its looking at based upon its calibrated color its looking for

  13. Sensors cont. • Potentiometers • Encoder • CMU camera

  14. Getting Started with Code • You need a computer….duh • You will need a serial port or a USB to serial converter • Download or install all the necessary programs • MicroChip MPLAB: • This is the default FIRST C programming environment. This is where all of our code will be written. We can open projects and modify the code here. There are several different types of compilers and environments. • C-18 • This is the compiler to translate the written code into a language that is recognizable to the embedded microchip in the robot controller. The compiler is specifically tailored to compile the code to a specific set of microchips. • IFI-Loader • This is the default software used to program the actual robot. It uses the serial connection between your PC and the robot controller. • The FRC Default source code • The “source” is essentially a fancy word for all the logic that we are going to edit and the put on the robot

  15. Getting Started with Code • C Code Hierarchy • .c -Source Files • .h -Header Files • .lib -Library Files • .lkr -Linker Scripts • We will edit the .h and .c files • Compile and download to the RC

  16. Working with Code • We are primarily concerned with modifying only the .c and .h files in the code. • More specifically we are going to be modifying the user_routines.c and user_routines.h file. • Here we have code that enables us to read inputs from the OI • We can sample the inputs from the sensors • We can the utilize this information and run our custom functions (PID) to make the robot do what we want to do. • To understand how this all works together we will take a look at how all the code is put together

  17. Working with Code • What is this .c and .h file? • The .c file is considered the source file. • This file is where the actual math is done. It is where you will put all your functions. • Eg. Motor1= (255-JoystickInput)*scale; • The .h file is called the header file • The header file is where we enumerate (define) all the variables that we are going to be needing for the functions called in the .c file • It should have the same name as the .c file

  18. Working with code: Main.c • Everything starts within the top function called main.c • This function simply calls all the necessary functions needed to run the robot. • It first will initialize all the variables that you have defined • It will the process all the inputs • It will run autonomous code if needed • And finally it will execute all of your written algorithms and write the data to the output of the controller.

  19. Working with Default Code

  20. User_Initialization • This is where we initialize all of the variables to their starting values • Initialize PWM values to send to victors as neutral (127). More on this later • Initialize the digital inputs and outputs • Initialize the input and output ports for use in the code

  21. Working with Default Code

  22. Process_Data_From_masterUP • The name sounds complicated but in reality it calls a set of functions used to read in the info from the camera. • It also is used to process any other data from any other sensors that need to be read • But most importantly it calls the default_routine. • And finally it will take all the data written by the default routine and put the data on the output ports of the robot controller.

  23. Default_routine • The default routine is the basic code that is used to control the robot. • This is the location where team 294 does the majority of the changes to the code. • The default code is preloaded onto the Robot Controller which provides a way to simply build a robot and drive it around without worrying too much about programming

  24. Default_routine • Since the code is so long only snippets of the code will be shown. • Essentially it does two things • Reads the OI values from the joysticks and assigns the correct PWM to each wheel • Maps button presses on the joystick to the relay outputs on the robot controller

  25. Working with Default Code

  26. Autonomous code • This is the special code position where we will put out autonomous functions. • Only used when autonomous time is valid. • The default autonomous code does nothing • This runs in the user_routines_fast file

  27. Working with Default Code

  28. Process_Data_From_Local_IO • Another really long name that does not do anything too complicated • All it does is process data every program loop • So if you have something that needs to be executed every single program loop this is where you will put it • The only thing team 294 has running every loop is the autonomous code • We have also experimented in the past with using interrupts for reading in inputs from other sensors

  29. Changes to the Default Code • Team 294 does make some changes to the default code • These changes enable us to do much more complicated things. • We have code to drive the arm linkages by using a PID algorithm. • Operate the gripper to effectively grab game pieces and score points • Autonomous code to score during the autonomous periods • In addition we have cleaned up some of the initializations to make the code more legible and intuitive

  30. 294 Code Changes • All these changes exist with in the files we just covered before. • The files we have changed are • User_routines • We wrote our own default_routine. Now called control_routine • User_routines_fast • We have added our own autonomous code

  31. Control_routine • This is the code used for the 2007 robot • For the control routine to work we needed to first add initialization to the arm motors. Hence we have added this line to the User_initialization function

  32. Control_routine cont. • Now onto the bulk of what we have done • What we are attempting to do is take in commands from the OI and make the robot do what we want to do • First: Drive all 6 motors based upon the commands sent by the joystick • Second: Move the arm to a predefined position that we want to go. • E.g. Pick up off ground, Score, descore. Etc • Operate the pneumatics to open and close the gripper to pick up the game piece • So lets take a look at that your teammates wrote

  33. First we define all the internal variables to the function. Eg. The grabber state, the arm command, etc Next read in the actual arm positions from the sensors (potentiometers) Then set the arm pwms to 127 A pwm of 127 is considered to be zero motion The pwm ranges from 0-255 0 being full reverse and 255 full forward. Control_routines cont.

  34. Control_routines cont. • Next we have modified the drive code to drive all 6 motors we have on the robot. • If you notice that the names are different than calling it pwm01, pwm02 • The reason for this is to make it simple to read the code. • The actual mapping of the “LEFT_DRIVE_CIMS” is located in the header file! • We have also included the ability to let the operated reduce the top speed of the robot for a fine control of the driving

  35. Control_routines cont. • Next is the arm commands • In 2007 we had two ways to control the arm • First we could use a “fine tune” using the co-drivers joystick • Or we could use the preset positions for pickup, score low, score high etc. • These used the toggle switches on the on the control board

  36. Control_routine cont. • Fine control. Takes the input from the joystick and issues a new command to the arm (either shoulder or elbow) in small increments • This calls the PID function to be reviewed later • Again notice the variables names to be intuitive and easy to understand • Also comments are really useful to separate out the code

  37. Control_routine cont. • Using preset positions. • Only one shown for brevity • Sets the command to a predefined position • Positions set via calibration before the match

  38. Control_routine cont. • This is the code to effectively run the gripper. It will open and close based upon the drivers commands

  39. control_routine • Finally the arm command has been set, the gripper is either set to open and close • But now we need to send the arm commands to the motors. • We do this through a function called PID • What PID is a very effective method to write the PWM commands to the motors. • It uses the error between the arms current location and commanded position to determine how fast it should go • There is a ton of theory here that we can go over another time • The PWM are then written by the PID function and sent to the arm motors • That then finishes off the control_routine!

  40. Autonomous code • In the user_routine_fast file simply add in the code you want to execute under the autonomous • In 2007, we never got autonomous code fully tested due to a variety of other problems • In 2006 we had a fairly effective autonomous code that could select between several options to score • In 2005 we had a very simple set of code to score a couple points consistently

  41. Wrapping it up… • So we have covered: • Some of the basic elements that are used as interfaces between our code and the actual robot • The tools necessary to build and compile code onto the robot • A quick (hopefully) overview of what the default code looks like and how it runs • Finally, the changes made to the default code by team 294

More Related