PDA

View Full Version : code conversion



saturnX
- 8th September 2005, 13:28
hi, i was wondering if it is possible to convert codes from picbasic pro to picbasic. i have a program in pro version and i only recently purchased the basic vesion... hehe couldn't afford the pro ;) anyways can anyone help me or teach me. kinda new to this and need some help from ya all...

mister_e
- 8th September 2005, 15:12
We can try if you post the code to be converted. Could be interesting...

saturnX
- 9th September 2005, 09:43
'Declare variables
x1 VAR BYTE
x2 VAR BYTE
y1 VAR BYTE 'The movement is adjusted by varying the Y1 AND Y2 numbers in each movement.
y2 VAR BYTE
lp VAR BYTE

'Declare array
b VAR BYTE [12]
Initialize array variables
b(0) = 148 'Right ankle’ (vertical)
b(1) = 121 'Right ankle’ (horizontal)
b(2) = 204 'Right knee’
b(3) = 126 'Right hip’
b(4) = 150 'Left ankle’ (vertical)
b(5) = 178 'Left ankle’ (horizontal)
b(6) = 101 'Left knee’
b(7) = 180 'Left hip’
b(8) = 0 'counter’
b(9) = 0 'counter’
b(10) = 0 'counter’
b(11) = 0 'Dummy value’



Start:
'Holding loop that holds upright position 3 seconds before moving

b(8) = b(8) + 1
GoSub servoout
IF b(8) < 180 Then GoTo start
b(8) = 0 'Reset the loop counter’
'__________________
For b(10) = 1 TO 3 'Take 3 steps forward’
'__________________
'Leg movement For one whole step
'__________________

'First movement
x1 = 0 'Servomotor 0
x2 = 4 'Servomotor 4
y1 = 129 'Tilt right ankle (horizontal)
y2 = 135 'Tilt left ankle (horizontal)
lp = 106 'Loop counter
GoSub m1
'___________________

'Second movement
x1 = 5 'Servomotor 5
x2 = 6 'Servomotor 6
y1 = 2 'Left ankle (vertical)
y2 = 70 'left knee
lp = 140 'Loop counter
GoSub m3
'___________________

'Third movement
x1 = 4 'Servomotor 4
x2 = 7 'Servomotor 7
y1 = 150 'Left ankle
y2 = 160 'Left hip
lp = 75 'Loop counter
GoSub m3
'___________________

'Fourth movement
x1 = 1 'Servomotor 1
x2 = 5 'Servomotor 5
y1 = 132 'Straighten ankle
y2 = 200 'Straighten ankle
lp = 90 'Loop counter
GoSub m3
'___________________

'Fifth movement
x1 = 6 'Servomotor 6
x2 = 0 'Servomotor 0
y1 = 85 'Left knee
y2 = 140 'Straighten ankle
lp = 96 'Loop counter
GoSub m2
'___________________


'Sixth movement
x1 = 0 'Servomotor 0
x2 = 4 'Servomotor 4
y1 = 167 'Tilt right ankle
y2 = 169 'Tilt left ankle
lp = 80 'Loop counter
GoSub m2
'___________________

'Seventh movement
x1 = 6 'Servomotor 6
x2 = 5 'Servomotor 5
y1 = 101 'Tilt knee
y2 = 178 'Tilt ankle
lp = 95 'Loop counter
GoSub m3
'___________________

'Eighth movement
x1 = 2 'Servomotor 2
x2 = 1 'Servomotor 1
y1 = 244 'Right ankle
y2 = 104 'Right knee
lp = 140 'Loop counter
GoSub m3
'___________________


'Ninth movement
x1 = 3 'Servomotor 3
x2 = 7 'Servomotor 7
y1 = 140 'Right hip
y2 = 180 'Left hip
lp = 80 'Loop counter
GoSub m2
'___________________

'Tenth movement
x1 = 1 'Servomotor 1
x2 = 2 'Servomotor 2
y1 = 121 'Right ankle
y2 = 204 'Right knee
lp = 150 'Loop counter
GoSub m3
'___________________

'Eleventh movement
x1 = 0 'Servomotor 0
x2 = 4 'Servomotor 4
y1 = 121 'Straighten right ankle
y2 = 204 'Straighten left ankle
lp = 150 'Loop counter
GoSub m1
'___________________

'Twelfth movement
x1 = 5 'Servomotor 5
x2 = 6 'Servomotor 6
y1 = 217 'Left ankle
y2 = 70 'left knee
lp = 144 'Loop counter
GoSub m3
'___________________

