AM38: Intermediate Level Programming
AM38: Intermediate Level Programming
AM38: Intermediate Level Programming
Programming
Kasper Støy (
[email protected])
Class MyClass {
int *i; // member variable
int plus( int a, int b ); // method
MyClass(); // constructor
~MyClass(); // destructor
}
Class Example
In file ”MyClass.cpp”:
#include ”MyClass.h”
Int MyClass:: plus( int a, int b ) {
return( a + b );
}
MyClass::MyClass() {
i = new int;
}
MyClass::~MyClass() {
delete i;
}
Class Example
#include "MyClass.h"
public:
CPoint2D(); //constructor defined in cpp file
~CPoint2D(); //destructor defined in the cpp file
T **M; //dynamic
M = (T**)calloc(m,sizeof(T*));
for(int i=0;i<m;i++) M[i]=(T*)calloc(n,sizeof(T));
vector<vector<T> > M
(note!!!!! the space between > and >)
Robot Mini Project
Robot Mini Project
Aims
– Introduction to programming in Unix
– Introduction to the Player/Stage multi-robot
simulation tool
– Show off your powerful c++ skills
Robot Mini Project
Your task
– Program a mobile robot controller using c++
Your c++ program linked with a library
connects across the network and controls a
robot
The Pioneer Robot
Two wheels (can rotate
on the spot)
A sonar array with 16
sonars
(A laser ranger finder
sweeping -90 to 90
degrees)
We will use a simulation
of this robot
Simulation Overview
C++
Client
YOUR
Library PRG.!
int main(int argc, char *argv[]) {
PlayerClient robot("localhost", atoi(argv[1]));
Example SonarProxy sp(&robot,0,'r');
PositionProxy pp(&robot,0,'w');
int newturnrate,newspeed, i=0;
while(true) {
if(robot.Read()) exit(1);
pp.SetSpeed(newspeed,newturnrate);
}
}