Position Controller, HELP!!! Original Wheel_controller C code to Spin conversio
rpdb
Posts: 101
I have been working on converting the original Wheel_Controller to SPIN.·
I have a personal deadline to get it done before UPEW·this weekend
I have built wheel encoders for 36 ppr at the wheels,·and just·now have installed some USDigital units for 80_000 ppr(wheel revolution)·at the motors. I currently·have 10 inch wheels driven through a 450:1 gear box, the motors are each driven by an HB25 (pwm on mode 0)
I know others might like this code to modify for thier own use, those that stray from standard, and need to optimize for thier own use and purpose.
I am at a loss,· no, stuck in qaugmire for a bit·as to continue on this code for "I cant see the forest for the trees". I need input and morale support, perhaps a blessing to forgive my cussing.
I want to keep this compatible with the orginal API.
The header would read "original code by: K. McCullough
·······························"converted to SPIN by the Propeller Community"
I am asking for help from the Prop community to get this done and bring it to the UPEW as well as the OBEX and forums, as a collabritive effort.
The spin.code I have is in the rar and·is a loose translation from C to SPIN and does not yet work.
· (the original code is .c)
I need help with the following to make PositionController.spin work:
1. to get the ISR routine running IN PositionController.spin using the values provided by the Quadrature_Encoder ie Pos[noparse][[/noparse]0/1] and Encoder.ReadDelta(0/1) instead of positionUpdate(). I was thinking maybe run this value through a moving_average object to get the average speed. I also need to make a method to pass which Pos[noparse][[/noparse]x] to look at when the positioncontroller is called.
2.Move global vars and locals to where they go.
3.write the code to pass recieve longs or byte for commands ie [noparse][[/noparse]TRVL (BYTE/LONG)]·to maintain,·or make possible·backward compatability. I will have to pass longs for Pos or travel.
4.pique the brains of the smartest people I know (Prop-Heads) and make new friends
I attach the original.c and my mess.spin
Post Edited (rpdb) : 6/23/2010 10:43:35 PM GMT
I have a personal deadline to get it done before UPEW·this weekend
I have built wheel encoders for 36 ppr at the wheels,·and just·now have installed some USDigital units for 80_000 ppr(wheel revolution)·at the motors. I currently·have 10 inch wheels driven through a 450:1 gear box, the motors are each driven by an HB25 (pwm on mode 0)
I know others might like this code to modify for thier own use, those that stray from standard, and need to optimize for thier own use and purpose.
I am at a loss,· no, stuck in qaugmire for a bit·as to continue on this code for "I cant see the forest for the trees". I need input and morale support, perhaps a blessing to forgive my cussing.
I want to keep this compatible with the orginal API.
The header would read "original code by: K. McCullough
·······························"converted to SPIN by the Propeller Community"
I am asking for help from the Prop community to get this done and bring it to the UPEW as well as the OBEX and forums, as a collabritive effort.
The spin.code I have is in the rar and·is a loose translation from C to SPIN and does not yet work.
· (the original code is .c)
I need help with the following to make PositionController.spin work:
1. to get the ISR routine running IN PositionController.spin using the values provided by the Quadrature_Encoder ie Pos[noparse][[/noparse]0/1] and Encoder.ReadDelta(0/1) instead of positionUpdate(). I was thinking maybe run this value through a moving_average object to get the average speed. I also need to make a method to pass which Pos[noparse][[/noparse]x] to look at when the positioncontroller is called.
2.Move global vars and locals to where they go.
3.write the code to pass recieve longs or byte for commands ie [noparse][[/noparse]TRVL (BYTE/LONG)]·to maintain,·or make possible·backward compatability. I will have to pass longs for Pos or travel.
4.pique the brains of the smartest people I know (Prop-Heads) and make new friends
I attach the original.c and my mess.spin
Post Edited (rpdb) : 6/23/2010 10:43:35 PM GMT
Comments
Why convert it to SPIN? I just compiled the C source under Catalina, and it comes in at 14kb 8kb ** - so even if you have to add in a custom serial comms object and a few other odds and sods, it should easily run on any Propeller. Is there more to the program that you have not shown, or is it just that one C file?
Of course, I shouldn't really pretend that just compiling it is the end of the story - the code I generated will not actually run since it is full of hardware assumptions that relate specifically to the AVR - but you presumably already know all the Prop equivalents or you wouldn't be able to translate it to SPIN.
Also, you'd probably also have to restructure the code slightly because the AVR has to use interrupts to do things that you would do much more logically with a separate cog on the Propeller (ugh! - this kind of stuff is so ugly on chips like the AVR it makes me remember why I love the Propeller so much!) - but it is all doable.
Ross.
** recompiled to exclude floating point, which I assume you don't need.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Post Edited (RossH) : 6/23/2010 9:53:28 AM GMT
Briefly looking at the code I can see that we can replace the serial port stuff with FullDuplexSerial or such.
The updatePosition function, called from two pin interrupts can be replaced with a simple Spin or PASM loop in it's own Cog.
The TIMER1_OVF routine perhaps should run in it's own Cog and the main command loop in another.
So we have 4 Cogs here: Main loop, timer tick, position sense and FDS.
There is no way Zog is mature enough to do this yet and I'm having doubts about being able to handle the 20ms timer tick in time. Although if Zog cannot do it it may be hard in Spin also.
Catalina should have no problems.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Post Edited (heater) : 6/23/2010 10:33:00 AM GMT
Mostly because the code would be open source for use on the Prop. There are C compilers for the Prop, but I don't know how they handle the conversion for interupts.
Second the AVR is running at 14Mhz and the prop at 80Mhz and the encoders I am using are going to need that. I will probably run a 6.25MHz crystal to get 100MHz.
Yes, it is doable. Did you find the PositionController.spin file in the rar? It is close but I need a little help.
Post Edited (rpdb) : 6/23/2010 10:40:22 AM GMT
Basically one can replace those pin interrupt handlers with Spin or PASM code running in a separate COG. The logic there is small so it should be simple. Perhaps you need PASM for the speed. Perhaps using waitpe/waitpne to trigger on pin changes. Anyway that COG would detect the pin changes and update some globally available HUB variables with the acquired data.
That takes care of the high speed real-time part.
The code hanging off the 20ms interrupt would probably need to run in it's own COG. We have to hope that Spin can do this in time. Don't forget Spin is interpreted.
I presume the command loop can be a bit more laid back.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
The main thing that I need help with is the position_controller.spin.
1). The original C code used interupts for each "phase A/B" quadrature encoder to increment posUpdate().
······
2). My hope is to convert to SPIN and the inputs will instead be from·Quadrature_Encoder.spin
····· to update position and average speed with the following:
·3). I am having difficulty wrapping my mind around the [noparse][[/noparse]idx_ctr]··and the [noparse][[/noparse]cntr] in the··ISR· and PosUpdate routines of·the·original C code.
4). I am·NOT trying to compile the C code with catalina etc or any other C compiler. I wish for help to re-write this to·make this run in SPIN. PositionController.spin is what I have so far as my conversion from PositionController.c.· To make the PosUpdate and ISR work in PositionController.spin, to find·the average speed and position is what I need help with.
5). I am truly grateful for any and all suggestions and help in this endevour.
Post Edited (rpdb) : 6/24/2010 9:51:37 AM GMT
·Here is the latest: