Author Topic: how to make a GUI for robots?  (Read 14721 times)

0 Members and 1 Guest are viewing this topic.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #60 on: February 06, 2009, 04:19:47 AM »
Hey I was looking into the kilobytes per second thing.
Turns out with oscilloscopes you are supposed to use ksps, or kilosamples per second.
So basically count the number of datapoints collected per second and display that instead.

I haven't managed to buy my oscilloscope yet, but I'm pretty sure they're measured in MEGAsamples per seconds or GIGAsamples per seconds :) Even the USB ones are rated in the 10's of MEGA samples per second. On the other hand I just ran a google search for "ksps", looking for some values, and I found a commercial device that does DAQ logging, 10 bit, a single channel, and advertises an huge 1500 samples per second :)) - asks $170 for that. Axon + this application does WAY better for less!

Quote
And I was thinking. Can you make a button that automatically runs the bootloader exe? That way with a single click someone can automatically bootload up a DAQ .hex seamlessly. Sound yummy? :P

Yeh, that would be very easy to do. Preferably after I get my Axon so I can test stuff myself.

But I've got a few more ideas that would make our toy oscilloscope actually quite usefull in the realm of hobby robotics: A 1-bit (yep, 1 bit) "DAC" usefull for sampling servo signals: The "DAC" would be retrograded to just "D", we'd read an digital input 8 times, make an byte and send that over the serial line. This would give 80 kilosamples per second for a resolution of 12 us - enough to properly "see" the servo signal. The primary reason I wanted to buy an oscilloscope was to be able to see servo signals.

An other option would be an smart Axon application that not only sends data but also receives commands from the GUI. It would default to sending nothing and we could have a command in the GUI to select the kind of output we want from the Axon: 10bit / 8bit / 4bit / 1bit, including selection of channels. So the user might select 4 bit output from channel ADC3; The Axon would start sampling ADC3, putting together the upper 4 bits of two samples and send that over as an 8 bit byte :) A nice way to speed things up while still providing an fair amount of information.




Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #61 on: February 06, 2009, 04:57:25 AM »
Here's a dumb question: What's keeping you from setting up the Axon at 1,000,000 baud? Or at 500,000 baud? 256,000 baud? All those settings would give 0% baud error and are supported by the CP2102. They're not standard baud rates but then again on the PC side the port is virtual, the speed setting is just a convention - doesn't really matter :D I'm pretty sure it only matters on the UART side!

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #62 on: February 06, 2009, 05:54:39 AM »
Quote
Here's a dumb question: What's keeping you from setting up the Axon at 1,000,000 baud? Or at 500,000 baud? 256,000 baud? All those settings would give 0% baud error and are supported by the CP2102.
Thats a good question.

The ATmega640 datasheet says .5M and 1M, while the CP2102 datasheet, your software, and hyperterminal say 460800 and 921600. So I just went with 115200 to avoid any confusion - it was fast enough for the time anyway. Perhaps the ATmega datasheet was just rounding off?

But now looking into it, Device Manager won't let me go above 128000.

Just for the heck of it I tried to do it at 460800, and 921600, but whether I have the Axon turned on or not, your software gives an 'Unknown baud-rate.' error.

Quote
But I've got a few more ideas that would make our toy oscilloscope actually quite usefull in the realm of hobby robotics: A 1-bit (yep, 1 bit) "DAC" usefull for sampling servo signals: The "DAC" would be retrograded to just "D", we'd read an digital input 8 times, make an byte and send that over the serial line. This would give 80 kilosamples per second for a resolution of 12 us - enough to properly "see" the servo signal. The primary reason I wanted to buy an oscilloscope was to be able to see servo signals.

An other option would be an smart Axon application that not only sends data but also receives commands from the GUI. It would default to sending nothing and we could have a command in the GUI to select the kind of output we want from the Axon: 10bit / 8bit / 4bit / 1bit, including selection of channels. So the user might select 4 bit output from channel ADC3; The Axon would start sampling ADC3, putting together the upper 4 bits of two samples and send that over as an 8 bit byte Smiley A nice way to speed things up while still providing an fair amount of information.
excellent idea!

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #63 on: February 06, 2009, 06:21:13 AM »
Quote
Here's a dumb question: What's keeping you from setting up the Axon at 1,000,000 baud? Or at 500,000 baud? 256,000 baud? All those settings would give 0% baud error and are supported by the CP2102.
Thats a good question.

