1. 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!
  2. 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
  3. 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

4Dof-Controller code for arduino mega for AASD-15A and similar driver

Discussion in 'SimTools compatible interfaces' started by cubexxx, Mar 19, 2020.

  1. robjos1

    robjos1 Member

    Joined:
    Jun 17, 2018
    Messages:
    49
    Occupation:
    Flying about
    Location:
    United Kingdom
    Balance:
    308Coins
    Ratings:
    +38 / 0 / -0
    My Motion Simulator:
    6DOF
    Would this code be adaptable to a 6DOF Setup?
  2. cfischer

    cfischer Active Member Gold Contributor

    Joined:
    Sep 7, 2015
    Messages:
    284
    Location:
    Colorado
    Balance:
    2,006Coins
    Ratings:
    +199 / 0 / -0
    Just use two arduinos. No need to adapt anything.
  3. Trigen

    Trigen Active Member

    Joined:
    Nov 25, 2018
    Messages:
    483
    Balance:
    3,056Coins
    Ratings:
    +177 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino
    Ive really only had that issue if there's a massive surge but never any random DC when everything is grounded. Still getting that issue with it getting a random or just starting the wrong way until i reset and cycle it twice in mover. Ive broken cast motor mounts due to that. Since i cant figure it out and cant afford the 400 euro for the Thanos controller ive added washers to my G seat arms so they will slip if there's to much load. Id love to figure out why one earth its doing that though.

    An extra layer doesn't hurt though.

    20210801_092641.jpg
  4. cubexxx

    cubexxx Member

    Joined:
    Oct 4, 2019
    Messages:
    67
    Balance:
    473Coins
    Ratings:
    +35 / 0 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF
    Not quite sure what you mean by "cycle twice in mover". Generally I'd advise to disconnect the usb and the driver power after a computer reboot or any crash/exception, then assure that the actuators are in the "zero" state, then connect the mega (usb), then turn driver power on, then (re)start mover and click "connect" in the output module. Also I've configured the display of my aasd drivers to show the position (default is speed). Now this will show zero at startup and this should not change until you connect in mover. Also if you disconnect in mover it should go back to zero (+/- one "count" (Pn 98) because mover can be one count off)
  5. Trigen

    Trigen Active Member

    Joined:
    Nov 25, 2018
    Messages:
    483
    Balance:
    3,056Coins
    Ratings:
    +177 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino
    Appreciate the tip. Ill have a look into that.

    By cycle i mean to keep the enable off on the rig. Then turn everything on and let it connect, then disconnect and do that one more time. Then its usually fine. But if i dont cycle it it will do this and sometimes even then. And i always reset the mega and drivers after i reboot the computer. Which is quite strange. Hopefully setting the drivers to show position can help me see whats going on
    Last edited: Aug 2, 2021
  6. Trigen

    Trigen Active Member

    Joined:
    Nov 25, 2018
    Messages:
    483
    Balance:
    3,056Coins
    Ratings:
    +177 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino
    This happens without fail if i dont cycle move connections on and off no matter if i disconnect or reset drivers and the mega.
  7. cubexxx

    cubexxx Member

    Joined:
    Oct 4, 2019
    Messages:
    67
    Balance:
    473Coins
    Ratings:
    +35 / 0 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF
    So I guess you set the display to show position and the 3 drivers on the right are used for 3dof. The "-9999" I'd say is the one count that mover can be off and that's neglectable in my opinion. The 2 drivers on the left don't look right, how are they used? Do you use 2 megas?
  8. Trigen

    Trigen Active Member

    Joined:
    Nov 25, 2018
    Messages:
    483
    Balance:
    3,056Coins
    Ratings:
    +177 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino
    Hello. Appreciate the quick response. I use two mega with the same sketch. One (the two gseat flaps) is driven by directs in Mover and the other on a 3dof rig.

    All drivers will do the same but the 3dof actuators sit at 0mm and cannot move further down so they will be stuck at -9999 but you can hear them trying to move. The other two runs two G seat flaps and move a lever which will move until they slam into the hard stop (as you can hear on the video) and then the driver drop to 0 so i believe the behavior to be the exact same for all drivers.

    So while the one count (if its that) may be neglectable its clearly trying to send everything to -9999. So then the question is, besides cycling the connect in Mover, could something else be done in the sketch or does Mover need to be reprogrammed?
    Last edited: Aug 3, 2021
  9. gzresident

    gzresident New Member

    Joined:
    Feb 4, 2018
    Messages:
    10
    Location:
    China
    Balance:
    - 38Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    thanks for the share.
    I wrote a 6axis6actuator code, in mege2560 too, but just set port up and down to generate pulse,very slow.
    want to learn from you, CTC and interrupt, but seems one timer interrupt just can control one output pin, don't know how to set up 1 timer two interrupt two output pin.
  10. KingPommes

    KingPommes New Member

    Joined:
    Nov 7, 2018
    Messages:
    9
    Balance:
    84Coins
    Ratings:
    +8 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Your code works fine so far. The Arduino behaved strangely, however. After connecting the USB cable, the motors do not respond to input signals. If the controller is reset after connecting the USB cable, everything works. Do you have any idea why that could be?
  11. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    300
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,238Coins
    Ratings:
    +177 / 2 / -0
    My Motion Simulator:
    2DOF
    Hi ! I am trying to use a AASD driver with an arduino Uno, and I can't rotate the motor (the test though FN002 works). The code is simple, I repeat :

    digitalWrite(StepPin1, HIGH);
    delay(10);
    digitalWrite(StepPin1, LOW);
    delay(10);

    The wiring is the following
    DB connector :
    3 pulse
    4 dir
    5, 6, 10, 14 GND
    9 5V

    And it doesn't move at all... Any idea @cubexxx ?
    By the way I used your idea about inverting the linear bearing for my SRT100 actuators (stepper based actuators), great idea !
    [​IMG]

    Without touching the motor, I have :
    SigOUT1 (Servo ready) =0
    SigOUT2 (Alarm detection) =0
    SigOUT3 (Positioningcomplete)=0
    SigOUT4 (Zero spee)=1
    When I turn the shaft, sigout3=1.
    Is it normal ?

    Attached Files:

    Last edited: Nov 4, 2021
  12. cubexxx

    cubexxx Member

    Joined:
    Oct 4, 2019
    Messages:
    67
    Balance:
    473Coins
    Ratings:
    +35 / 0 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF
    Code looks ok. Maybe something wrong with the "enable"? You can set it to be permanently "on" with aasd param Pn003. And while the "digitalWrite/delay" approach should work in principle, it's not very suited for good motion because these methods are too slow and don't have timing that is exact enough, that's why I used timers and registers to set the output pins directly. Bet these are dependent on the type of arduino, so different for uno and mega.
  13. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    300
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,238Coins
    Ratings:
    +177 / 2 / -0
    My Motion Simulator:
    2DOF
    thanks a lot for your reply ! I checked PN003, it is on 1. When I try Jog0, it shows error when I press the button...
    Yes I just used digitalWrite to have a very basic code. For the SRT100, I am using the port manipulation, it is already far better.
    I rode your code a little bit, and it is far more advance than mine. I don't know if it does a difference in the end, I must study it.
    If you want to take a look at mine.

    I mounted the seat mover today with a stepper motor. It works but the motor itself isn't suited... I have to debug the servo :/
    [​IMG]

    EDIT : with PN003 at 0, JOG0 works.
    EDIT : it seems to work !
    Last edited: Nov 5, 2021
  14. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    300
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,238Coins
    Ratings:
    +177 / 2 / -0
    My Motion Simulator:
    2DOF
    @cubexxx

    1) why don't you use higher baudrate in your code ? I use 921600.

    2)Serial.read() << 8 | Serial.read()
    How does it work ? the Serial.read on the left read the first byte available and the serial.read on the right read the second one ? We are sure that we are not reading two times the same byte ?

    I know that the "<<8" is equivalent to "*256".

    3) Is it really faster than :
    buffer = Serial.read();
    commandbuffer[buffercount-1] = buffer;
    buffercount++;
    if (buffercount >= 3) {
    MotorTarget = commandbuffer[0]*256 + commandbuffer[1];

    4) In my code I change direction only if necessary to save time.. I thougth it might be more effective.
    Last edited: Nov 6, 2021
  15. cubexxx

    cubexxx Member

    Joined:
    Oct 4, 2019
    Messages:
    67
    Balance:
    473Coins
    Ratings:
    +35 / 0 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF
    ad 1) I used baudRate = 115200 because that was enough for and I think it's a little more stable with lower baud rate, but in general I think it's not a problem to use higher rates
    ad 2) and 3) it's just for reading one unsigned int (2 bytes). There are surely other ways to do this and they will work probably just as well, I just like to have low-level control of those things,. I doesn't matter much in that part of the code I think
    ad 4) I also do that. It's not so easy to understand what my code does because of the low-level use of timers and interrupts
  16. zhai1987

    zhai1987 New Member

    Joined:
    Sep 7, 2021
    Messages:
    20
    Balance:
    48Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    2DOF
    Brother, I use some codes. My servo control can be used normally. Thank you for communicating with you!
  17. d4m

    d4m New Member

    Joined:
    Nov 23, 2021
    Messages:
    1
    Balance:
    17Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    AC motor, Arduino, 4DOF
    Thanks so much for your work. Added actuator limits detection via interrupt pins, mapping from 0 to 65535 and a bit of information for guidance https://github.com/ehmotion/eh-msc-4dof
    Working great so far ;-)
  18. KingPommes

    KingPommes New Member

    Joined:
    Nov 7, 2018
    Messages:
    9
    Balance:
    84Coins
    Ratings:
    +8 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    If anyone has a similar problem with controller is not reacting after start serial communication, try to put a elko between RST and GND. That solved the problem for me
    • Informative Informative x 1
  19. KingPommes

    KingPommes New Member

    Joined:
    Nov 7, 2018
    Messages:
    9
    Balance:
    84Coins
    Ratings:
    +8 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    @cubexxx
    It would be awesome if you can help me.

    I tried to use this code for another servo motor. It seems like 3us is too fast for the motor to recognize the pulses. I changed it to ~3,5us and motor is working. But every motor is loosing steps now after a while.

    You also said in your code

    // 3us (should not be changed, timing is critical)
    const unsigned int pulseLength = 6;

    (changed it from 5 to 6)

    So i tried to understand timers, but i dont know how to figure out why it has to be exact 3 microseconds. So i also dont know what i have to change to increase the pulseLength.
  20. zhai1987

    zhai1987 New Member

    Joined:
    Sep 7, 2021
    Messages:
    20
    Balance:
    48Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    2DOF
    Hi. Brother, have you tried using simtools link!
    upload_2021-11-27_6-22-55.png