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.

53 Comments

  1. Thanks for your marvelous posting!

    • Sawbot Update 2 is an interesting article for the students to take interest in the new techniques of the basic infrastructures that can be used to creative day by day as the services which are giving to the peoples like the professional content writer are here to gives you better and best contents for your assignments and blogging in all over Pakistan

    • Thanks for the article!

    • Great sharing and throughout explanation! Thank you very much for providing us extensive information. Please keep updating more articles.
      Do not hesitate to see and discuss with us more at our website

  2. I’ve got you book marked to look at new stuff you post…

  3. SGK emeklilik tablosu ile ne zaman emekli olabileceğiniz hakkında hesaplama yapabilirsiniz. Kadın ve erkekler için emeklilik yaşı tablosu, emeklilik hesaplama ve tüm detaylar sgkbilgisi.com sayfamızda.

  4. SGK bilgisi sayfamızda emeklilik tablosu, SGK emeklilik şartları, kadınların ve erkeklerin emeklilik hesaplaması hakkında bilgi bulabilirsiniz.

  5. SGK bilgisi sayfamızda emeklilik tablosu, SGK emeklilik şartları, kadınların ve erkeklerin emeklilik hesaplaması hakkında bilgi https://sgkbilgisi.com/emeklilik-tablosu/

  6. Fimody, A website where the best and most beautiful content is shared. If you are looking for free accounts and codes, you are on the right page. Search: how to create a free account, create a free account, free account create, create your free account now. Our Fimody website is a website that has been launched in these recent years. I was once looking for free accounts but could not find them. After discovering this, I believed that nothing would be impossible and I created this website.

  7. Fimody, A website where the best and most beautiful content is shared. If you are looking for free accounts and codes, you are on the right page.

  8. Amazing blog and everything has been shared in an amazing way.
    Keep it up. Rivipedia

  9. Amazing blog and everything has been shared in an amazing way.
    Keep it up.

  10. The best snake online game to train your brain.

  11. Offshore Hosting with 100% DMCA ignored Hosting, Offshore Dedicated Server, Offshore VPS Hosting. http://offshorededi.com/ is the Most Secure Offshore Host. Providing Offshore Streaming Servers as well.

  12. Our site offers free chegg accounts that you can use on mobile android and iphone devices and desktop applications.

  13. It was a good article. I’m looking forward to the rest. You can also view my site by clicking here.

  14. It was a good article. I’m looking forward to the rest. You can also view my site by clicking here.

  15. Fully managed to host with SSD storage, Free cPanel, Instant setup, and up to 10x faster. The power of SSD + Simplicity of cPanel. Secure, powerful, and easily scalable. 1-Click Upgrade. 24×7 Support. Host Unlimited Website. Unmetered SSD Disk Space.

    Best Free VPS Hosting

  16. Really great post, thanks for sharing.
    keep going.

  17. Thanks for update!

  18. Thank you so much for sharing all this wonderful information !!!! It is so appreciated!! You have good humor in your blogs. So much helpful and easy to read!

  19. Moda uzun yıllardır hayatımızın merkezinde yer almış durumdadır. Moda standı moda trendleri hakkında bilgilendirmeler yaparak modaya uymanızı sağlamaktadır.

  20. Nice coding
    Going to share and subscribe

  21. You could shoot a video clip about this update, since it is not entirely clear in the article what new has been added, and edit it using the movavi video editor https://www.movavi.com/videoeditor/ Personally, I use this video editor, and have never regretted choosing it.

  22. Thanks!
    This is Couponsva, a professional blogger I enjoy writing on multiple callings with a firm grip on specialty include digital marketing, affiliate marketing, entertainment, and e-commerce blogs.

  23. Thank you so much for sharing all of this fantastic knowledge with us!!!! It’s really appreciated!! In your posts, you have a nice sense of humour. So much information that is both useful and easy to understand cookie clicker!

  24. Thank you so much for sharing all of this incredible information with us!!!! It’s really helpful!! You have a good sense of comedy in your posts. There is a wealth of material that is both valuable and simple to comprehend cookie clicker!

  25. Free Roblox Accounts free old roblox accounts, free roblox accounts 2021. Free roblox accounts generator, free roblox accounts with robux. Examine This Report On Account And Passwords. Currently, we have been offering you free Nitroflare High quality accounts and passwords. For people of you that are not familiar with Nitroflare, don’t be concerned! We will give you several facts about this System in the following paragraphs. Within the function your password can’t be reset by using the myAccount process, you must Speak to ITS Guidance applying among the list of approaches below.

  26. Nevas Technologies is a certified Microsoft Dynamics 365 Business Central Partner with more than 15 years of experience dedicated to delivering Microsoft Dynamics ERP and CRM solutions and services. Nevas provides professional services that will help your business migrate to, implement, support, or customize Microsoft Cloud software; especially Microsoft Dynamics Microsoft Dynamics 365 ERP partner, and Dynamics CRM. At Nevas, we continue to make investments in growing our global presence in order to meet the demands of our worldwide Microsoft Dynamics AX and Microsoft Dynamics 365 Finance & Operations, Dynamics 365 Business Central customer base. We have proven track record deploying and supporting Microsoft cloud solutions across a global footprint, so you can count on us to do what we need to do, and be where we need to be.

  27. pembe portakal guncel kadin blogudur .. https://bedavanumune.net ..

  28. Recently, my sister was tested online to qualify for a job. I noticed how frightened she was, and I urged her to pay someone to take my test. She was on the job list after a week of testing. My sister thanked me so much. She spent little for services, and more than that, she’s going to get that money out in a month. I suggest to anyone this site.

  29. Elektronik kart tamiri hizmeti vermekteyiz, kombi kartı tamiri, beyaz eşya anakart tamiri, klima kart tamiri
    Elektronik kart tamiri

  30. Super interesting, congratulations!

  31. Interesting post. I was wondering about this, so thanks for posting. Pretty interesting post. It’s really nice and useful.

  32. Such an informative post.Thank you for sharing the great knowledge. If you want to buy aws without your free credit card on amazon then i suggest you to try real credit card generator.

  33. Hi tһere, You’ve done a great ϳob. I will certainly Dig it and personally recommend it to my friends. I’m sure they’ll be benefited from this site.

    IPL 2021 Match Prediction

  34. Visit take my courses for me. This site provides you good online educational courses about your own concern.

  35. PGSLOT a direct website, a popular online slot camp with many special promotions It is a favorite of all slot game fans. In addition to the new and unique gameplay style.

  36. ufabet888 and have the opportunity to turn into hundreds of thousands or millions of winnings in the blink of an eye.

  37. Thank you so much for giving everyone an exceptionally brilliant
    possiblity to read articles and blog posts from this web site.
    Can join with us UFABET

  38. Thank you so much for giving everyone an exceptionally brilliant
    possiblity to read articles and blog posts from this web site.
    Can join with us https://ufabet-auto.com/

  39. Thank you so much for giving everyone an exceptionally brilliant
    possiblity to read articles and blog posts from this web site. https://ufabet-auto.com/

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