The ATmega640 datasheet says .5M and 1M, while the CP2102 datasheet, your software, and hyperterminal say 460800 and 921600. So I just went with 115200 to avoid any confusion - it was fast enough for the time anyway. Perhaps the ATmega datasheet was just rounding off?

But now looking into it, Device Manager won't let me go above 128000.

Just for the heck of it I tried to do it at 460800, and 921600, but whether I have the Axon turned on or not, your software gives an 'Unknown baud-rate.' error.

The CP2102 datasheet says it's getting it's baud rate from the PC side of things so the PC side configuration does matter after all. With the Bluetooth thingy I'm using I can set the baud rate from hyper-terminal and, because it's an virtual port it doesn't matter what speed I'm specifying when I'm connecting (PC-side).

When I get home from work I'll take a look into my application and try to make .256, .5 and 1 Mbit speeds available. When configuring the serial port one has to set up a datastructure that specifies the baud rate; *everyone* uses the predefined Windows constants for setting up those speeds - if Microsoft didn't list the .5 and 1 Mbit constants in the header files there's a good chance no one set them up in configuration programs. But just because a given constant doesn't exist it doesn't mean the value isn't valid! As I said, I'll make the value available so you can give it a try. When I wrote the list of available boud rates I actually copied the list of available boud rates as shown by HyperTerminal :D

P.S: I just took a look on MSDN at the given datastructure! There *is* a constat for 256,000 boud - but it's also the constant for the greatest boud rate defined! The 256,000 boud rate is not offered by most things (including my application) even those it's defined by Microsoft, yet other boud rate are offered even those they're NOT defined by Microsoft. This makes me think all 3 of .256, .5 and 1 Mbit are available and should work!

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #64 on: February 06, 2009, 01:32:06 PM »
Two things for tonight: I modified the "SoR Scope" to allow unusual boud rates: 250,000 (yep, 250,000, not 256k!), 500,000 and 1,000,000; The thing with those boud rates is that they can be reproduced exactly on 4/8/16 Mhz MCU! The other thing is that I've actually tested those boud rates on my MCU, and that's an Atmega324P running at 8Mhz. I was able to use 500,000 boud rate - with the boud rate prescaler (UBRR) = 0 and it worked!

The conclusions for tonight is that the Axon might actually go as high as 1Mboud per second! My Roving Networks RN-41 can't handle the 500,000 boud rate (it works but I'm seeing erroneous chars at times) - I'm pretty sure that's the Bluetooth thing to blame, the USB should handle that! I can't test :(

Tonight's installer is at the usual location. Hopefully over the weekend I'd be able to implement the expression evaluator so the graphic can graph centimeters inches and other things besides volts.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #65 on: February 07, 2009, 02:12:41 AM »
It worked up to 500k baud.  :)
If I did 1M baud the data came in all corrupted . . .


Also, it just occurred to me that with a simple jumper wire from a hardware PWM pin to the ADC that you can measure the PWM for debugging! What microcontroller do you know of that can graphically measure its own PWM? :P

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #66 on: February 10, 2009, 01:40:53 AM »
Over the previous weekend I managed to implement the expression evaluator but I haven't fully linked it to the graphics yet, I need to solve a few more problems. For now the expression evaluator only works on a "debug" page where you write a expression and you get to see the result in some other box :)

Anyway, now I'm facing a few problems: How do you people think I should be scaling the graphic? Right now the "Y" scale is from 0 to 5V and it's fixed, but that doesn't work for graphics that have a expression: I might have a range of 5 to 250 cm! I thought of scaling the graphic according to the absolute minimum and absolute maximum value as seen by the given sensor (ie: min and max over the entire range of recorded data). The downside of this would be that a "glitch" in the sensor would mess with the scale (imagine an IR sensor giving an 1 us 5V sample - being transformed to a 250 cm distance, where all other readings are between 5 and 10 cm - it makes the screen difficult to read). Letting the user manually change the scale would work but would be tough on the user.

Right now I'm leaning towards an automatic scaling system that would work like this:
- Start with a scale that correctly displays whatever's on screen NOW
- While the data on screen changes increase the scale if required (ie: if the data no longer fits the scale, make the scale larger); Never automatically decrease scale!
- Give the user an single button to "fit scale to data" - when the user presses this button the scale goes back to something that perfectly fits whatever data I'm seeing right now.

An other problem I'm facing: What math functions should be implemented in the expression evaluator? I was thinking of getting the list of Math functions listed by Excel under the "math" section and implement as many of them as possible; But hopefully I'd get away with less...

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #67 on: February 10, 2009, 02:25:40 AM »
I think auto-scaling is really useful, I use it on oscilloscopes all the time. A radio button could be used to let the user define which type of auto-scaling is best for him.

