1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Tronic's proportional servo motor control with basic stamp

Discussion in 'SimTools compatible interfaces' started by tronicgr, Aug 4, 2007.

  1. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    In this presentation I will try to give you an idea of the way my DC motor servo system works and how I interface it with x-sim software.

    First of all, I used a Basic Stamp2 microcontroller to read the data from the USO (serial) interface of the x-sim. And the motors are driven with the use of Parallax's HB-25 motor controllers that converts the wiper motors to big servos! To position the motors using just the HB-25 is impossible so I wrote my own servo proportional code that does the job. The servo proportional code is implemented in p-basic and the bs2 runs it along with the demanding job of receiving the motion data from the computer.

    To have feedback about the position of the motors I used special 90 degrees potentiometers (from hobby radio control unit) and ADC0831 to read them with the BS2. Then BS2 compares the motion data input with the pots feedback to calculate the speed of the motors and their direction. See sample code below:

    -----------------------------------------------------
    ...sample code...

    SetPoint = bank 'Sets the seek feedback signal pointed to the bank input value from USO.

    idx = 0 'Selects the apropriate ADC chip.
    GOSUB Read_0831 'Reads the feedback potetiometer angle.
    bankpot = adc(idx) 'Sets the feedback potetiometer angle into a variable.
    SetPoint = SetPoint MIN 35 'Provides input that is inside the limits of the feedback so to protect from overshoot outside the feedback potentionmeters limits.
    SetPoint = SetPoint MAX 220
    error = SetPoint - bankpot 'calculates the difference between the received angle and the current angle.
    p = Kp * error 'Calculates the proportional drive to the desired point.
    bankpot = p + Offset 'Converts the proportional drive values to the servo pulses range.
    bankpot = bankpot MAX 1000 'Limits the max speed that is feeded to the motors for either direction to the ones that the HB-25 can handle
    bankpot = bankpot MIN 500
    PULSOUT bankport, bankpot 'Finally pulses the HB-25 with the speed and direction we need

    ...etc

    ------------------------------------------------------

    I uploaded the firmware for the BS2 in three setting setups that each has its own level of reaction during fast motions. Kp3 is a slow setting that can protect the motors for the first tests, Kp5 is a fast enough setting that reacts fine, and Kp7 is an extreme fast setting that can rip the motor gearing if you fall in a bumpy ride.


    [​IMG]projectbs2firmware.zip (802.38 KB)


    The settings I set on USO interface are shown in the photo. Be careful to check the Hexadezimal format for the output as BS2 is read them in values from 00 to FF (0 to 255) with 127 (7F) being its center.

    [​IMG]



    And a small surprise... I decided to give the code of the old BS2 interface as open-source since I have no more time to do adjusts in the code for others. The code contains detailed comments so anyone can figure it out easily.

    [​IMG]BS2_interface_v1_1_HB25_open_source.zip (2.91 KB)





    In these photos you can take a closer look on the basic stamp2 and its connections to the external peripherals like the HB-25 motor controllers an the potentiometers. As you can see I have the ADC chips temporally placed on the breadboard of the BS2 board of education and made an extra little board with MAX232 and the serial port that reads the data from the computer. Even if the Bs2 board of education has already serial port I had to add a new one with Max232 chip as it seems that the echo, that the Bs2's serial port is producing, is causing communication errors.

    [​IMG][​IMG][​IMG]
    [​IMG][​IMG]


    A new better version of the Max232 circuit that includes etchable PCB layout is this:

    [​IMG]


    [​IMG]serial_max232_interface1_1.pdf (38.84 KB)


    To see how to use this simple connection setup look into the next schematic, that, by the way, it uses a little different ports for the ADC from the ones shown on the photo to work with the firmware.


    [​IMG]simplexsimwiringv12.pdf (104.42 KB)


    In a try to concentrate all the connections and add more features, I designed a dedicated board that connects other components too like relays to switch-on the computer PSU's from the BS2, extra ADC inputs with the use of more ADC0831, some switches and piezospeaker. I initially designed this interface board for flight sim and Portdrvr I used to read flight data was not needed any RS232 buffer. So I included in the final plans I give for x-sim the extra Max232 chip interface on the interface board too.


    [​IMG]bs2interface12_sch.pdf (54.56 KB)


    I designed and a small board that can host the Basic Stamp2 Chip from parallax and can be placed directly on top of the bigger board. The little board that hosts the Basic Stamp2 chip has also programming port and its own power source voltage regulator that can power directly the bigger interface board.

    EDIT: I repaired some issues I have seen in this old BS2 motion interface and added PCB layouts for the boards in case you want to etch them...!


    [​IMG][​IMG]


    [​IMG]bs2_base_interface13.pdf (178.87 KB)

    [​IMG]bs2_host_board_1_3.pdf (62.01 KB)





    Below are the pictures of the way I placed the 90degree potentiometers inside the casters that is the actual rotation point (pivot) for the frames of the joyrider cockpit. This way I can easily measure -45 to +45 degrees of angle position of the frames and have this as feedback to drive the motors into the desired position angle.

    [​IMG][​IMG][​IMG][​IMG][​IMG]

    Mounting the feedback potentiometer this way can leave me unlimited ways of motor mounting as I could easily use electric linear actuators instead simple car wiper motors...


    You can find more info on the simulator, in general, in these links:

    http://ptyxiouxos.net//greekbotics/user ... ronics.htm

    http://ptyxiouxos.net//greekbotics/user ... ulator.htm



    Regards, Thanos
  2. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    Thanks for publishing the assemly instructions and your code!

    Your work is a great step forward, to make X-Sim work with motor powered simulators.

    If you dont mind, you could easily make an etchable layout of the board with the max232 chip.

    I dont get it in total, still. The dedicated board, you mentioned. Is it neccessary for to drive the simulator, or is it just an additional/optional interface.


    regards
    ego
  3. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    The dedicated board is an attempt to manage all the connections to the external devices and make more permanent circuit for the ADC chips.
    So only one ribbon cable is attached to the BS2 directly to his ports...

    Its not nessasary to make it, as you can see in the photos above, all nessasary connections for the ADC chips can also made on the BS2 breadboard

    I don't have the tools to make an etchable board but I'd like to make one in the future when I finish with all the additions to it. I made this dedicated board with direct wire connections...

    [​IMG]

    Thanos
  4. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    Ok, now its clear.

    But I mentioned the other one, with the max232. If you would change it perhaps like this example, it would be imho ready for an etch layout.

    The blue lines are the edited ones.

    [​IMG]

    I have a local etch service, which etches boards for 11 euros including shipping. Well, in Germany. With drilled holes for ca. 13 euros, depending the amount of drills.

    ego
  5. RaceRay

    RaceRay Administrator Staff Member SimAxe Beta Tester

    Joined:
    Nov 8, 2006
    Messages:
    4,656
    Occupation:
    Self-employed | Web and application development
    Location:
    Hamburg, Germany
    Balance:
    23,837Coins
    Ratings:
    +1,965 / 13 / -0
    My Motion Simulator:
    2DOF, DC motor, SimAxe, SimforceGT
  6. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    Not really. How would you attach DC motors to the MK2000 alu profiles?

    @Thanos

    If you flashed your firmware on the BS2 PIC, we would not need the to purchase the board perhaps.
    I could make a similar layout like the BS2 with eagle.
    And those who cannot solder, could buy it at parallax's webshop.

    ego
  7. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    I know that you mean. For this reason I updated the schematics in the PDF with PCB design that you can print in a etchable board. It is designed in two side PCB board and It needs more redesign to convert it in single side PCB board or the afterward use of some wire bridges...

    The local etch services doesn't accept less that 10 of these boards otherwise the cost is too high.

    Thanos
  8. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Its true. If you flash the firmware on BS2 chip you can place it on a custom PCB board simular to the one I made above and have it run from there. I might try and design such a board with a socket to accept the BS2 chip on it. And maybe with an extra programming serial port to able to update the firmeware on it without having to remove the BS2 chip.

    The basic stamp2 I have is in OEM form (not the standard that parallax sells on it's site) so I'm forced to use it's whole board that has also the clock crystal and the memory chip. I have five such boards that I bought them 25 euro each, before many years now, to experiment in robotics.

    Generally it works well and its fast but I want to program a AVR in its place to see if I can do better with higher baud speeds and multiple check points of the position in each interval of data.

    Now it only checks the position everytime it refreshes the input data. But this produces no chopness in motion as the HB-25 keeps the last speed on the motors until instructed to change it.

    Thanos
  9. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    I updated the presentations schematics with PCB board printouts and fixed various issues in them. So download them again to get the latest updates.

    Also added schematic connections for simple connections without the dedicated board...

    Another cool thing is that Sirnoname fixed the delay issues the x-sim introduced and now LFS has the fastest response than ever!! (Thanks Sirnoname)

    Regards, Thanos
  10. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    Great!

    But why are these vias in your layout?
    [​IMG]

    I would like to know why the speed was slowed down and how it could be fixed.

    ego
  11. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    I just forgot to delete these vias when redesigned... They have no use...

    The delay on LFS was because of the smoothing of the profiler that existed even if you pilled all the way down the bar setting to weak. Sirnoname sended me a new version of profiler that had another tick on the bar that totaly disabled the delay of the smoothness.

    Now it runs really fast and the responce time was fallen below 20 ms. In the new version you can actually see the spikes on crashing into a wall. Now It moves the simulator even when you shifting gears!!! Cool!!

    I hope he puts it on the next release to see it for yourself.


    Today I bought a car battery to power the motors (TUDOR model TC10) with capacity of 100AH!!! This beast will be enouph to move my simulator for atleast straight 4 hours with no intermision. The salesman was so impressed by my construction that he gave me the battery for 60 euro cheaper (I paid only 100euro)!! I also bought a 10amp car battery charger to charge it when not using it...
    So be patient to connect the battery for the new videos... :)

    Regards, Thanos
  12. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    That would be really great!!!!
    I would really appreciate such a board, and would like to replicate it, as well!

    I know that the BS2 Controller Boards are affordable. But we like the DIY way. And everyone could decide for himself, if he would like to buy a ready BS or if he rather would like to build a PCB by himself.

    BTW, with how many wires are your motors connected to the controller. Two, or more?

    regards
    ego
  13. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    I'll design such a board with a standard BS2 chip socket for all to have it here. Just be patience because of lots of things I'm involving with right now.

    One of the things I'm making is a new interface based on a ATmega8535 that will receive the data on 56K and run multiple checks on the position in each data update interval. I'll still use HB-25 motor controllers to drive the motors...

    The motors are conneected with just two wires (Positive,Ground) to the HB-25 motor controllers.

    Regards, Thanos
  14. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    How can I define more axes on the USO? It seems to have available only x,y. I know I can use the second serial port in there but what about the more axes? The profiler doesn't seem to give z,yaw options.

    And when I tried to run more than once the profiler it gave me back error about opening the serial port. I guess the second profiler tries to access the already opened serial port of the fisrt profiler.

    Any suggestions? A patch maybe that defines more axis than x,y to the desired force?

    Regards, Thanos
  15. RaceRay

    RaceRay Administrator Staff Member SimAxe Beta Tester

    Joined:
    Nov 8, 2006
    Messages:
    4,656
    Occupation:
    Self-employed | Web and application development
    Location:
    Hamburg, Germany
    Balance:
    23,837Coins
    Ratings:
    +1,965 / 13 / -0
    My Motion Simulator:
    2DOF, DC motor, SimAxe, SimforceGT
    In the registry you have to generate the key DualRun in

    HKEY_LOCAL_MACHINE\Software\X-Sim\Force-Sender and set it on 1.

    Than you can start the Force-Sender twice! If you use a second control PC you can send the complete datapackages to both of them.

    So you can control 4 Achses. Ok, it´s a workaround, but it should work.

    regards
    Ray
  16. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Yes, I already tried this and had two force-senders. But the problem was on the profiler!!!

    I couldn't define more axis in the serial string: B~x~P~y~
    There are only x,y available.

    And when I tried to open a second profiler to run a second serial interface it won't open for second time and gave me the message: Error opening socket (or something).

    The way I see it, changes in the profiler are needed to be able to assign the extra available forces to more axis. i.e z-heave, z-rotate etc...

    And I prefer to use only one computer to elliminate as possible all the delay issues of the network communication...


    Regards, Thanos
  17. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Well, here you go. I made a small board that hosts the Basic Stamp2 chip and sits on top of the interface connections board. It has programming serial port and It also has power source regulator that also powers the interface connections board directly.

    I also fixed some minor design issues of the bigger board and alligned it to be ready to host on it the smaller board with the BS2 chip.


    [​IMG]BS2compatiblexsimwiringv12.pdf (210.83 KB)


    [​IMG]


    [​IMG]

    Regards, Thanos
  18. egoexpress

    egoexpress Active Member

    Joined:
    Dec 13, 2006
    Messages:
    3,839
    Location:
    Germany - Frankfurt/M
    Balance:
    421Coins
    Ratings:
    +7 / 1 / -0
    That was fast ;)

    Nice, I see support for 4 Servo Motors, adding the heave and yaw axes.
  19. RaceRay

    RaceRay Administrator Staff Member SimAxe Beta Tester

    Joined:
    Nov 8, 2006
    Messages:
    4,656
    Occupation:
    Self-employed | Web and application development
    Location:
    Hamburg, Germany
    Balance:
    23,837Coins
    Ratings:
    +1,965 / 13 / -0
    My Motion Simulator:
    2DOF, DC motor, SimAxe, SimforceGT
    Hi Thanos,

    great work for the community. Thank you :D

    regards
    Ray
  20. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Yes I also added them to be there, so when a profiler that supports more axis came out, I'll just update the firmware...

    Regards, Thanos