-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_forward.cc
More file actions
39 lines (29 loc) · 799 Bytes
/
simple_forward.cc
File metadata and controls
39 lines (29 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "stage.hh"
using namespace Stg;
static const double cruisespeed = 0.4;
typedef struct{
ModelPosition* pos;
int steps;
} robot_t;
int PositionUpdate( Model* mod, robot_t* robot );
extern "C" int Init( Model* mod, CtrlArgs* args ){
robot_t* robot = new robot_t;
robot->steps = 0;
robot->pos = (ModelPosition*)mod;
robot->pos->AddCallback( Model::CB_UPDATE, (model_callback_t)PositionUpdate, robot );
robot->pos->Subscribe();
robot->pos->SetXSpeed( cruisespeed );
// robot->pos->SetTurnSpeed( 0 );
puts("Finished initializing!");
return 0;
}
int PositionUpdate( Model* mod, robot_t* robot ){
if (robot->steps == 30){
puts("Stopping...");
robot->pos->SetXSpeed( 0.0 );
return 1;
}
printf( "%d\n", robot->steps );
robot->steps++;
return 0;
}