That being said, manual scaling should also be an option - letting the user define the min and max value. The problem with auto-scaling is that when there isn't a signal it focuses on signal noise instead.

Just be careful to not over complicate the GUI.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #68 on: February 10, 2009, 02:36:30 AM »
The GUI is allready getting bloated (in my opinion) and it's not even version 1 :(
I might resort to some ribbon-like toolbar (but not THE ribbon because that requires a licence) - just an simple paged control that groups different commands on different pages.

Quote
A radio button could be used to let the user define which type of auto-scaling is best for him.

What would be the options here?

P.S: My Axon is in Sibiu, my home town. I'll get it tomorow. It got here unusually fast!

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #69 on: February 10, 2009, 03:40:39 AM »
Perhaps put the auto-scale and manual scale stop in the drop down menu, as options or something like that?

It basically qualifies as advanced stuff, so it doesn't need to be that obvious to an ultra beginner.

Quote
What would be the options here?
perhaps it should be in the same window as manual scale . . . such as:

define min value options: scale, fixed value
define max value options: scale, fixed value

autoscale options: throughout session, just immediate window

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #70 on: February 10, 2009, 03:16:00 PM »
Progress has been slow lately, but here's an new installer at http://stoiadan.ro/sor_oscilloscope_setup.exe

Here's the news. I've got the expression evaluator working. There's a lot more work to do but it's working and it can be tested. The expression evaluator is a 100% custom job, designed from the ground up to work for the SoR Scope project. The syntax will allow for some very nice "if" statements, as well as some "case" statements - because I absolutely hate Excel's way of doing "if" :) The "runtime" bit is very fast: Expressions are first "compiled" to something that's very close to native code (give or take some virtual method calls :D ) and this makes it efficient. It also has a method of detecting math errors that will allow me to represent them on the graph with a red vertical bar (or some other way). Error processing would be done without stopping the graphing process.

To test just go to the page with the graph and enter the expression in the top box; "V" (from Value) is the "Y" before applying the expression. Don't ask me why I didn't call it "Y"... Just make sure you enter a fairly logical expression: If the expression generates runtime errors they'll slow things down enough to make the program almost freeze. This will probably be fixed. If you want to try this don't try it with simple stuff like "V/0", try it with stuff like "Power(V-128,-2)" - that would raise a library error as an exception that's why it's slow.

Here's the list of functions currently available in the script:
Ignore the function prefix and hope you'll figure out the Pascal syntax. The names should be self-explanatory. If they're not... I'm not sure I understand them all :D I just made all the functions in my Math library available to the scripting engine :D

Code: [Select]
function D1_ArcCos(const X : Double) : Double;
function D1_ArcSin(const X : Double) : Double;
function D1_Tan(const X: Double): Double;
function D1_Cotan(const X: Double): Double;
function D1_Secant(const X: Double): Double;
function D1_Cosecant(const X: Double): Double;
function D1_RadToDeg(const Radians: Double): Double;
function D1_RadToGrad(const Radians: Double): Double;
function D1_RadToCycle(const Radians: Double): Double;
function D1_DegToRad(const Degrees: Double): Double;
function D1_DegToGrad(const Degrees: Double): Double;
function D1_DegToCycle(const Degrees: Double): Double;
function D1_GradToRad(const Grads: Double): Double;
function D1_GradToDeg(const Grads: Double): Double;
function D1_GradToCycle(const Grads: Double): Double;
function D1_CycleToRad(const Cycles: Double): Double;
function D1_CycleToDeg(const Cycles: Double): Double;
function D1_CycleToGrad(const Cycles: Double): Double;
function D1_Cot(const X: Double): Double;
function D1_Sec(const X: Double): Double;
function D1_Csc(const X: Double): Double;
function D1_Cosh(const X: Double): Double;
function D1_Sinh(const X: Double): Double;
function D1_Tanh(const X: Double): Double;
function D1_CotH(const X: Double): Double;
function D1_SecH(const X: Double): Double;
function D1_CscH(const X: Double): Double;
function D1_ArcCot(const X: Double): Double;
function D1_ArcSec(const X: Double): Double;
function D1_ArcCsc(const X: Double): Double;
function D1_ArcCosh(const X: Double): Double;
function D1_ArcSinh(const X: Double): Double;
function D1_ArcTanh(const X: Double): Double;
function D1_ArcCotH(const X: Double): Double;
function D1_ArcSecH(const X: Double): Double;
function D1_ArcCscH(const X: Double): Double;
function D1_Log10(const X: Double): Double;
function D1_Log2(const X: Double): Double;
function D1_Sign(const AValue: Double): TValueSign;

