Skip to main content

Posts

Showing posts from January, 2013

Writing C programs

You can also write C programs with the WPI Robotics Library using a set of C functions that map on top  of the C++ classes and methods. To write C code: • You need to create .cpp (C++ files) rather than .C files because the C wrapper functions take advantage of overloaded functions. This means that there are a number of functions that have the same name, but different argument lists. This increases the compatibility with the C++ programming interfaces and will make transition to C++ much easier if you choose to do that. • Specify port and/or slot (module) numbers in most of the functions. Behind the scenes, the functions allocate C++ objects that correspond to the functions that you are using. This serves two purposes: it ensures that you are not using a particular port for two purposes accidently since the C++ underlying functions track “reservations” and makes the code very similar to previous years where the port numbers were on each call. You will find that there are

Using objects In Robotics

In the WPI Robotics Library all sensors, motors, driver station elements, and more are all objects. For the most part, objects correspond to the physical things on your robot. Objects include the code and the data that makes the thing operate. Let’s look at a Gyro. There are a bunch of operations, or methods, you can perform on a gyro: • Create the gyro object – this sets up the gyro and causes it to initialize itself • Get the current heading, or angle, from the gyro • Set the type of the gyro, i.e. its Sensitivity • Reset the current heading to zero • Delete the gyro object when you’re done using it Creating a gyro object is done like this: Gyro robotHeadingGyro(1); robotHeadingGyro is a variable that holds the Gyro object that represents a gyro module connected to analog port 1. That’s all you have to do to make an instance of a Gyro object. Note: by the way, an instance of an object is the chunk of memory that holds the data unique to that object. When you create

A simple robot program

Creating a robot program has been designed to be as simple as possible while still allowing a lot of flexibility. Here’s an example of a template that represents the simplest robot program you can create. #include "WPILib.h" class RobotDemo : public SimpleRobot { RobotDemo(void) { // put initialization code here } void Autonomous(void) { // put autonomous code here } void OperatorControl(void) { // put operator control code here } }; START_ROBOT_CLASS(RobotDemo); There are several templates that can be used as starting points for writing robot programs. This one, SimpleRobot is probably the easiest to use. Simply add code for initializing sensors and anything else you need in the constructor, code for your autonomous program in the Autonomous function, and the code for your operator control part of the program in OperatorControl. SimpleRobot is actually the name of a C++ class or object that is used as the base of this robot program called RobotDemo

What is the WPI Robotics Library

The WPI Robotics library is a set of C++ classes that interfaces to the hardware in the FRC control system and your robot. There are classes to handle sensors, motors, the driver station, and a number of other utility functions like timing and field management. The library is designed to: • Deal with all the low level interfacing to these components so you can concentrate on solving this year’s “robot problem”. This is a philosophical decision to let you focus on the higher level design of your robot rather than deal with the details of the processor and the operating system. • Understand everything at all levels by making the full source code of the library available. You can study (and modify) the algorithms used by the gyro class for oversampling and integration of the input signal or just ask the class for the current robot heading. You can work at any level. First, something about our new environment. We have about 500x more memory and 40x faster for fixed point an

Command line arguments

Programs that have minimal and/or optional inputs, command line arguments offer a great way to make programs more modular.  Command line arguments  are optional string arguments that a user can give to a program upon execution. These arguments are passed by the operating system to the program, and the program can use them as input. For example  Let’s write a short program to print the value of all the command line parameters: #include <iostream> int main(int argc, char *argv[]) {     using namespace std;     cout << "There are " << argc << " arguments:" << endl;     // Loop through each argument and print its number and value     for (int nArg=0; nArg < argc; nArg++)         cout << nArg << " " << argv[nArg] << endl;     return 0; } Now, when we invoke this program with the command line arguments “Myfile.txt” and “100″, the output will be as follows: There are 3 arguments:

Array in a Class

Here is an example #include <iostream> #include <vector> template < typename T> class MyVector : public std::vector<T> { // Bingo. You already have all the properties of a std::vector // Now suppose You want to add a new method // which prints all the members of the container. public : void printAll ( void ) { typename std::vector<T>::iterator it; for (it = this ->begin (); it != this ->end (); it++) ------- Array std::cout << *it << "\t" ; std::cout << std::endl; } }; int main ( void ) { MyVector< double > v; v.push_back (1.1); // inherited from std::vector v.push_back (2.5); // inherited from std::vector v.push_back (3.9); // inherited from std::vector v.printAll (); // you have defined it yourselves. }

C Type header File

This header declares a set of functions to classify and transform individual characters. Functions These functions take the int equivalent of one character as parameter and return an int that can either be another character or a value representing a boolean value: an int value of 0 means false, and an int value different from 0 represents true. There are two sets of functions: Character classification functions They check whether the character passed as parameter belongs to a certain category: isalnum Check if character is alphanumeric (function ) isalpha Check if character is alphabetic (function ) isblank Check if character is blank (function ) iscntrl Check if character is a control character (function ) isdigit Check if character is decimal digit (function ) isgraph Check if character has graphical representation (function ) islower Check if character is lowercase letter (function ) isprint Check if character is print

Reslt Managment Project Coding

////////////////Created By C++ PRogramming//////////////////////// #include<conio.h> #include<process.h> #include<fstream.h> #include<string.h> #include<stdio.h> #include<dos.h> // CLASS NAMED 'STUDENT' TO CALCULATE GRADE,TOTAL AND PERCANTAGE // class student { private: public: char grade(long int x,int y); long int total(int a,int b,int c,int d,int e); float percent(long int z); }; char student::grade(long int x,int y) { // FUNCTION TO CALCULATE GRADE // if((x*100/y)>74) return('A'); else { if((x*100/y)>60) return('B'); else { if((x*100/y)>33) return('C'); else return('E'); } } } long int student::total(int a,int b,int c,int d,int e) { // FUNCTION TO CALCULATE TOTAL MARKS // int t; t=(a+b+c+d+e); return (t); } float student::percent(long int z) { // FUNCTION TO CALCULATE PERCANTAGE // float p=0; p=(z*100)/500; return(p); }

Program to show string and pointer combination

////////////Program Created By C++ Programming//////////////// #include<iostream.h> #include<ctype.h> #include<conio.h> typedef char str80[80]; void main() { clrscr(); char *notes; str80 str="vR2GooD"; int L=6; notes=str; while (L>=3) { str[L]=(isupper(str[L])?tolower(str[L]):toupper(str[L])); cout<<notes<<endl; L--; notes++; getch(); }};; OUTPUT vR2Good R2Good 2GoOd gOOd