'Thirteenth movement
x1 = 4 'Servomotor 4
x2 = 3 'Servomotor 3
y1 = 133 'Left ankle
y2 = 126 'Right hip
lp = 66 'Loop counter
GoSub m1
'___________________

'Fourteenth movement
x1 = 6 'Servomotor 6
x2 = 5 'Servomotor 5
y1 = 101 'Left knee
y2 = 178 'Left ankle
lp = 144 'Loop counter
GoSub m3
‘___________________


'Fifteenth movement
x1 = 0 'Servomotor 0
x2 = 4 'Servomotor 4
y1 = 148 'Left knee
y2 = 150 'Left ankle
lp = 115 'Loop counter
GoSub m2
'___________________
Next b(10) 'Next Step
'___________________

Hold:
GoSub servoout
GoTo hold

‘____________________

Servoout:
'Output servomotor position(s)
PORTB = 0 'Prevent signal inversion

Right Leg
PulsOut PORTB.0, b(0) 'Send current servo 1 position out
PulsOut PORTB.1, b(1) 'Send current servo 2 position out
PulsOut PORTB.2, b(2) 'Send current servo 3 position out
PulsOut PORTB.3, b(3) 'Send current servo 4 position out

Left Leg
PulsOut PORTB.4, b(4) 'Send current servo 5 position out
PulsOut PORTB.5, b(5) 'Send current servo 6 position out
PulsOut PORTB.6, b(6) 'Send current servo 7 position out
PulsOut PORTB.7, b(7) 'Send current servo 8 position out
Pause 5 '5 milisescond delay to generate 50Hz signal
Return 'To servomotors
‘_____________________

'The delay routines
m1: '(Negative increment (s) -, -)
b(8) = b(8) + 1
IF b(9) = 2 Then m12
b(9) = b(9) + 1
GoTo m13

m12:
b(x1) = b(x1) - 1
b(x2) = b(x2) -1
b(9) = 0

m13:
IF b(x1) < y1 Then
b(x1) = y1
EndIF
IF b(x2) < y2 Then
b(x2) = y2
EndIF
GoSub servoout
IF b(8) < lp Then m1
b(x1) = y1
b(x2) = y2
b(8) = 0
b(9) = 0
Return
'______________________
M2: '(Positive increment (s) +, +)
b(8) = b(8) + 1
IF b(9) = 2 Then m22
b(9) = b(9) + 1
GoTo m23

m22:
b(x1) = b(x1) + 1
b(x2) = b(x2) + 1
b(9) = 0

m23:
IF b(x1) > y1 Then
b(x1) = y1
EndIF
IF b(x2) > y2 Then
b(x2) = y2
EndIF
GoSub servoout
IF b(8) < lp Then m2
b(x1) = y1
b(x2) = y2
b(8) = 0
b(9) = 0
Return
'______________________

M3: '(Positive-Negative increment (s) +, -)
b(8) = b(8) + 1
IF b(9) = 2 Then m32
b(9) = b(9) + 1
GoTo m33

m32:
b(x1) = b(x1) + 1
b(x2) = b(x2) -1
b(9) = 0

m33:
IF b(x1) > y1 Then
b(x1) = y1
EndIF
IF b(x2) < y2 Then
b(x2) = y2
EndIF
GoSub servoout
IF b(8) < lp Then m3
b(x1) = y1
b(x2) = y2
b(8) = 0
b(9) = 0
Return
'______________________

saturnX
- 9th September 2005, 09:46
hi mister_e.... thanks for the reply... just posted the code.. its for a walker robot that i am building wif 8 servomotors using the PIC16F84 as the brains. the problem is that when i got the book i never realised it was written for the pro version. hope you can help me. i noticed its kinda long after posting the codes... here i have attached the walker code as a txt file.

mister_e
- 9th September 2005, 16:19
well the only thing is see is to change those () for [] when using array var.

After that... can't see what else it have to be modfied.

saturnX
- 11th September 2005, 09:37
hi steve.. thanks for the update.... i forgot to update the post here but i managed to track down a copy of PICBasic Pro from a friend of mine and got him to compile the program for me. lol solves the problem and having to change the codes. Thanks anyways... oh any idea where i could find a virtual breadboard? not the one from http://www.muvium.com/ (previously virtualbreadboard.com). I came across a few versions written in java but does not have the 16F84 chip. anything that can help?

