Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

control_module.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "control_module.h"
  2. ControlModule::ControlModule(){
  3. }
  4. ControlModule::ControlModule(float forwardSpeed, float rotateSpeed, float moveSideSpeed)
  5. {
  6. this->forwardSpeed = forwardSpeed;
  7. this->rotateSpeed = rotateSpeed;
  8. this->moveSideSpeed = moveSideSpeed;
  9. }
  10. ControlModule::~ControlModule()
  11. {
  12. }
  13. void ControlModule::moveForward(){
  14. for(int i = 0; i <= sizeof(motors)/sizeof(int); i++){
  15. motors[i] += forwardSpeed;
  16. }
  17. };
  18. void ControlModule::moveSide(int imageColumsMiddle, int contourColumsMiddle){
  19. float speed = moveSideSpeed * (contourColumsMiddle - imageColumsMiddle)/imageColumsMiddle;
  20. motors[0] += speed;
  21. motors[1] -= speed;
  22. motors[2] -= speed;
  23. motors[3] += speed;
  24. }
  25. void ControlModule::rotate(int angle){
  26. float speed = rotateSpeed * (angle + 90)/90;
  27. motors[0] += speed;
  28. motors[1] -= speed;
  29. motors[2] += speed;
  30. motors[3] -= speed;
  31. }
  32. void ControlModule::unit(){
  33. float max = 10E-12;
  34. for(int i = 0; i <= sizeof(motors)/sizeof(int); i++){
  35. if(motors[i] > max)
  36. max = motors[i];
  37. }
  38. for(int i = 0; i <= sizeof(motors)/sizeof(int); i++){
  39. motors[i] /= max;
  40. }
  41. }
  42. void ControlModule::calcSpeeds(int imageColumsMiddle, int contourColumsMiddle, int angle){
  43. moveForward();
  44. moveSide(imageColumsMiddle, contourColumsMiddle);
  45. rotate(angle);
  46. unit();
  47. }