-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstractrobot.cpp
78 lines (65 loc) · 1.73 KB
/
abstractrobot.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @file abstractrobot.cpp
* @brief C++ Implementation: abstractrobot
*
* @details Holds the abstract class AbstractRobot which all the robots inherit.
*
* Copyright: See COPYING file that comes with this distribution
*
* @author Margus Ernits <[email protected]>, (C) 2008
* @author Mauno Pihelgas <[email protected]>, (C) 2010
*/
#include "abstractrobot.h"
#define MOTOR_ZERO_CMD 162
#define MOTION_CMD 300
#define THROWER_CMD 400
AbstractRobot::AbstractRobot()
{
Image & imageobject = Image::getImage();
image = & imageobject;
View & viewobject = View::getView();
view = & viewobject;
Comm & _com = Comm::getComm();
com = & _com;
com->openSerial("");
unsigned char digitalBitMaskValue=0;
}
AbstractRobot::~AbstractRobot()
{
}
int AbstractRobot::requestSensors()
{
return requestSensors(0);
}
int AbstractRobot::requestSensors(int nr)
{
return com->requestSerialMulti(44, nr);
}
int AbstractRobot::getSensorsResponse()
{
return getSensorsResponse(0);
}
int AbstractRobot::getSensorsResponse(int nr)
{
return com->serialMultiResponse(microcontrollerData, nr);
}
void AbstractRobot::setDcMotor(int motor, int speed)
{
setDcMotor(motor, speed, 0);
}
void AbstractRobot::setDcMotor(int motor, int speed, int nr)
{
if((motor<0 || motor>5) && (motor != 100 /* remote */) ) {
fprintf(stderr,"ERROR: DC motor nr %d out of range\n",motor);
return;
}
com->sendCommand(MOTOR_ZERO_CMD + motor, speed, nr);
}
void AbstractRobot::setOmni(int dirDeg, int velocityBody, int velocityAngular)
{
com->sendCommand3(MOTION_CMD, dirDeg, velocityBody, velocityAngular);
}
void AbstractRobot::setThrowerCommand(int requestedRpm, int precision)
{
com->sendCommand3(THROWER_CMD, requestedRpm, precision, 0);
}