Propeller programming help for project
raleigh747
Posts: 13
Howdy all. I'm pretty new to Propeller and programing in general. I have a school project in which we have to design, build and program a robot to autonomously move around on a board and determine the heights of 20 dhow rods. The rods range from 50 mm tall to 250 mm at 10 mm and no height is used more than once (Yes, I know that means there are 21 possible heights but I am simply relaying the rules). My team and I have decided to use 40 whiskers (20 per side of our robot) to accomplish this task. 20 whiskers will be connected to a single 40 pin DIP Propeller chip and should be able to determine the heights of any rod.
Here is my current problem.
In my current code, I'm running an IF statement that checks to see if the lowest whisker has contacted the rod. Until it has, nothing is done. If the lowest whisker comes into to contact, the program checks all the whiskers above it. The code then takes the number location of the highest pin that's in contact and converts it into the corresponding height. An issue arising from this is that not all the whiskers may contact at the same time meaning a single run of the line of may not yield the right value. So, I will have the code be repeated several times to make sure that the correct height is recorded. What I can't figure out how to do is make my value an array and then take the greatest value recorded in that array as the value.
Basically, I want to record a height for a1 through a500. Then I want to take the maximum height that was recorded and assign it to a.
Here's my current code:
Eventually, I need to generate a table where I can say Location 1.4 (column and row designation) corresponds with a (my rod height)
Thanks guys for helping with posting code. That's a new one on me.
Post Edited (raleigh747) : 4/11/2010 4:12:03 PM GMT
Here is my current problem.
In my current code, I'm running an IF statement that checks to see if the lowest whisker has contacted the rod. Until it has, nothing is done. If the lowest whisker comes into to contact, the program checks all the whiskers above it. The code then takes the number location of the highest pin that's in contact and converts it into the corresponding height. An issue arising from this is that not all the whiskers may contact at the same time meaning a single run of the line of may not yield the right value. So, I will have the code be repeated several times to make sure that the correct height is recorded. What I can't figure out how to do is make my value an array and then take the greatest value recorded in that array as the value.
Basically, I want to record a height for a1 through a500. Then I want to take the maximum height that was recorded and assign it to a.
Here's my current code:
CON _clkmode = xtal1 + pll16x 'Feedback and PLL multiplier _xinfreq = 5_000_000 'External oscillator = 5 MHz sensors_start = 8 'Define lowest whisker port sensors_end = 15 'Define highest whisker port OBJ pst:"Parallax Serial Terminal" 'Start Terminal for visual output PUB WhiskerTest | a,b,c,d,e 'Title and variable defintion of a through e pst.start(9600) 'Define Terminal communication rate repeat repeat 500 'Start loop for "tree a" if ina[noparse][[/noparse]8] == 0 'If whisker on Port 8 contacts tree, begin whisker check a:= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Variable a is equal to the highest port value multipled by 10 plus 40 else 'If whisker on Port 8 does not come into contact, a:= 0 'a is 0 and do not check reamining whiskers 'Port value: Port 8 = 1, Port 15 = 8 pst.dec(a) 'Define display units of a in Terminal visual window pst.newline
Eventually, I need to generate a table where I can say Location 1.4 (column and row designation) corresponds with a (my rod height)
Thanks guys for helping with posting code. That's a new one on me.
Post Edited (raleigh747) : 4/11/2010 4:12:03 PM GMT
Comments
You can always include extra spaces after the opening square bracket to disable this interpretation.
[noparse][[/noparse] code ]
[noparse][[/noparse] / code ]
I hope that helps.
chkval := ina[noparse][[/noparse] sensor_start .. sensor_end ]
This stores the state of the input in chkval, moving bit sensor_start from ina to bit 0 of chkval ...
So chkval has a value between 2 to the power of 0 to 2 to the power of (sensor_end-sensor_start) - 1.
Now you can use a list of expected values and do a lookdown. Lookdown will return the index of chkval in the list.
The list would be:
%00000000, %00000001, %00000011, %00000111 .....
Here is a simple way to start with... Check it works and then you can simplify things.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
a:= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40)
Looks at all the inputs at once and finds the highest bit that is a 0 (because the whiskers ground the input). It then multiplies the pin number (so if 8 was the lowest pin with a 0, it would be converted to a 1) by 10 and adds 40 to get the height of the rod (for this example, it would be 50). So it currently checks all the whiskers in a single step. I'm just afraid that not all the whiskers will hit at once and the wrong height will be recorded.
@Cluso99, I was going to use a bunch of if statements until I got a little help and found the code I'm currently using. So I think they do the same thing.
@MagIO2, that looks like another way to record the height that I didn't think of. But what I need, is to define an array(i.e. a1-a500, fill it (using the repeat command or something else), and then pick out the maximum value of that array to be recorded as my height (variable "a" for table referencing).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
As you can see, I'm pretty lost...
One more thing, you probably only want to start the 500-cycle scan loop IF the lowest whisker has contact.
Post Edited (kuroneko) : 4/13/2010 3:50:23 AM GMT
Anyways, Kuroneko, I did get that code to work. I was having problems with it displaying the values in the Terminal but I figured it out.
Here's my code so far:
So basically, it sees if the pin designated as sensors_start is grounded, checks all the whiskers if it is and reports the maximum value recorded for a. Then it goes to b only if a is not 0 and repeats the process until b is finished and so on all the way to t (20 heights).
Now I need to figure out how to add a slight delay in the measuring (currently, my repeat is acting as my delay but they may cause memory problems) and build a table. I need to display a row x column positon (which I figured I could assign manually) with the correspondibng height. Then, I've got to transfer the table via bluetooth to a computer. So far, I have no idea how to do any of this. Any thoughts?
2) Spin (using the Propeller Tool) only has single subscripts. You have to calculate the subscript from row and column. If you have "rowSize" rows and "colSize" columns, you can use "x * rowSize + y" as your subscript for row "x" and column "y". You'd declare your array as having "rowSize * colSize" elements.
3) You'd use one of the Easy Bluetooth adapters for the Bluetooth serial link to your PC. There's documentation and sample code available. Once initialized, this looks just like a wired serial port between the Propeller and the PC. On the Propeller side, you can use any serial driver (there are several in the Object Exchange and FullDuplexSerial comes with the Propeller Tool). On the PC side, you'll need to write your own program or use some kind of existing serial data capture program. You could probably use PLX-DAQ or StampPlot Pro which are available under the Stamp Downloads link on the Downloads webpage on Parallax's website.
My department is supplying some bluetooth modules for use in transmitting but I am not sure which one they will have for us. Once I know, I will see what the device's manual can help me with.
As for the delay, I'm not quite follwoing your calculations Mr. Green. Are you saying that no matter what, if I divide CLKFREQ by 10, I will wait 100ms? If I'm following the Propeller manual right, when xinfreq is set to 5 MHz and my clkmode has a 16x in it, my clkfreq should be 80 MHz. So wouldn't my wait be 800 ms?
For the table, I have to display my data in a row, column table, but I know my rod location already. Essentially, We know where each rod is and simply need to associate a rod height with each location. For instance, at location 1,4 (it has to be displayed as row, column corresponding to the test field) I will measure my rod height to be 200 mm tall. So I need to display the text "1,4" in the lcoation cell and to the right the measured height which will be "a," the first height recorded by the program I posted previously.
If I have 20 rows (rowSize) and 2 columns (colSize), my first cell in the table (1,1) will have a subscript of 21 (22 for my height cell), right? So do I need to have 21 = "1,4" my rod's grid location and and have 22 = "a" my rod height? Then, how would I actually display it in table format such that "1,4" and 240 are the only values displayed in their respective cells?
I will wait 2 seconds. is each cycle always 12.5ns?
Also, I figured out how I will display my measurements. Thanks for the help guys! I will post again if I have any problems.
You might find the "I/O and Timing" section of the Propeller Education Kit Labs: Fundamentals book helpful, starting on page 49. The PDF and sample code for this book are bundled in the Propeller Tool software· v1.2.7, you can open it from the Help menu.
Best wishes for your project!
-Steph
When I set sensors_start = 0 and sensors_end = 7, run the program and ground pin 0, the PST reports a value of 50. However, if I change sensors_end = 7 to 8, run and ground pin 0, the PST reports a value of 130. If I ground both pin 0 and 8, the PST reports a value of 50. I have no idea what is going on. Any thoughts?
Note: If I set sensors_start = 8 and sensors_end = 15, run and ground pin 8, the PST reports a value of 50.
Post Edited (kuroneko) : 5/5/2010 12:18:36 AM GMT