Jeremy W. Langston

Personal Website

Sawbot Update 2

So, I wrote a bit of code to control brushed DC motors from a Logitech USB Gamepad -> Custom VC++ Software -> Custom Arduino Software -> Motor Driver -> Brushed DC motor.  This is mostly just temporary code to test things.  Ultimately there will be three modes of operation:   remote via RC transmitter, remote via PC, and autonomous.  Depending on how I decide to control this thing, the RC transmitter/receiver will be pretty much plug-n-play.  Autonomous control will come much later.  This is something I’ve done before and know how much work goes into it.  Remote via PC is fairly straight-forward, as I mentioned.

Here’s my code, including the Arduino sketch and the code for VC++:

DCMotor

The DCMotor class talks with the Arduino via the USB using RS232 communications.  I had to make my own protocol for passing commands to the Arduino to control the motors.  Right now each message is composed of the following:

<STX> <Forward> <Speed[7-0]> <Speed[15-8]><Speed[23-16]><Speed[31-24]> <ETX>

Each are bytes, where:

STX = start of text = 0x02

Forward = 1-forward, 0-back

Speed[#-#] = individual bytes of the unsigned int speed

ETX = end of text = 0x03

Inside the DCMotor zip are the DCMotorTestDlg .cpp/.h files I’ve used.  They can’t be directly built because there are several other files needed.  Really all you need to know are how to use the DCMotor class and how to talk to gamepads.  In the OnInitDialog() method of DCMotorTestDlg I make the following three calls:

m_DCMotor.Create(“DC Motor”, WS_CHILD|SS_NOTIFY, CRect(0,0,0,0), this, 6666);

m_DCMotor.Open(“COM13”);

SetTimer(m_pTimer, 20, NULL);

Create() is used for making a window.  The window is used for sending messages internally and externally. Internal messages go to/from the internal thread which does the communications to the Arduino.  External messages aren’t really used for much right now, but I’ll eventually rewrite all of this to be a Sawbot controller which will give status updates.  Open() does exactly what you think.  For now, I’m running at 9600, 8, n, 1.  SetTimer() is used for polling the gamepad for button presses.  I won’t get into the details of why I do polling instead of interrupts, except to say that polling allows for more use of the gamepad.  Feel free to let me know I’m wrong.

As you will see in OnTimer() method of DCMotorTestDlg, I issue move commands to the DCMotor class based on the analog X position of the gamepad.  Sorry about the massive lack of commenting.  I wrote it fast, but what isn’t obvious can be Google’d.  Just in case, here’s a quick explanation of what I’m doing.
if (bJoyPresent){
if ((joyInfoEx.dwXpos < 28672) || (joyInfoEx.dwXpos > 36864)){
if (joyInfoEx.dwXpos > 32767)
m_DCMotor.IssueCommand(true, (joyInfoEx.dwXpos – 32768)/128);
else
m_DCMotor.IssueCommand(false, (32767 – joyInfoEx.dwXpos)/128);
}
else {
m_nLastXpos = 32768;
m_DCMotor.IssueCommand(false, 0);
}
}

First, I’ve retrieved the gamepad/joystick info (refer to lines 104-109 of DCMotorTestDlg.cpp, not shown here).  If a gamepad is connected, then I check to see if I should command the motor to move.  I’ve put a dead-zone of 8192 (between 28672 and 36864).  This is to prevent the motor from always wanting to turn unless the value is exactly 32767.  Then I noticed a mistake.

The Arduino is an 8-bit microcontroller, and the pseudo-analog (read:  PWM) output I use to control the DC motor is 8-bit.  That’s a range of 0-255.  Much less than 0-32767.  So I divide by 128 to get in the appropriate range.  Not a big deal though as I doubt I will ever need to do anything more refined.

If you don’t quite follow my mental defection logic, feel free to leave a comment and I’ll explain.  Also, this code is very very basic and unfinished.  The Arduino code is easy to follow and uses the same protocol I stated above.  I’ll post up a demo when I get a chance.

51 Comments

  1. E vizite uygulama girişi ve SGK vizite girişi hakkında detaylar ssksor.com sayfamızda.

  2. Thank you for sharing this article with such good content. Good luck in the following article.

  3. Sawbot Update 2 – Snow Day Predictor – Today Updates For School Holiday

  4. Nice to see you readers! My name is Cameron Lake and I work as an essay author for learners at online writing service. One study tip that really helped with planning and accountability was to have pupils schedule study hours into their month, just like any other activity in their life. If you had a test one or two weeks, you would block three of four hours of studying time on your calendar each day leading up to the test. We also created schedules for a few months before finals and designated which subjects would be studied on which days based on the order of your final examinations. So, I recommend you to click on and discover here our beautiful service’s website and to buy essays online.

  5. به جون تو که نباشی میخوام این دنیا نباشه
    بدون تو بدون که زندگیم آخراشه
    به جون تو که دلم طاقت دوریتو نداره
    بدون تو میرسه به ته خط دلم دوباره
    نمیشه که بری خاطره هاتو فقط بذاری نمیشه که به این راحتی بگی منو نداری

    دانلود آهنگ جدید ماکان بند به جون تو

  6. Skyrim Script Extender (SKSE) – SKSE 64 Install, Update With Vortex

  7. How to Get Free Hulu Premium Accounts in 2020? (Working Accounts & Methods)

  8. I think that it can be a good idea to read some HempWorx gummies reviews. It doesn’t take hours to look through. However, you can find something really noteworthy.

  9. DC Motors are very simple to build. It generates more than 5v that’s why u kept 5v voltage regulator is it anyway it’s super cool.

  10. Thank you for sharing this article with such good content. Good luck in the following article.

  11. Thank you for your post. I think you can use C and Arduino IDE on linux. It’s eassy to code. No need to use C++ for programming Arduino.

  12. Your site is exactly what I have looking for it such a nice content. Thank you for sharing valuable information.

  13. m_DCMotor.Create(“DC Motor”, WS_CHILD|SS_NOTIFY, CRect(0,0,0,0), this, 6666);

    m_DCMotor.Open(“COM13”);

    SetTimer(m_pTimer, 20, NULL);

    this code is not working…kindly help

  14. Find live NFL scores, pro football player & team news, NFL videos, rumors, stats, standings, team schedules & fantasy football games on FOX Sports.

  15. nice technology super valuable information thank you sir

  16. To seek the best Life Science Writing Services for those studying biology coursework writing services, it is important to hire an award winning science paper writing service company.

  17. To seek the best Life Science Writing Services for those studying biology coursework writing services, it is important to hire an award winning science paper writing service company.

  18. Philosophy coursework writing service seekers have been on the rise lately since most learners need Philosophy Essay Writing Services, philosophy assignment writing services and philosophy research paper writing services.

  19. All things are very great that you have introduced us in this blog but I think these are useful for my

  20. It’s excellent . its unique

  21. thanks for sharing with us download

  22. This is a good information blog. I am pretty much pleased with your good work.

  23. Thanks for sharing this method. I’m searching for it, and now I’m landing on the right page.
    This is a beneficial method.
    I have a tip for you. I’m searching for the solution of my homework, and I find Textsheet Alternative which help me to solve my homework so if you are facing any issue in your homework you should also visit Textsheet Alternative.

  24. Click on any coupon of Beulah London on the promothecode website and enjoy shopping!

  25. You can lie but I know that you’re not fine (oh yeah) Every time you talk You talk ’bout me but you swear I’m not on your mind You can pretend you don’t miss me (me) You can pretend you don’t care. tetris

  26. skribbl io Everybody knows You and I are suicidal stolen art (oh yeah) Pretty moments sews Stitches into all your bitches broken hearts.

  27. روشهای نوین و قانونی ماخذ اقامت اروپا از طریق تمکن مالی و ثبت شرکت بدون سرمایگذاری تحصیل رایگان فرزندان
    EGHAMAT EUROPA
    Nice Post! I am really thank you for sharing these sites here, GREAT JOB.

  28. روشهای نوین و قانونی ماخذ اقامت اروپا از طریق تمکن مالی و ثبت شرکت بدون سرمایگذاری تحصیل رایگان فرزندان
    EGHAMAT EUROPA
    Nice Post! I am really thank you for sharing these sites here, GREAT JOB1.

  29. یونیت هیتر یا واحد گرمایشی، دستگاهی تک فصل (گرمایشی) است. قطعات اصلی دستگاه یونیت هیتر شامل موتور و پروانه، کویل یا کوره حرارتی و بدنه دستگاه است.

  30. What I read from the forum is very good. I am looking for your content. That helps me improve my website.geometry dash

  31. I think that thanks for the valuabe information and insights you have so provided here. Play animal crossing with me!

  32. With every breath
    And all the choices that we make run 3

  33. good Forumdan okuduklarım çok güzel

  34. Chinese Evergreen Plant

    The Chinese evergreen is the common name used for a collection of plants from the Aglaonema genus – which tend to tolerate low light conditions very well.

    Aglaonemas will produce flowers (these are not very showy), but they’re grown primarily for the attractive leathery leaves.

    Description
    Picture of the Chinese evergreen

    There are many hybrid varieties of the Chinese evergreen available which have been cultivated over the last century. This is because of their increasing popularity for indoor growers to use them as ornamental plants for room decoration.

    These slow growing plant varieties includes, plain green, speckled, blotched and variegated types. One of the most popular and sought after is the silver queen which has leaves covered in silver mainly with some small green patches.

  35. 7 days detox hakında bilmedikleriniz.

  36. 7 days detox hakında bilmedikleriniz. neler neler

  37. 7 days detox nedir, 7 days detoksu

  38. قیمت حوله خشک کن ها براساس تعداد لوله های رادیاتور حوله ای محاسبه می شوند و به طور کلی قیمت حوله خشک کن در مدل های آلومینیومی کمتر از مدل های فولادی و استیل موجود در بازار می باشد.

  39. I would like to recommend you to contact edubirdie review if you need a written work. Here you will write a work of any complexity, any volume. I myself have ordered in total about ten works in the past year. I received all of them in time and at best.

  40. saglik-sozlugu.com

    December 27, 2020 at 7:08 pm

    Eğitim ve sağlık hakkında tamamen özgün ve güncel bilgiler sunuyoruz. Maaşları, ne iyi gelir.
    #maaşları #neiyigelir
    https://saglik-sozlugu.com

  41. Eğitim ve sağlık hakkında tamamen özgün ve güncel bilgiler sunuyoruz. Maaşları, ne iyi gelir.
    #maaşları #neiyigelir
    https://saglik-sozlugu.com

  42. Thanks for this great post, I really loved reading your blog. I find it very interesting and very well thought out and put together. I just hope that you keep it going on later on as well. Cheers!

  43. Thank you for another informative blog. Where else could I get that type of info written in such a perfect approach? I have an undertaking that I’m simply now working on, and I’ve been on the lookout for such information.

  44. hank you for another informative blog. Where else could I get that type of info written in such a perfect approac
    ทางเข้า slotxo

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