function D2_ArcTan2(const Y, X: Double): Double;
function D2_Hypot(const X, Y: Double): Double;
function D2_LogN(const Base, X: Double): Double;
function D2_Power(const Base, Exponent: Double): Double;
function D2_RoundTo(const AValue, ADigit: Double): Double;

Admin, you gave me those two expressions as sample expressions:

Code: [Select]
1384.4*pow(X,-.9988)
(15*8_bit_value-180)

You'd write them as:

Code: [Select]
1384.4*power(V,-.9988)
15*V-180

The scripting engine also has access to every single "sensor" values throw the use of variables S1 to S99; Yep, I've increased the numbers of sensor to 99; By default only the first 16 get nice graphics but you can go to the expression variable and type "S75" and you'd get a graph of the 75'th value that was sent to the GUI over COM.

The nice thing is that you can graph the difference between recorded values. Example: S1-S2; Of course, you can also do: "S1-Power(S2,S3)*S4-S5"... show me an real scope that can do that :)

An other way to test the expression evaluator is to go to the "SoR Script" page and type an expression into the left side; The expression would be instantly evaluated and the result would be written to the right side. Try something like "Power(2,3)"

The other news is that the auto-scale function works, but it's not configurable.

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: how to make a GUI for robots?
« Reply #71 on: February 10, 2009, 05:21:17 PM »
Is there a way I can communicate to the scope through printf in other programs besides the DAQs.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #72 on: February 11, 2009, 12:16:39 AM »
Yes there is: Just send whatever value you want to send in decimal notation (ie: human-readable, not hex or other encoding) followed by end line. The SoR Scope will accept from 1 to 99 values on the same line, and you'll get graphics for the first 16 values.

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: how to make a GUI for robots?
« Reply #73 on: February 11, 2009, 12:02:48 PM »
Would something like this work?
Code: [Select]
rprintf("%d, %d%d, %d%d, %d%d",sharp_ir, scan_angle, wheel_left, wheel_right);

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #74 on: February 12, 2009, 12:26:37 AM »
The values are supposed to be separated by space, no commas; Also you've doubled the "%d"'s for some reason, I assume that was just a typo. I'm not sure if the "rprintf" functions prints an newline char after the text, most likely not. Try one of this two, one will work:

Code: [Select]
rprintf("%d %d %d %d\n",sharp_ir, scan_angle, wheel_left, wheel_right);

or

Code: [Select]
rprintf("%d %d %d %d",sharp_ir, scan_angle, wheel_left, wheel_right);

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #75 on: February 12, 2009, 12:51:28 AM »
I think he doubled the %d because he is doing long ints.

Jdog, are you just trying to graph the values you send to a servo? I think this would be better:

Code: [Select]
int angle_left;
angle_left=convert_to_angle(wheel_left);

rprintf("%d %d %d %d\n",sharp_ir, scan_angle, angle_left, wheel_right);

you get the idea . . .

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: how to make a GUI for robots?
« Reply #76 on: February 12, 2009, 08:12:14 AM »
Thanks, I got it now. Although I don't see why you converted wheel_left to angle_left.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #77 on: February 12, 2009, 10:51:13 AM »
Thanks, I got it now. Although I don't see why you converted wheel_left to angle_left.
wheel_left is a long int value, such as 637.

angle_left is an int, some value below 255.

To my knowledge, for now, the SoR Scope can only take in int values.

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: how to make a GUI for robots?
« Reply #78 on: February 12, 2009, 10:53:23 AM »
Then why didn't you convert wheel_right to an int as well?

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #79 on: February 12, 2009, 11:03:55 AM »
Then why didn't you convert wheel_right to an int as well?
too lazy :P

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #80 on: February 12, 2009, 11:09:01 AM »
The SoR scope accepts unsigned integer numbers, that is 0 to whatever.
Internally it stores the values as double precision floating numbers, so I should update the parser to allow negative numbers and to handle floating points (the "." thingy). Maybe I'll make the time tonight. I'm really curios how fast the Axon's DAQ is: I haven't had the time to take it out of it's envelope  ::)

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #81 on: February 12, 2009, 01:37:23 PM »
I updated the parser; It now accepts any numbers, positive or negative, integer or floating point.

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #82 on: February 12, 2009, 08:37:43 PM »
Quote
I'm really curios how fast the Axon's DAQ is: I haven't had the time to take it out of it's envelope