mister_e
- 11th September 2005, 09:57
Some will hate me but i assume my words 100%. I hate Virtual stuff as they never give the truth... well maybe close to but i'd and i'll never use and trust that kind of stuff. I still prefer spending time to build a real one... yeah i have that old manner to work.

SO probably ISIS, VSM, PROTEUS( i can't remind wich is wich) from Labcenter could help.. see info on the link bellow
http://www.labcenter.co.uk/

Some said it's a great tool... can't commernt on. I have it, but never tested and i'll probably never.

Sorry!

bartman
- 13th September 2005, 23:14
I'd be interested in knowing the name and author of this book. I have a book for a walking robot that uses just 3 servos. I'm interested in the 8 servo one.

Bart

saturnX
- 16th September 2005, 13:53
The book is called PIC robotics by john iovine. Am interested in your 3 motor robot. Where can i have a look at that project???

bartman
- 17th September 2005, 05:13
Thanks. I'll check into that book.

The book I bought is called "Insectronics" by Karl Williams.

Web site: http://www.thinkbotics.com/

I haven't built it yet, don't know if I ever will because I'm holding out for something with a bit more in the way of degrees of freedom.

I looked at your code here too and as much as I wouldn't genrally disagree with Mister E (who is 1000X smarter than I) I don't think you can just make a couple changes to get it to work in PicBasic. The ENDIF statement alone would grind it to a halt so you are lucky to have found someone who can compile it for you with the Pro version.

Bart

saturnX
- 19th September 2005, 18:01
haha you know what though i managed to get a copy of the pro version last minute from a friend of mine. thank goodness! saved me a lot of work. lol... thanks for the link too. will look into it later on.

Raycher
- 20th September 2005, 16:17
Hi, the code were used for a insec bot. I used the book called "Insectronics" by Karl Williams to built a six legged insec - works pretty well once one can program the chip.

Regards
r

saturnX
- 20th September 2005, 18:58
i guess i have to go get the book huh bartman... lol... thanks raycher for the post

bartman
- 20th September 2005, 20:46
I guess if you want it you'll need to buy it, yes. I don't want to sell or give mine away as it has useful information that may come in handy.

I ordered the book you mentioned from Amazon. Came to $20.00 with shipping which seemed pretty reasonable.

Bart

saturnX
- 20th September 2005, 21:15
that isn't a too bad price i guess. have fun with it when you get the book. the problem about the book is that i find the author some times forget that there are newbies to the whole PIC programming and basic robotics so some of his projects seem a little way advance. plus when i first got the book and read the first few chapters i was under the impression that the projects would be written for PICBasic Compilers along with the Pro Compilers. when i finally purchased PicBasic i couldn't compile his codes for the walking robot which were written for the pro versions. i was new then some 20 posts ago ;) Strange thing was the earlier projects before the walking robot had both basic and pro version of codes.

bartman
- 25th September 2005, 05:30
I received the book you mentioned yesterday. I guess I should have taken a better look at the code you posted. I was thinking it was for a hexapod walking robot, but it really is for a bipedal robot you are referring to.

The book I mentioned only deals with the haxapod walker so skip it if you are building a bipedal.

Bart

saturnX
- 25th September 2005, 06:26
sorry about that bartman... definately a miss communication. lols... i have this other book on hexapod walkers. first i have to go find it, lent it to a friend of a friend and has not returned it to me. will post it when i get it back. sell the book back on amazon maybe?

bartman
- 25th September 2005, 08:01
Yeah, we weren't on the same page, but that's okay. I'm still going to keep the book. Lots of useful information in it that may come in handy and I didn't spend a lot of money on it. If you get the name of that other book about the hexapod I'm interested in that too!

Bart

saturnX
- 2nd October 2005, 09:01
bartman.. not too sure if you still read this thread but just to update you.. the book that i lent to a friend of a friend... guess what that dude is not even in the country anymore and he took my book with him. but in the book that you bought there is a Hexapod Walker (Chapter 10) but its a basic one that you find on a lot of personal hobbist *there should be a spell check on the forum ;)* websites. I suppose the reason its in the book is because it was easy to build for beginners. I just bought the AMPHIBIONICS the other day. next project at hand is building the robot snake.

bartman
- 3rd October 2005, 18:17
Yes, I saw that. I am hoping to eventually find information on something with six legs and 12 servos. I know there are kits out there, but I'd like it to be more Do-It-Yourself.

Bart