Author Topic: newby C programming question  (Read 2865 times)

0 Members and 1 Guest are viewing this topic.

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: newby C programming question
« Reply #30 on: February 27, 2011, 05:36:45 PM »
more like just trying to get my my feet wet with functions :D   and i thought this would a good challenge

just to clarify: My code that i listed works perfectly, I just want to try to make an equivalent function.

I'll post some code shortly of my attempt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,166
  • Helpful? 111
Re: newby C programming question
« Reply #31 on: February 27, 2011, 05:52:52 PM »
This thread seems to be careering over various topics. Please consider splitting into different threads - else hard for anyone to 'Search' on.
Now seems to be to do with 'Tank steering' and may not necessarily be anything to do with WebbotLib
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: newby C programming question
« Reply #32 on: February 27, 2011, 05:54:08 PM »
ok, wrote something simple for starters.  
Code: [Select]
int findarea(int x, int y);
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
blaahahahahh long code that works
some code that determines y_final and x_final

displayGoto(&LCD,0,3);
rprintf("area   %d",findarea(x_final,y_final));
}
//--------------functions----------------------------------
int findarea(int x, int y){
return x + y;}
this simple code works. now just to get something similar that does the mixing logic

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: newby C programming question
« Reply #33 on: February 27, 2011, 06:02:45 PM »
Quote
Now seems to be to do with 'Tank steering' and may not necessarily be anything to do with WebbotLib
Quote
more like just trying to get my my feet wet with functions    and i thought this would a good challenge

it can see your point webbot and will start another thread but it still kind of relates to newby C programming questions :D

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: newby C programming question
« Reply #34 on: February 27, 2011, 08:26:23 PM »
never mind the "how to use functions question", i figured it out and got my code working; just had syntax errors :P

I have a another question which is relevant to post ;).  The "rprintf" function only prints integers.  But what if i want to print a float?  Is it possible to print decimal numbers to an LCD screen?

thnx

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: newby C programming question
« Reply #35 on: February 28, 2011, 09:53:33 AM »
My guess is that you can use the function: rprintfFloat, but I believe you will need to define
#define RPRINTF_FLOAT

before the rprintf.h file is included...

I don't think he put any support into the actual rprintf function itself to support floating point.  Personally I prefer to avoid floating point.   Instead I usually try to go to some fixed point version.  For example if I were working with displaying the current battery voltage in 10ths of a degree I would keep the value as an integer where for example the value 62 would refer to 6.2 volts.   If on my remote I wish to display this, I currently simply display it as 62 (different processor... and I was lazy), but if I wanted to display it as 6.2 I could probably do something like:
rprintf("%2d.%1d", volts/10, volts%10);

Just a thought...

Kurt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,166
  • Helpful? 111
Re: newby C programming question
« Reply #36 on: February 28, 2011, 02:25:47 PM »
My guess is that you can use the function: rprintfFloat, but I believe you will need to define
#define RPRINTF_FLOAT

before the rprintf.h file is included...
Correct

Quote
I don't think he put any support into the actual rprintf function itself to support floating point.
Not in the rprintf but the rprintfFloat uses floating point.

Quote
  Personally I prefer to avoid floating point.   Instead I usually try to go to some fixed point version.  For example if I were working with displaying the current battery voltage in 10ths of a degree I would keep the value as an integer where for example the value 62 would refer to 6.2 volts.   If on my remote I wish to display this, I currently simply display it as 62 (different processor... and I was lazy), but if I wanted to display it as 6.2 I could probably do something like:
rprintf("%2d.%1d", volts/10, volts%10);
100% agree
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: newby C programming question
« Reply #37 on: February 28, 2011, 04:44:33 PM »
thanks guys, i was displaying values in mV but thought it might be nice to displays decimals.
Code: [Select]
rprintf("%2d.%1d", degrees/100, degrees%100);on my LCD this displays "%2d.%1d" not values, however this
Code: [Select]
rprintf("%d.%d", degrees/100, degrees%100);displays the correct values.

Does rprintf not support conversion specifications? (at least i think its called that)

I also tried rprintffloat
Code: [Select]
warning: implicit declaration of function 'rprintfFloat'
I get this warning ^^^ when using the float and it displays a crazy amount of digits; any way to get rid of the warning? 

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,166
  • Helpful? 111
Re: newby C programming question
« Reply #38 on: February 28, 2011, 06:44:19 PM »
To support the 'conversion specifics' then you need to add
#define RPRINTF_COMPLEX
at the top of C code that does the rprintf.
All these '#define's may sound complex but are used to include the most efficient version of rprintf for what you are trying to do,

Also note that you should probably use:
rprintf("%2d.%02d", degrees/100, degrees%100);
So that the stuff to the right of the decimal point has leading zeroes where necessary.

The 'implicit declaration of rprintfFloat' is either becasue you haven't done a #define RPRINTF_FLOAT at the top of your code or you aren't using it with two parameters.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here