Oh I forgot . . . I attempted to get it to read it's own PWM using the original DAQ program . . . waaaay to slow, see image.

But I can probably get it to work if I wrote the DAQ carefully enough, just haven't gotten around to it yet.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #83 on: February 12, 2009, 11:53:49 PM »
I'll be working on an axon_scope.hex :D this weekend; Last night I did manage to take the Axon out of it's envelope and I did some experiments; Sending out constant data to the USB port (ie: rprinf("1 2 3\n");) I got precisely 53.4 kilobytes per second (as shown by the SoR Scope). Next I modified the super-simple loop to read a value from the ADC and then rprint-it to the USART - data rate dropped to just 17 kilobytes - and those kilobytes aren't kilo samples because the data is sent in decimal notation and there's an line terminator in there (probably 4 bytes per sample average).

What I'll attempt to do over the following weekend is to make the axon application talk to the PC application (as in bidirectional talk, not just send data), and make the sampling/sending configurable (10/8/4/1 bit per sensor, configurable number of sensors). I'll also attempt making the USART send overlap the ADC sample, to keep the USART saturated most of the time.

Theoretically the 53.4 kilobytes per second should directly translate to 53.4 kilo samples per second, one sensor, 8 bit precision: that gives 18us time base, enough to see the PWM signal!

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #84 on: February 13, 2009, 12:22:34 AM »
Quote
Sending out constant data to the USB port (ie: rprinf("1 2 3\n")Wink I got precisely 53.4 kilobytes per second (as shown by the SoR Scope). Next I modified the super-simple loop to read a value from the ADC and then rprint-it to the USART - data rate dropped to just 17 kilobytes
wow I didn't realize the ADC affected the transmission that much . . .

Another solution - don't use the ADC for reading PWM, use a digital pin instead.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #85 on: February 13, 2009, 12:48:28 AM »
Quote
Another solution - don't use the ADC for reading PWM, use a digital pin instead.

That's what "1 bit" mode will do: sample a single digital pin 8 times, make a byte and send that over; Timing would be crucial, ideally the time between the 8 samples should be just right so the 8 bits are produced in the amount of time it takes the USART to send the previous byte. That way we'd get an maximum of 424 kilo samples per second! And that's one thing I'm 100% sure of: I can get 424 kilo samples out of an digital pin because there's no ADC to slow things down.

Do you, by any chance, know how I can make the ADC faster if I only want 8 bit or 4 bit precision? (I'm lazy, I'm sure it's in the datasheet!). Is there a configuration option for this or do I simply read ADCH when I feel it's time to read it? Do I tweak the ADC clock?

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #86 on: February 13, 2009, 01:08:32 AM »
Quote
Do you, by any chance, know how I can make the ADC faster if I only want 8 bit or 4 bit precision? (I'm lazy, I'm sure it's in the datasheet!). Is there a configuration option for this or do I simply read ADCH when I feel it's time to read it? Do I tweak the ADC clock?

This is what I did. Basically the scaling defines how many clock cycles are used to get an ADC reading. However fewer cycles you use, the more inaccurate it gets (because its charging up internal capacitors). The original DAQ uses DIV32, but the faster version uses DIV4.

Code: [Select]
void axon_DAQ_fast(void)
{
int a9;

//select speed/accuracy of data conversion
a2dSetPrescaler(ADC_PRESCALE_DIV4); // configure ADC scaling

while(1)
{
//gather data
a9=a2dConvert8bit(9);

//report data, add time stamp and overflow count at end of data
rprintf("%d\r\n",a9);
//uart2SendByte(m2);//even faster, but doesn't have carriage return
}
}

And some notes from AVRlib:
Quote
   //select speed/accuracy of data conversion
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling, 32 default

   // A2D clock prescaler select
   //      *selects how much the CPU clock frequency is divided
   //      to create the A2D clock frequency
   //      *lower division ratios make conversion go faster
   //      *higher division ratios make conversions more accurate
   // ADC_PRESCALE_DIV2       -> CPU clk/2
   // ADC_PRESCALE_DIV4        -> CPU clk/4
   // ADC_PRESCALE_DIV8        -> CPU clk/8
   // ADC_PRESCALE_DIV16      -> CPU clk/16
   // ADC_PRESCALE_DIV32      -> CPU clk/32
   // ADC_PRESCALE_DIV64      -> CPU clk/64
   // ADC_PRESCALE_DIV128      -> CPU clk/128

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: how to make a GUI for robots?
« Reply #87 on: February 15, 2009, 04:59:24 AM »
Here's a new version of SoR Scope. New stuff:
(1) Made it use the "performance counter" for a time base. The performance counter is directly related to the PC's CPU speed, very accurate, but may give strange result on SMP processors and on computers with ACPI that happen to change CPU frequency to save power.
(2) Made it accept two more encodings for the input stream: "binary-8bit" and "binary-4bit". There's an radio button for "binary-2bit" but it doesn't work right now.

Using the "binary-4bit" encoding, an Axon, a Atmega324 board and an two wire jumper cable that links the ground on the two boards and moves the servo signal output from the Atmega324 to an analog input on the Axon. I got the image in the attachment. The servo signal can be seen fairly well, but I'm afraid I can't do better without buying an actual oscilloscope to test that data! In the picture the graphed time base is 1/100 seconds, so the thick numbered vertical lines are for 1/100 seconds, that's 10 ms; The thin lines are each 1 ms. You can see the high signal being around 1.5ms - that's about what I was sending from the Atmega324.

Here's the code I used on the Axon (control.c):
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 www.societyofrobots.com
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
****************************************************************************/

void read8bit(void)
{

//uartSetBaudRate(1, 500000);
outb(UBRR1L, 1);
outb(UBRR1H, 0);

a2dSetPrescaler(ADC_PRESCALE_DIV16); // Set the ADC prescale so we get fast conversions

// Prepare ADC to convert from port "1" - sorry by this, that's where my inter-mcu cable lands,
    ADCSRB &= ~_BV(MUX5);
    outb(ADMUX, (inb(ADMUX) & ~7) | (1 & 7));   // the (1 & 7) part selects the port, change the 1 to something else (between 0 and 7 that is!)
sbi(ADCSR, ADIF);
sbi(ADCSR, ADSC);
while( bit_is_set(ADCSR, ADSC) );

// Send an start byte

uartSendByte(1,0);

// ADC result
volatile unsigned char ADCR;

while (1)
{
while( bit_is_set(ADCSR, ADSC) ); // wait until previous conversion completes
ADCR = ADC >> 2;
// Start next conversion
sbi(ADCSR, ADIF);
sbi(ADCSR, ADSC);

while(!(UCSR1A & (1<<UDRE1))); // wait until previous byte got sent
outb(UDR1, ADCR);
}
}

void read4bit(void)
{

//uartSetBaudRate(1, 500000);
outb(UBRR1L, 1);
outb(UBRR1H, 0);

a2dSetPrescaler(ADC_PRESCALE_DIV8); // Set the ADC prescale so we get fast conversions

// Prepare ADC to convert from port "1" - sorry by this, that's where my inter-mcu cable lands,
    ADCSRB &= ~_BV(MUX5);
    outb(ADMUX, (inb(ADMUX) & ~7) | (1 & 7));   // the (1 & 7) part selects the port, change the 1 to something else (between 0 and 7 that is!)
sbi(ADCSR, ADIF);
sbi(ADCSR, ADSC);
while( bit_is_set(ADCSR, ADSC) );

// Send an start byte

uartSendByte(1,0);

// ADC result
volatile unsigned char ADCR_1;
volatile unsigned char ADCR_2;

while (1)
{
while( bit_is_set(ADCSR, ADSC) ); // wait until previous conversion completes
ADCR_1 = ADC >> 2;
// Start next conversion
sbi(ADCSR, ADIF);
sbi(ADCSR, ADSC);
while( bit_is_set(ADCSR, ADSC) ); // wait until previous conversion completes
ADCR_2 = ADC >> 2;

ADCR_1 = (ADCR_1 & 0b11110000) | (ADCR_2 >> 4);

while(!(UCSR1A & (1<<UDRE1))); // wait until previous byte got sent
outb(UDR1, ADCR_1);
}
}

void control(void)
{
read4bit();
}

Here's the image:

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #88 on: February 15, 2009, 07:23:21 AM »
Nice!

I think this is good enough resolution for testing servo PWM. :)

Offline AdminTopic starter

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: how to make a GUI for robots?
« Reply #89 on: February 19, 2009, 03:49:55 AM »
RoboRealm now has a GUI that communicates directly with the Axon to control servos from your PC:

http://www.societyofrobots.com/robotforum/index.php?topic=7041.0



edit: fixed link
« Last Edit: February 19, 2009, 04:25:07 AM by Admin »

 


Get Your Ad Here