linuxid10t

Joe Code

Sep 3rd, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1.  
  2.  
  3. static float robotspeed=0.0;//speed of the robot's movement
  4. static float robotangle=0.0;//angle of the robot's movement
  5.  
  6. //static float robotrotation=0.0;//the robot's orentiation
  7. static float robotrotationalvelocity=0.0;//change in the robot's orientation, from -1 to 1
  8.  
  9. struct {
  10. float speeds;
  11. int arrayLength;
  12. } motorSpeeds;
  13.  
  14. void setMotorSpeeds()//this assumes 4 motors placed on axes.
  15. {
  16. float vlength=robotspeed;
  17. float vangle=robotangle;
  18. // float xmovement=vlength*cosDegrees(vangle-robotrotation);
  19. // float ymovement=vlength*sinDegrees(vangle-robotrotation);
  20. float xmovement=vlength*cosDegrees(vangle);
  21. float ymovement=vlength*sinDegrees(vangle);
  22. float northValue;
  23. float southValue;
  24. float eastValue;
  25. float westValue;
  26. nxtDisplayTextLine(5, "xm=%f", xmovement);
  27. nxtDisplayTextLine(6, "ym=%f", ymovement);
  28. nxtDisplayTextLine(7, "rrv=%f", robotrotationalvelocity);
  29. northValue=xmovement-robotrotationalvelocity;
  30. motor[north]=northValue;
  31. southValue=-xmovement-robotrotationalvelocity;
  32. motor[south]=southValue;
  33. eastValue=ymovement-robotrotationalvelocity;
  34. motor[east]=eastValue;
  35. westValue=-ymovement-robotrotationalvelocity;
  36. motor[west]=westValue;
  37. nxtDisplayTextLine(1, "north = %f", northValue);
  38. nxtDisplayTextLine(2, "south = %f", southValue);
  39. nxtDisplayTextLine(3, "east = %f", eastValue);
  40. nxtDisplayTextLine(4, "west = %f", westValue);
  41. }
  42.  
  43. void getMotorSpeeds(motorSpeeds dest)//this assumes 4 motors placed on axes.
  44. {
  45. float vlength=robotspeed;
  46. float vangle=robotangle;
  47. // float xmovement=vlength*cosDegrees(vangle-robotrotation);
  48. // float ymovement=vlength*sinDegrees(vangle-robotrotation);
  49. float xmovement=vlength*cosDegrees(vangle);
  50. float ymovement=vlength*sinDegrees(vangle);
  51.  
  52. float speedValues[4];
  53. speedValues[0]=xmovement + sinDegrees(robotrotationalvelocity);
  54. speedValues[1]=-xmovement - sinDegrees(robotrotationalvelocity);
  55. speedValues[2]=ymovement + cosDegrees(robotrotationalvelocity);
  56. speedValues[3]=-ymovement - cosDegrees(robotrotationalvelocity);
  57.  
  58. dest.speeds=speedValues;
  59. dest.arrayLength=4;
  60. }
  61.  
  62. void rotateVector(float* vlength, float* vangle, float rotation)//rotates the vector given by vlength and vangle by rotation.
  63. {
  64. vangle=vangle+rotation;
  65. if(vangle>360.0)
  66. {
  67. vangle-=360;
  68. }
  69. if(vangle<-360.0)
  70. {
  71. vangle+=360;
  72. }
  73. }
  74.  
  75. void increaseVector(float* vlength1, float* vangle1, float vlength2, float vangle2)//adds vector2 to vector1 storing in vector1
  76. {
  77. float x1=vlength1*cosDegrees(vangle1);
  78. float y1=vlength1*sinDegrees(vangle1);
  79. x1+=vlength2*cosDegrees(vangle2);
  80. y1+=vlength2*sinDegrees(vangle2);
  81. //TODO: this!
  82. /* *vlength1=asin()/
  83. if()
  84. {
  85.  
  86. }
  87. *vangle1=atansin()
  88. */
  89. }
  90.  
  91. void setVelocity(int speed, float angle)
  92. {
  93. robotspeed=speed;
  94. robotangle=angle;
  95. }
  96.  
  97. void setRotationalVelocity(float turnVelocity)
  98. {
  99. robotrotationalvelocity=turnVelocity;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment