Over the years we have had some great programming students on our team. We find, however, that our programmers already knew how to program before joining. This year, several of our programmers have graduated – but we have many new students who have expressed an interest in learning to program. Historically, we haven’t had a lot of success with students learning to program through us – and we are hoping to change that.
Programming has a fairly high barrier to entry – you need to learn syntax, setup development environments, and initially at least, it seems to take a lot of text to produce a mundane output. FIRST changes the last part of this – with just a few lines of code you can make a robot move or actuate a component. We want to leverage this to make coding exciting.
Our approach for the year is to have students learn some background knowledge on their own and then to dive straight into making robots move. Hopefully the excitement of making a robot move spurs students to want to delve deeper into the underlying details, and will help foster individuals who are able to produce useful code.
Step 1 – Learn Some Syntax
We program in Java – and it is a fairly popular language. For someone just starting out though, it is very much a foreign language. We feel that it is important to know at least the basic structures – variables, conditionals, loops, etc. – before trying to do something with them. More over, as with any learning, programming should be an active task. There are a multitude of tutorials that exist on Java – most of them however, either focus on a single idea or simply present the ideas without an opportunity to implement them. We wanted a platform that would present an idea and give students an opportunity to practice that idea. Additionally, it needed to not require the setup of an IDE as this presents an additional barrier to entry. CodeAcademy was recommended by one of our mentors and has proven to be a good platform for teaching the basic ideas.
So far, many of our students have completed the basic Java course that CodeAcademy offers. The challenge though is that through this process they were guided step by step towards a solution. Real programming is usually much more open-ended and the errors are far more cryptic.
Step 2 – Practice Solving Problems
As with everything, to improve, one needs practice. This presents two challenges for us – firstly, how do you practice? Writing the same ‘Hello World’ program with a different phrase isn’t really useful; secondly, how do you verify that the code was written correctly.
To actually get useful practice, students need to attempt a variety of different programming problems – problems that are all slightly different and which require writing actual code. Ideally, these problems shouldn’t be phrased as a computer problem – just a generic task that can be solve with a computer program. A well known site that implements this is ProjectEuler. We found however, that the solutions quickly required math that exceeded the levels known to our students. While programming, logic, and math go hand in hand, we wanted tasks that didn’t seem like math homework – something that offered a wider variety of tasks and also something that allowed programming in-line (instead of setting up an IDE).
We eventually settled on CodeWars. This site has a growing array of ‘katas’, and the solutions are validated against unit tests. Students can solve problems in an array of languages, type and test their code in-line, validate their solutions, and they earn ‘honour’ and advance in ‘rank’ as they complete more problems of greater difficulty. Our students are definitely finding the transition from fully guided coding to solving actual problems to be a large step – however, we are seeing definite learning take place. Students are starting to be able to take the syntax they know and form it into something that produces a useful result.
Step 3 – Make a Robot Move
We don’t run our team as a class – and frankly, lectures and homework is the exact opposite of what our students want when they come to a meeting. However, programming takes a lot of effort to master. We want to get students interested enough and having enough fun that they want to learn more of it on their own. In the ideal world, our first two steps will help students get to the point where they can read and write some basic code. From here we would like to switch to writing robot code. For the most part, the code needed to operate a robot in teleop is fairly basic – setup some constants; initialize a few objects; and pass your joystick into a function to get your robot moving. In just over a dozen lines of code you can go from a blank page to a driveable robot.
We would like our students to understand this process and then, using some of our past robots, write the code needed to drive them. Hopefully over the course of a few hours we’ll be able to augment their programming knowledge with the WPILib API and get some robots moving. In addition to simply writing the code, the challenges here are also grasping the iterative structure; setting up a programming environment (we are moving from Eclipse to Visual Studio Code this year); and also understanding the connection between the code and the hardware (e.g. which motor is ID#3).
Step 4 – Write an Auto
The goal, of course, is to produce smooth movements in telop and sophisticated and consistent autos. The first auto is, of course, a drive straight. Even this simple task can take on a variety of forms. In the simplest case, you just apply power to each wheel, count a number of iterations, and turn off the motors. A little more complexity may use a time based conditional to stop the robot. Better still, we can get feedback from encoders and figure out an actual distance. From here we can set a fixed speed as well. Finally, we can use a gyroscope to see that we are actually going straight and continually correct for any turning that may be occurring.
Our hope is that by the time the holiday season rolls around, our students will have been able to write some of these autos and will be ready to take it to the next level come build season.