Help with coding errors!
Botdocter
Posts: 271
Hey guys. I wrote this code, and can't get it right. Does anyone see what i'm doing wrong? I seem to have a problem with the AF_Pin and BF_Pin.
Any help is welcome!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
Any help is welcome!
CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 PING_Pin = 16 ''PING))) I/O Pin AF_Pin = 24 BF_Pin = 26 default_speed = 40 VAR long range long aspeed long bspeed OBJ PWM : "PWM_32_v2.spin" ping : "ping" BS2 : "BS2_Functions" PUB Main | DutyCycle PWM.Start '' Initialize PWM cog. This Block Starts the PWM Object BS2.Start(31,30) repeat range := ping.Centimeters(PING_Pin) ' Get Range In Millimeters IF range > 100 range := 100 aspeed := default_speed - range bspeed := default_speed - range '' calculate the direction and speed of motor a IF range < 30 and range > 24 repeat DutyCycle from 0 to 40 PWM.Duty(AF_Pin,DutyCycle,5000) ' Ramp Duty cycle up from 0 to 100 repeat 10000 repeat 1500 ' Hold at 100% for a little bit repeat DutyCycle from 40 to 0 PWM.Duty(AF_Pin,DutyCycle,5000) ' Ramp Duty cycle down from 100 to 0 repeat 10000 repeat 1500 aspeed := 0 bspeed := 0 repeat 3000 ''-------- This Block creates a 3-Phase 60Hz square wave on Pins 1,2, and 3 ----------- PWM.Duty(AF_Pin,aspeed,16665) 'Create a 60Hz 50% duty cycle on Pin1 PWM.Duty(BF_Pin,bspeed,16665) 'Create a 60Hz 50% duty cycle on Pin2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
Comments
Or is that a way of creating a time delay?
Post Edited (ElectricAye) : 4/2/2010 2:43:09 PM GMT
i want the bot to drive forward and and when it is withing 100cm range i want the speed to go down untill 25 cm. at 25 cm i want the bot to wait for a bit, and then drive one wheel forward to turn. then it goes from the top again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
Your comment at the bottom says "Create a 60Hz 50% duty cycle on Pin1" but it looks like in your CON statement you have "AF_Pin = 24" ???
Also, are you working in centimeters or, as your comment says, "Get Range In Millimeters" ???
I doubt these are what are causing your problem, but it's just stuff that sticks out at me.
But do you have any idea to get this working?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
I'm not a coding guru, but it might help the forum if you edit and repost your code to clean up the comments, etc. The last thing anyone wants to slog through is lots of "minor" things that cloud the problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
I will change that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Post Edited (ratronic) : 4/2/2010 7:39:20 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
·http://forums.parallax.com/showthread.php?p=617192
And you must RTFM (Read The Fine Manual)
·http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf
Look up "waitcnt" in the Propeller Manual.
www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf
You can program the Propeller so that a Main program runs in a cog separately from a program inside another cog that is controlling an action but that's not what your code is showing.