1"use strict";(self.webpackChunktechtoolbox=self.webpackChunktechtoolbox||[]).push([[8330],{3905:(e,t,o)=>{o.d(t,{Zo:()=>s,kt:()=>h});var n=o(7294);function r(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function a(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?i(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):i(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function l(e,t){if(null==e)return{};var o,n,r=function(e,t){if(null==e)return{};var o,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(r[o]=e[o]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(r[o]=e[o])}return r}var p=n.createContext({}),d=function(e){var t=n.useContext(p),o=t;return e&&(o="function"==typeof e?e(t):a(a({},t),e)),o},s=function(e){var t=d(e.components);return n.createElement(p.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var o=e.components,r=e.mdxType,i=e.originalType,p=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),u=d(o),c=r,h=u["".concat(p,".").concat(c)]||u[c]||m[c]||i;return o?n.createElement(h,a(a({ref:t},s),{},{components:o})):n.createElement(h,a({ref:t},s))}));function h(e,t){var o=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=o.length,a=new Array(i);a[0]=c;var l={};for(var p in t)hasOwnProperty.call(t,p)&&(l[p]=t[p]);l.originalType=e,l[u]="string"==typeof e?e:r,a[1]=l;for(var d=2;d<i;d++)a[d]=o[d];return n.createElement.apply(null,a)}return n.createElement.apply(null,o)}c.displayName="MDXCreateElement"},4112:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>p,contentTitle:()=>a,default:()=>m,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var n=o(7462),r=(o(7294),o(3905));const i={sidebar_position:3},a="Creating an OpMode",l={unversionedId:"Getting Started/opmode",id:"Getting Started/opmode",title:"Creating an OpMode",description:"* Our tutorial on opmode creation",source:"@site/docs/Getting Started/opmode.md",sourceDirName:"Getting Started",slug:"/Getting Started/opmode",permalink:"/docs/Getting Started/opmode",draft:!1,tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"Choosing a IDE",permalink:"/docs/Getting Started/ide"},next:{title:"Motors and Encoders",permalink:"/docs/Getting Started/motors"}},p={},d=[{value:"Two Types",id:"two-types",level:2},{value:"OpMode",id:"opmode",level:2},{value:"LinearOpMode",id:"linearopmode",level:2},{value:"Important LinearOpMode Methods",id:"important-linearopmode-methods",level:2},{value:"Tele-op Linear OpMode",id:"tele-op-linear-opmode",level:2},{value:"LinearOpMode Autonomous",id:"linearopmode-autonomous",level:2}],s={toc:d},u="wrapper";
1function m(e){let{components:t,...o}=e;return(0,r.kt)(u,(0,n.Z)({},s,o,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"creating-an-opmode"},"Creating an OpMode"),(0,r.kt)("admonition",{title:"Resources",type:"note"},(0,r.kt)("ul",{parentName:"admonition"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://www.youtube.com/watch?v=UmsXnZxoDmI"},"Our tutorial on opmode creation")))),(0,r.kt)("p",null,"In FTC your code is written in op-modes, you use op modes for both Tele-op and Autonomous. You will learn the basics in setting up your first op-mode."),(0,r.kt)("h2",{id:"two-types"},"Two Types"),(0,r.kt)("p",null,"There are two types of op-modes, the OpMode and the LinearOpMode, both of them are programmed a bit differently, but ultimately achieve the same purpose. Our video on OpMode Creation goes in depth into both. "),(0,r.kt)("h2",{id:"opmode"},"OpMode"),(0,r.kt)("p",null,"An OpMode class is composed of five different methods that you can write your code inside. The code in the five different methods runs in a different time/way. "),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"init()")," - Code inside this method will run once after the program is initialized."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"init_loop()")," - Code inside this method will loop repeatedly while the program is initialized."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"start()")," - Code inside this method will run once after the program is started."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"loop()")," - Code inside this method will run repeatedly for the duration of the program. "),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"stop()")," - Code inside this method will run once after the program is stopped.")),(0,r.kt)("p",null,"The whole setup for the OpMode class with all five methods will look like this."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-java"},'import com.qualcomm.robotcore.eventloop.opmode.OpMode;\n\n@TeleOp(name = "NonLinearTeleop")\npublic class FirstTeleop extends OpMode { //Make sure the class extends OpMode\n @Override //Override is used for each loop\n public void init() {\n //Happens once on init\n }\n\n @Override\n public void init_loop() {\n //Happens repeatedly during init\n }\n\n @Override\n public void start() {\n //Happens once after program starts\n }\n\n @Override\n public void loop() {\n //Happens repeatedly during the program\n }\n\n @Override\n public void stop() {\n //Happens once after stop\n }\n}\n\n')),(0,r.kt)("h2",{id:"linearopmode"},"LinearOpMode"),(0,r.kt)("p",null,"The other op-mode class is called LinearOpMode. It uses some different functions and has the code organized differently."),(0,r.kt)("h2",{id:"important-linearopmode-methods"},"Important LinearOpMode Methods"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"waitForStart()")," - Waits for Program to be started after initialization."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"opModeIsActive()")," - Checks to see if the op-mode has been started, returns True or False."),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("inlineCode",{parentName:"li"},"runOpMode()")," - Contains all op-mode code, runs once after the start of the OpMode.")),(0,r.kt)("h2",{id:"tele-op-linear-opmode"},"Tele-op Linear OpMode"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-java"},'@TeleOp(name = "LinearTeleop")\npublic class LinearTeleop extends LinearOpMode{\n @Override\n public void runOpMode() throws InterruptedException {\n //Initialization Code Goes Here\n waitForStart();\n while(opModeIsActive()){ //while loop for when program is active\n //Code repeated during teleop goes here\n //Analogous to loop() method in OpMode\n }\n\n }\n}\n')),(0,r.kt)("h2",{id:"linearopmode-autonomous"},"LinearOpMode Autonomous"),(0,r.kt)("p",null,"The autonomous for LinearOpMode is very similar to the Teleop setup, however the while(opModeIsActive) is not necessary for most code as autonomous happens once. The while(opModeIsActive) can still be used for things such as constant telemetry readings during the autonomous."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-java"},'@Autonomous(name = "LinearAuto")\npublic class LinearAuto extends LinearOpMode{\n @Override\n public void runOpMode() throws InterruptedException {\n //Initialization Code Goes Here\n waitForStart();\n //Auto Code Goes Here\n\n }\n}\n')))}m.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.