Various KISS-C++ questions

30 replies [Last post]
ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

Thank you. This is a great help to me for getting stuff running for our team.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 18 weeks ago.

No problem. Hope everything works!

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

Once everything is tested I'll be sure to tell you if it does. If I'm happy enough with it I may even put it up on github.

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

Sorry for the double post, but I'm getting a new error with 4.0.5. It is compiling, but linking is failing with the following error

c:/program files (x86)/kiss platform 4.0.5/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function `main':
C:\MinGW\msys\1.0\src\mingwrtmain.c:73: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

EDIT: Are in libraries like cvBlob installed on the kovan or do I have to get them onto the robot some other way? If not how should I do blob detection?
If I want to use some external lib how can I load it onto the kovan so that it compiles in?

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 8 years 32 weeks ago.

Are you sure you have a main method? Could you post the code?

Perform a binary filter of the image in your hsv range and detect contours. Here's how it's done in libkovan: channel_p.cpp
That if statement is just to check if the low hue is greater than the high hue (with is possible with red hues). It basically shifts the entire matrix up and performs the filtering on the new range.

Now that I think about it, I don't know if I added opencv linking to user programs or not. I'll check tomorrow.

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

I am getting a new error now. I'm not sure what it means to be honest
error: Failed to extract KISS Archive.

If I want to compile programs with a custom command(for linking or something like that) would I have to ssh in and do that or is there a built-in way?

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 8 years 32 weeks ago.

Could you post your source code? Are you talking to the simulator or Link? What's the OS?

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

I'm on windows 7 and this is my source code. Sorry for it being so messy. I was just trying out an idea I had.

  1. #include <ctime>
  2. #include <cmath>
  3. #include <deque>
  4. //#include <kovan/motors.hpp>
  5.  
  6. //! \brief Runs this as a standalone program to make sure it works. Comment it out to use it in a class
  7. //! \todo Test this and remove all the crap testing code
  8. #define DEBUG_LINEFOLLOW 1
  9. #ifdef DEBUG_LINEFOLLOW //I'm moving these into the class so these defines are going away in a non-test situation
  10. //! Port the left motor is on
  11. #define LMOTOR 0
  12. //! Port the right motor is on
  13. #define RMOTOR 1
  14. //! Port the tophat sensor is on
  15. #define TOPHAT 6
  16. //! \brief How wide is the robot in ticks
  17. //! \todo implement a ticks to cm conversion routine using a single define
  18. #define WIDTH 250
  19. #else
  20. #include "Robot.h"
  21. #endif
  22. //! Where does black begin
  23. #define GRAYLOW 256
  24. //! Where does white begin
  25. #define GRAYHIGH 767
  26. //! How biased should it be to turn to the left. Can be negative
  27. #define BIAS 5
  28. //! How much should we normalize the acceleration
  29. #define NORM 3
  30. //! How many loops should it go between checks when it is not lost
  31. #define PREC 5
  32.  
  33. /**
  34.  \brief Follows a line at a set speed and for a set distance
  35.  \author Devon Richards
  36.  \date February 6, 2013
  37.  \param distance approximately how far it should follow the line
  38.  \param speed About how fast it should move
  39.  \exception std::string The line was lost
  40.  \return Whether it finished succesfully
  41.  \todo Optimize this using the ternary operator. Should be simple
  42.  
  43.  This functions does its best to follow a solid black line using an infared sensor.
  44.  It tries to go the approximate distance given to it, but this will not be very
  45.  accurate, especially for large distances or low speeds
  46.  */
  47. #ifdef DEBUG_LINEFOLLOW
  48. bool lineFollow(unsigned int distance, const unsigned short &speed)
  49. #else
  50. bool CBC::lineFollow(unsigned int distance, const unsigned short &speed)
  51. #endif
  52. {
  53. #ifdef DEBUG_LINEFOLLOW
  54. Motor lmotor(LMOTOR);
  55. Motor rmotor(RMOTOR);
  56. Analog irsens(TOPHAT);
  57. #endif
  58. int timeorig=std::time(NULL), counter=0, turn=0, tmptime=seconds() * 1000;
  59. std::deque<double> alpha(NORM);
  60. double theta, omega, timetotal=distance/speed, tmpa=0;
  61. while(seconds()-timeorig <= timetotal)//loop till the approximate distance has been traveled
  62. {
  63. if(counter%PREC==0 || turn>1)//only do the time intensive tests when needed
  64. {
  65. counter=0;
  66. if(irsens.value()>GRAYHIGH)//check if we see white
  67. {
  68. for(std::deque<double>::iterator i=alpha.begin(); i!=alpha.end() && i<alpha.end(); i++)//find an average
  69. {
  70. tmpa += *i;
  71. }
  72. alpha.pop_front();
  73. alpha.push_back(tmpa/NORM+0.25);
  74. tmpa=0;
  75. }
  76. else if(irsens.value()<GRAYLOW)//check if we see black
  77. {
  78. for(std::deque<double>::iterator i=alpha.begin(); i!=alpha.end() && i<alpha.end(); i++)//find an average
  79. {
  80. tmpa += *i;
  81. }
  82. alpha.pop_front();
  83. alpha.push_back(tmpa/NORM-0.25);
  84. tmpa=0;
  85. }
  86. else//we're in gray so we're happy
  87. {
  88. alpha.pop_front();
  89. alpha.push_back(alpha.back()-omega.back()/2);
  90. theta=0;
  91. turn=0;
  92. }
  93. omega += alpha.back();
  94. if (omega>0)//use the correct formulas
  95. {
  96. lmotor.MoveAtVelocity(speed+BIAS);
  97. rmotor.MoveAtVelocity(speed-WIDTH*tan(omega));
  98. }
  99. else//use the correct formulas
  100. {
  101. lmotor.MoveAtVelocity(speed-WIDTH*tan(-1*omega)
  102. rmotor.MoveAtVelocity(speed-BIAS);
  103. }
  104. theta += omega.back()*(seconds() * 1000-tmptime);
  105. tmptime=seconds() * 1000.0;
  106. }
  107. switch(turn)//Makes sure we aren't turning the wrong way.
  108. {
  109. case 0:
  110. if(theta > 15)
  111. {
  112. alpha.pop_front();
  113. alpha.push_back(alpha.back()*-1);
  114. turn++;
  115. }
  116. break;
  117. case 1:
  118. if(theta < -15)
  119. {
  120. alpha.pop_front();
  121. alpha.push_back(alpha.back()+2);
  122. turn++;
  123. }
  124. break;
  125. case 2:
  126. if (theta < -170)
  127. {
  128. alpha.pop_front();
  129. alpha.push_back(alpha.back()*-1);
  130. turn++;
  131. }
  132. break;
  133. case 3:
  134. if (theta > 170)
  135. {
  136. return 0;
  137. }
  138. }
  139. counter++;
  140. msleep(5);
  141. }
  142. return true;
  143. }
  144. #ifdef DEBUG_LINEFOLLOW
  145. //! \test This is just here to allow this to be compiled separately for testing purposes
  146. int main()
  147. {
  148. Motor lmotor(LMOTOR);
  149. Motor rmotor(RMOTOR);
  150. lmotor.MoveRelativePosition(100, 200);
  151. rmotor.MoveRelativePosition(500, 1000);
  152. lmotor.BlockMotorDone();
  153. return lineFollow(2000, 500);
  154. }
  155. #endif

I am trying to compile and send it to the simulator to run.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 18 weeks ago.

@ruler I fixed your embed; use < cpp > rather than < code > to avoid the weird formatting.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 7 years 20 weeks ago.

Braden any ideas?
How can I send projects to the robot and have them compile? Would I just have to ssh in and run the commands manually? In that case is make installed?