00001 #ifndef SIMPLEMOTOR_C 00002 #define SIMPLEMOTOR_C 00003 00004 #include "Component/OptionManager.H" 00005 #include "Devices/SimpleMotor.H" 00006 00007 SimpleMotor::SimpleMotor(OptionManager& mgr, 00008 const std::string& descrName, 00009 const std::string& tagName) : 00010 ModelComponent(mgr, descrName, tagName), 00011 itsSerial(new SerialAdvanced(mgr)) 00012 { 00013 addSubComponent(itsSerial); 00014 } 00015 00016 SimpleMotor::~SimpleMotor() 00017 { 00018 } 00019 00020 void SimpleMotor::setMotor(int speed) 00021 { 00022 speed = std::min(100, speed); 00023 speed = std::max(-100, speed); 00024 00025 speed += 128; 00026 00027 unsigned char buffer[1]; 00028 buffer[0] = (unsigned char) speed; 00029 00030 if(itsSerial->write(buffer, 1) < 1) 00031 itsSerial->perror(); 00032 } 00033 00034 #endif 00035