34 lines
785 B
C++
34 lines
785 B
C++
#include "Motor.h"
|
|
|
|
#include "Messages/BinaryMsg.h"
|
|
#include "Participant.h"
|
|
|
|
namespace RoboidControl {
|
|
|
|
Motor::Motor(Thing* parent) : Thing(parent) {
|
|
this->type = Type::UncontrolledMotor;
|
|
}
|
|
|
|
void Motor::SetTargetVelocity(float targetSpeed) {
|
|
if (targetSpeed != this->targetVelocity) {
|
|
this->targetVelocity = targetSpeed;
|
|
|
|
if (this->owner->networkId != 0) {
|
|
// in other word: if we are connected...
|
|
BinaryMsg* binaryMsg = new BinaryMsg(this->owner->networkId, this);
|
|
this->owner->Send(binaryMsg);
|
|
delete binaryMsg;
|
|
}
|
|
}
|
|
}
|
|
|
|
float Motor::GetTargetVelocity() {
|
|
return this->targetVelocity;
|
|
}
|
|
|
|
int Motor::GenerateBinary(char* data, unsigned char* ix) {
|
|
data[(*ix)++] = this->targetVelocity * 127.0f;
|
|
return 1;
|
|
}
|
|
|
|
} // namespace RoboidControl
|