Society of Robots - Robot Forum
Software => Software => Topic started by: mackmelby on December 19, 2008, 04:25:26 PM
-
Hi everyone. Well, I just finished all of my finals in college and I have a project I will be doing over Christmas break. It is an invention of mine, so I will need to keep the public disclosure to a minimum. Anyway, it involves one 180 degree servo using a servo stretcher and one potentiometer to controll it. I am using the $50 robot microcontroller with the ATmega8 in this project. As shown in the diagram below, there are 5 areas in the potentiometer that need to change the servo to five different angles.
The code should do something like this:
If Potentiometer=a number between -3 and 3
Then
Servo=0 (center)
If Potentiometer=a number between 3 and 10
Then
Servo=45
If Potentiometer=a number between 10 and 45
Then
Servo=90
If Potentiometer=a number between -10 and -3
Then
Servo=-45
If Potentiometer=a number between -10 and -45
Then
Servo=-90
I know, way to make things complicated using a potentiometer, but in my project, it is very important for it to work this way.
I basicaly need to know how to code, or the trick to coding this.
I would greatly appreciate help.
Thanks.
-Mack
-
What you need to do is have your potentiometer being run into an A2D converter so your MCU can put the resistance (technically the voltage after the voltage drop) on a scale from 0 to 255. Then its simply a matter of "if (A2DPotValue >= 0 && A2DPotValue <= 51) Then [Servo=45]" or whatever.
Hope this helped at all.
-Dragon
-
Oh, thanks, I think we're getting somewhere now.
Then its simply a matter of "if (A2DPotValue >= 0 && A2DPotValue <= 51) Then [Servo=45]" or whatever.
So, I'm still a little confused. (I need to know what variables are understood by the programming language)
The variable "A2DPotValue" will be replaced by the number between 0 and 255... is that correct?
Does it have to be in a scale of 0-255, or is there a way of making that number more precise.
Now, this A2D converter thing...Is this a software program or some kind of electrical tester? Do I have to buy one?
-
the Analog to Digital(A2D) converter is a pin on your micro controller. When you run a voltage to it, it will compare that voltage to the reference voltage and assign it a value between 0-255. 0-255 is the maximum for the average MCU. If im not mistaken there are more expensive MCUs that have a higher possible value. Ill need a more experience member to confirm or deny that one.
the A2DPotValue would be a variable that you can customize the name of. So instead of "A2DPotValue" you could put "CreamCheeseBagel" if you wanted to... but would make it hard to debug your code if you forget what "CreamCheeseBagel" is suppsed to be :P
You can create your own variables whenever you want but there are also some that have to be what they are. I wont go into specific detail on that one...
How much experience do you have with Microcontrollers exactly?
-
AVRs like the Mega8 have a 10 bit ADC so you get 1024 values.
If you are new to micro controllers consider the Arduino environment for writing programs for the $50 robot controller
Kirk
-
The ATmega8 features a 10-bit successive approximation ADC. The ADC is connected
to an 8-channel Analog Multiplexer which allows eight single-ended voltage inputs constructed
from the pins of Port C. The single-ended voltage inputs refer to 0V (GND).
Note that ADC channels ADC4 and ADC5 are limited to 8-bit accuracy. Channels
ADC[3:0] and ADC[7:6] offer full 10-bit accuracy.
awesome :)
-
How much experience do you have with Microcontrollers exactly?
Ha ha, well, soldering it together; I haven't even touched the code that was written for the $50 robot. Basically, none as far as programing one. As far as programing in general, I am pretty good with HTML and some Java. But my carear choice is all about robotics so I need to learn this somehow. Thats why I'm on the forums. ;D
Kirk: I googled Arduino environment and it looks pretty simple to use. But would I still need to use Avr studio + pony prog to load the code to the mcu? Does it include a good help file that shows examples, what code does what? Anyone know?
Btw, Thanks for the input. :)
-
Well HTML doesnt really count as programming lol
You might want to play around with the $50 robot a lot before you attempt anything else. Youll learn a ton of stuff.
-
Well HTML doesnt really count as programming lol
Ha ha, yea, I know html isn't a programming language- it's just there to give an idea about my experience of coding...That's totally out of the subject here.
So, basically, what I'm getting from this is that I need more experience? I just thought this would be easy to code. I guess it would be too hard to do in 3 weeks. In that case, I think I'd do better off using google.
Thanks anyway,
-Mack
-
Well...the same thing can be done using good old-fasioned circuitry. ;) So, I think I might stick to doing that.
-
If your carear choice is "all about robotics" you will not get too far without learning programming, so you might as well jump into it. You can either build the "pony-prog" or buy an ready-built programmer. Or buy a development board that includes an programmer. Then ask here about a very simple program to read an A2D port and light an LED based on that, just to get an idea about how things work! If you're good with HTML than you're allready used to using some syntax to acheave an purpose. If you've done some Java than you're allready doing programming (also something tells me you're actually doing JavaScript, not Java).
Also please note compilers are ALOT more programmer-friendly then web-browsers. Web browsers are designed to be used by the end user so they usually hide errors and try to make the best out of whatever they need to render. On the other hand compilers are designed to be used by programmers and error messages are shown immediately, with line numbers and some indication of why there was an error. Learning the basics should be easy - and "basics" is all you need!
-
Yea, I know, I'll be looking out for some college classes that teach programming. But like I said, It needs to be done in 3 weeks. So, just today, I found a temporary solution thats based on the value of several resistors. It works well, but I think later I'll mess around with the $50 robot code and just hope nothing gets fried. :o
-
Regarding to your question about Arduino and programing, There are 3 ways to get Code from Arduino to another board.
1) Load the boot loader onto the chip and use the environment directly. A USB to serial converter is needed (thereis one on the Arduino Board.
2) use AVR Studio
3) Use PonyProg
Personally I the Arduino environment for testing and for simple to medium complex projects. (WinAVR for the others)
I use Pony Prog. I found a parallel programer on ebay. Pololu.com has a USB programer
The tricks
1) You must attempt to upload in Arduino (it will fail) in order to get the .hex file generated. Then run Pony Prog
2) edit the boards.txt file in the Arduino environment. Add a section that includes:
My board name
CPU Speed
processor type ATMega8 or 168
Yes there are LOTS of Tutorials and examples and a GREAT reference section on the Arduino site.
Many of the tutorials use what some consider to be poor C style but it is still a great place to learn.
I started out with an Arduino board and found it a god way to get some early success and build on.
Kirk