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.

utils.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "utils.h"
  2. #define PI 3.14159265359
  3. LFRPoint::LFRPoint(/* args */) : x(0.0), y(0.0)
  4. {
  5. }
  6. LFRPoint::LFRPoint(double x, double y): x(x), y(y)
  7. {
  8. }
  9. LFRPoint::~LFRPoint()
  10. {
  11. }
  12. LFRVector::LFRVector(/* args */) : LFRPoint()
  13. {
  14. }
  15. LFRVector::LFRVector(double x, double y) : LFRPoint(x, y)
  16. {
  17. }
  18. LFRVector::LFRVector(const LFRPoint& pt) : LFRPoint(pt)
  19. {
  20. }
  21. LFRVector::~LFRVector()
  22. {
  23. }
  24. LFRLine::LFRLine(/* args */) : start(), dir()
  25. {
  26. }
  27. LFRLine::LFRLine(LFRPoint start, LFRVector dir) : start(start), dir(dir)
  28. {
  29. }
  30. LFRLine::LFRLine(LFRPoint start, LFRPoint end) : start(start)
  31. {
  32. dir = end - start;
  33. }
  34. LFRLine::~LFRLine()
  35. {
  36. }
  37. int Calcs::calcAngle(int deltaX, int deltaY){
  38. int refAngle = 0;
  39. if(deltaX > 10E-12){
  40. refAngle = (int)((atan(deltaY/deltaX) * 180.0/PI) + 0.5 - (refAngle<0)); //Here 0.5 (or -0.5) is added to round a float number to int right
  41. // convert from img coordinates to regbot coordinates
  42. refAngle = -(refAngle);
  43. if (refAngle > 90)
  44. refAngle = refAngle - 180;
  45. }else{
  46. refAngle = -90;
  47. }
  48. return refAngle;
  49. }