PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I should be more clear

    The code in my little cars is, in fact, very little. It only deals with distance. It does not calculate rates of speed, of approach, of turn. It does not calculate angles. It does no mapping.

    Maybe my 16F887 based kit is not up to that task. I am not sure and I do not know how to find out. Maybe I could architect better in C, but it has been literally twenty five years since..... and I used to have a very extensive (corporate supplied) library.

    Suggestions?

    Ken

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    mbed is a tool for Rapid Prototyping with Microcontrollers mBed

    Microcontrollers are getting cheaper, more powerful and more flexible, but there remains a barrier to a host of new applications; someone has to build the first prototype! With mbed, we've focused on getting you there as quickly as possible.

    Huge library (check out the Handbook, Cookbook and Code pages), free IDE and C compiler. 100MHz 32-bit MCU, 512kB Flash, 64kB RAM.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  3. #3
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Smile I have been so out-of-it

    mbed is ARM = RISC. I remember RISC from my days at DEC. For my robocars I chose the Microchip 16F887 because I stumbled upon and bought the PICkit 2 bread board system. Had the PICkit board come with 0.1" centers I would probably stayed with it. Now I use the PIC stand alone and solderless protoboard.

    I am afraid to leave Microchip and associated vendors. I bought two UBW32 BITwackers then found that I could not program them with my version of PICKit 2. Also the UBW32 does not come in a 0.1" DIP package. I am also a bit confused where to go for help other than this forum.

    Maybe I can stick with PICBASIC PRO if I can teach myself more about doing simple mathematics and array structures for data storage. I surely would like subroutine calls that accept parameters and return values.

    Suggestions?

    Ken

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    MicroChip also = RISC

    I surely would like subroutine calls that accept parameters and return values.
    Just write a sub routine that will do what you want and GOSUB. Pretty much the same thing. Yes, the "C" folks will flame this. But it is true.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    The code in my little cars is, in fact, very little. It only deals with distance. It does not calculate rates of speed, of approach, of turn. It does not calculate angles. It does no mapping.

    Maybe my 16F887 based kit is not up to that task. I am not sure and I do not know how to find out. Maybe I could architect better in C, but it has been literally twenty five years since..... and I used to have a very extensive (corporate supplied) library.

    Suggestions?

    Ken
    Hello Ken.

    Sure, there are more powerful chips to use. There are also more powerful languages. But, the question is, what are you going to be doing, and do you really need to change chips, and or languages? So far, the use you have made the chip perform, is probably the equivalent of an old man walking with a walker. You have not taxed your current environment whatsoever! Sure, a lot more could be done, but I think, if it was done right, the most required might be an 18F device.

    Currently, your PIC18F887 can handle 5 million assembly instructions per second. Your hardware (servo) can handle at maximum, 50 instructions per second (pulse width control at 50 hertz, or 20ms frames). So, with every chance to change your direction, your program can perform 100,000 assembly instructions. A lot of PBP code can fit into 100,000 instructions. That can basically go through every available code location (14k program space) on the chip seven times, during the 20ms it has to make a decision.

    Seeing as you are hardly putting a dent in the 14k, shouldn't you at least try to do something more, before saying you don't think the chip can handle it?

    Let's take a look at the items you mention:
    Speed : This is relatively easy to do and will hardly take any code. Put a sensor on a wheel and away you go!

    Approach of turn: You have all the distances measured, why not use them to in your control for turning. Calculate at what point in time will you be x length to the wall, and at this time turn, instead of saying "if my measurement is less than 4 feet, etc etc. Since you are only taking front measurements every 60ms?? or so, you might well be beyond the 4 feet by the time you measure.

    Calculate angles: Cool idea. But with what sensors are you going to determine that? And how? PBP has SIN, COS, Hypotenuse and ATAN built in. Sure these are rough calculations, but I don't know that with your current sensors you will need (or be able to use) anything more advanced. Add a magnetometer http://www.sparkfun.com/products/9371 , and perhaps this could get more complex. If it does need to be more precise, there is a PBP compatible CORDIC include file to calculate SIN, COS, ATAN, Hypotenuse. See http://www.picbasic.co.uk/forum/showthread.php?t=10528 . On an 18F, you can do this 9,000 times per second while still using PBP in our program.

    As for mapping, with your current set up, I would go out on a limb, and say that is impossible with any language. To map, you need to know where you are. You will need more sensors! A GPS (and a large outdoor "track"), or magnetometer, or light sensors that find at least a reference beacon, or barcode like strips on the floor, just to figure out where it is. Lots of ways to do it, some better than others.

    So, from what you have vaguely mentioned, I see no barrier using your current chip, or using PBP. Can you be more specific about what function libraries you are talking about? What ever language you choose, you are going to have to decide how you are going to perform these functions, and what sensors you are going to use to do them.
    Last edited by ScaleRobotics; - 21st January 2011 at 17:49.
    http://www.scalerobotics.com

  6. #6
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Smile Thanks, you got me started

    I have not been planning on adding sensors. I might change the SONAR for IR. I know nothing about the details.

    For speed I was planning on dividing distance traveled by time between measurements. For angles, I agree, the SONAR's have a vague and varying pattern. Hence the 'speed' calculations may be inconsistent.

    With the hobby level car I have complete proportional control of both steering and wheel power. If I could get a PWM system that is truly 50htz (my present system is not. It was calibrated by trial and error) then I would have a great deal of flexibility - the better to speed up the car. Then a parameter passing GOSUB would be very convenient.

    Ken

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    I have not been planning on adding sensors.
    Then it sounds like PBP should be plenty powerful for your application. Only, I don't think you will be able to get into mapping, as there is no reference to where the car currently is. You could count turns, but once you miss or rather add a turn, then you are off. The only angle you could calculate, is the angle between the front location sensed, and the side position sensed in reference to being parallel with the car. You would not know whether this angle is being measured on a corner, or a straight away.

    If you want to use accurate servo, you could use some of the code already pointed out to you.

    (Ok, this one is kind of new, so no one suggested it yet)
    http://www.picbasic.co.uk/forum/cont...th-2-I-O-lines

    Back on post #336 of this thread:
    http://www.picbasic.co.uk/forum/show...1961#post91961

    Somewhere way back on this thread:
    http://www.picbasic.co.uk/forum/cont...e-Servo-Driver

    And suggested back on post #80 of this thread (though these later examples a lot better)
    http://www.picbasic.co.uk/forum/cont...-encode-decode
    http://www.scalerobotics.com

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: PBP projects for R/C models

    Hi Ken,

    HPWM is hardware based, so it keeps going while other things happen.

    Check out the manual:
    It can run continuously in the background
    while the program is executing other instructions.

    You might try trouble shooting your output signal, to see what is happening.

  9. #9
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Unhappy Yes, but................

    HPWM is a hardware command. It runs while PAUSE is pausing except (it appears) when it is the first "active" command in the code. Really. Truly. The only difference between those two snippets of code is the WHILE statement at the beginning of the one that works.

    Note: These few lines of code precede the 'main:' label. All I am trying to do is to demonstrate that the wheel controls are working before experimenting with racing. Once the program counter gets past 'main:' both versions run identically.

    Ken

  10. #10
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Smile Telling time...

    I would like to read a TIMER immediately after sending a trigger pulse to my SONARS. Then immediately reset it for the next cycle. (Which TIMER am I not using with PAUSE or HPWM.) Anybody?

    I want to calculate velocity. I plan to subtract two SONAR distance readings and divide by the time elapse between triggers. Units of distance sound travels in a millisecond (13.2 inches) divided by the number of milliseconds. (Could do no translation: Use the distance sound travels in a 4Mhz tick divided by the number of those ticks between SONAR triggers.) Could I explain that to middle school students?

    I have not been translating SONAR echo pulses to inches. Instead I learned how to translate inches into SONAR echo times. That is how I set up my distance parameters. At 1100 feet per second that is 13.2 inches per millisecond. (When measuring distance the PIC must divide by two. It is measuring time for an echo response.)

    Any simple code snippets you know of?

    Ken
    Last edited by Kenjones1935; - 21st January 2011 at 21:52. Reason: error in calculation

  11. #11
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Smile What I am trying to write is...

    I would like to use the 4 Meg counter to measure time in seconds and the SONAR responses to measure distance in inches.

    I could then set up CONstants that would be recognizable
    and measurable by middle school students with a yardstick and a watch with a second hand.

    How?

    Ken

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This displays the sonar distance in inches. Using the "ping" module from Parallex.

    Code:
    '  18F6680
        DEFINE OSC 20
        @ __CONFIG    _CONFIG1H, _OSC_HS_1H
        @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
        @ __CONFIG    _CONFIG4L, _LVP_OFF_4L
        INCLUDE "modedefs.bas"
        DEFINE LCD_DREG     PORTG
        define LCD_DBIT     0
        DEFINE LCD_RSREG    PORTE
        DEFINE LCD_RSBIT    0
        DEFINE LCD_EREG     PORTE
        DEFINE LCD_EBIT     1
        DEFINE LCD_BITS     4
        DEFINE LCD_LINES    4
        DEFINE LCD_COMMANDUS    3000
        DEFINE LCD_DATAUS   150
        PAUSE 500
        PAUSE 1000
        
        INCONSTANT  CON 890
        INDISTANCE  VAR WORD
        TIME        VAR WORD
        
        START:
        HIGH PORTB.3
        PULSOUT PORTB.3,2
        PULSIN  PORTB.3,1,TIME
        INDISTANCE = INCONSTANT ** TIME
        LCDOUT $FE,1,DEC3 INDISTANCE," INCHES" 
        PAUSE 100
        GOTO START
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Red face How do I make hex memory look digital?

    My robocars have no LEDs. They have no debugger and no break points. Using PICkit 2 I can read EEPROM. My code can write in that area using the WRITE command.

    When I have my car on blocks connected via the PICkit2 USB cable, I would like to do a READ and see in the EEPROM section some words that the code placed there while it ran represented as decimal numbers.

    hex includes the digits 0-9. Is there a library routine or a command to which I can give a WORD containing a positive hexadecimal number (for example the response from a SONAR) and it will return that number in decimal format represented with the digits 0-9 in least significant (as read by PICkit2) to the right?

    Ken

  14. #14
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: PBP projects for R/C models

    Yes, but how are you checking to see that hpwm is not working, sometimes. Are you really observing the signal itself, or just the reaction it is "supposed" to cause? You have the tools to look at the source .... why not use them?

  15. #15
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Unhappy I compile and run....

    I compile the code with the WHILE command. During the first three seconds after powering up the wheels steer and roll as expected. I then comment out the WHILE, recompile and program. For the first three seconds the car does nothing. The PAUSEs work but the HWPM commands do not.

    After the initial three seconds both programs work identically.

    Ken

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts