you want to software?
we can help you software.
Below is a list of useful programming functions that you should learn to efficiently employ often. Keep in mind that in programming, there are a lot more ways to accomplish a task, and these functions are simply the first step. If you want to look further, LEGO provides extensive video and written tutorials for the coding beginner, and there are plenty of forums online that you can research.
in general
programming_for_rookies.pptx | |
File Size: | 365 kb |
File Type: | pptx |
demoprogram.c | |
File Size: | 4 kb |
File Type: | c |
FTC allows two different languages: LabView and RobotC. By far, RobotC is much more popular because of its familiar syntax mime with C. For example, there are the basic functions of while loops, if decisions, and for loops, just to name a few. This is a great language if you are already familiar with C programming.
We developed the PowerPoint Presentation and C file attached above to help teach RobotC programming. The presentation slides explain many of the basics of RobotC programming, and the C file provides fully commented examples of the concepts explained in the slides.
Other Tips:
A helpful tip is to utilize a helper function file. This will make your autonomous file much easier to write. Make the .h file, and then use #include to access those function within your other programs, so you don't need to needlessly copy over code.
We developed the PowerPoint Presentation and C file attached above to help teach RobotC programming. The presentation slides explain many of the basics of RobotC programming, and the C file provides fully commented examples of the concepts explained in the slides.
Other Tips:
A helpful tip is to utilize a helper function file. This will make your autonomous file much easier to write. Make the .h file, and then use #include to access those function within your other programs, so you don't need to needlessly copy over code.
loops
Loops are used whenever you want a computer or robot to execute a list of commands an infinite number of times until a certain goal is reached. There are many different kinds, and we will only briefly go over the most simplest of loops on this page.
while loops
This is usually associated with the function endtimeslice. It is an important combination if you wish to track encoder values that you put on motors. Example:
For example:
while (RightEncoder < encoderDistance)
{
EndTimeSlice();
}
This is used in our function that moves the wheels. It waits until the right encoder rotates enough.
For example:
while (RightEncoder < encoderDistance)
{
EndTimeSlice();
}
This is used in our function that moves the wheels. It waits until the right encoder rotates enough.
if/else loops
The if/else loop is used when one needs to choose one of two options. Most of the time, if/else loops have to deal with sensors.
If you want to pick from one of more than two options, simply include an "else if" bracket.
For example:
if (motorSide == 0)
{
motor[leftWheel] = speed;
}
else if (motorSide == 1)
{
motor[rightWheel] = speed;
}
else
{
motor[leftWheel] = speed;
motor[rightWheel] = speed;
}
If you want to pick from one of more than two options, simply include an "else if" bracket.
For example:
if (motorSide == 0)
{
motor[leftWheel] = speed;
}
else if (motorSide == 1)
{
motor[rightWheel] = speed;
}
else
{
motor[leftWheel] = speed;
motor[rightWheel] = speed;
}
sensors
Ultrasonic sensor
The ultrasonic sensor can be used to detect the distance your robot is away from other objects. This can be used within movement programs to stop if an opponents robot gets too close. The value on the ultrasonic can be set to different kinds of units to detect the distance from your sensor. Keep in mind that the ultrasonic sensor should not be used for measurements that must be within 5 cm, as it is not that accurate.
infrared (IR) sensor
An extremely common sensor in the FTC tournament, as every year, the autonomous challenge will almost always include some form of infrared beacon, which sends infrared signals from a specified location that your robot can pick up. The IR sensor is crucial when maximizing the number of autonomous points a robot can score. By using this effectively, one can ensure that the robot will travel, and subsequently score, in the correct basket.
The IR sensor works on a "clock" system. For example, 12:00 is straight ahead because it corresponds to the "up" direction on a clock dial, and 3:00 points to the right. Similarly, a value of 5 from the IR sensor indicates that the beacon is straight ahead. Anything less than 5 indicates direction is to the left, and anything greater than 5 indicates direction is to the right.
The IR sensor works on a "clock" system. For example, 12:00 is straight ahead because it corresponds to the "up" direction on a clock dial, and 3:00 points to the right. Similarly, a value of 5 from the IR sensor indicates that the beacon is straight ahead. Anything less than 5 indicates direction is to the left, and anything greater than 5 indicates direction is to the right.