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. Previously used products or services Please advise and trust to get started. We are accurate and secure. No. 1 online slots website,pg สล็อต camp, direct slots website for 2023, pgslot, direct website, agent exam, no minimum, many promotions is the best choice for you

  2. We must be very careful when reading blog posts. I already did it, and I think this post is really great

  3. “Your blog post is like a hidden gem in the vast treasure chest of the internet. It’s a refreshing departure from the ordinary, offering a unique perspective that’s both thought-provoking and genuinely intriguing. Your creativity shines brightly, casting a captivating spell on readers and leaving them with a delightful sense of wonder. Thank you for sharing this uncommon and inspiring piece of content that reminds us all of the endless possibilities when we dare to think outside the box!”
    Abogado de Conducir sin Licencia el Condado de Monmouth

  4. Your creativity shines brightly, casting a captivating spell on readers and leaving them with a delightful sense of wonder. Thank you for sharing.
    Abogado de Conducir sin Licencia el Condado de Monmouth

  5. I really appreciate this wonderful post that you have provided for us. I feel strongly that love and read more on this topic. I have spent a lot of my spare time reading your content. Thank you a lot.

  6. You’ve done us a great service by sharing this informative article. I urge you to continue your research on this topic, which I adore. only up

  7. I am continually impressed from the depth of the research. 바카라사이트

  8. Currently, downloading videos from TikTok without a watermark is a violation of TikTok’s usage policy, word wipe as the content on TikTok belongs to the user who created it and is not allowed to be distributed or reused without the author’s consent.

  9. Greetings. I have experience with graphic novels, which offer exceptionally unique content. However, in all honesty, I would recommend authors to consider utilizing polynesian images. This platform offers the option to acquire original images at a reasonable cost without compromising on quality. Many professionals rely on this resource for their projects because content in this format tends to have a more visually appealing appearance, remains distortion-free, has compact file sizes, and is easily editable.

  10. I am amazed at how well you operate terms to get your component throughout. I would be inquisitive about analyzing more of your work!!

  11. ne living re비아그라판매sources, nut비아그라판매rient cyclin비아그라판매g an

  12. I gained so much after seeing your post! In the past I often played games, this is a fun game for entertainment, but now I will follow you, reading your article will give me more knowledge.

  13. E-KTP ,KK (kartu Keluarga) dan Dokumen merupakan salah satu bentuk komunikasi tertulis yang penting dalam kehidupan sehari-hari. Dokumen dan Terkadang, kita mungkin menghadapi situasi di mana kita ingin menyempurnakan atau mengedit E-KTP dan KK (kartu Keluarga) yang akan dikirimkan. Dalam situasi ini, muncul berbagai jasa yang menawarkan layanan edit surat e-ktp dan KK atau yang lain nya. INGAT KAMI TIDAK MENCETAK & PRINT HANYA JASA EDIT SAJA

  14. I am looking for some good blog sites for studying. I was searching over search engines and found your blog site. Well i like your high quality blog site design plus your posting abilities. Keep doing it.

  15. d studies in씨알리스구입 사이트 India since씨알리스구입 사이트 1994, when 씨알리스구입 사이트GPS

  16. You overwhelmed me with facts. After reading your informative blog. Glad to learn from your useful skill. Thank you for sharing.

  17. Повезло вам учиться в этом удивительном вузе. Видимо, в нем сверхсовременные аудитории, спортзалы, есть все необходимое для практических занятий, и студенты имеют насыщенную жизнь вместе с учебой. То есть, есть все для тех, кто обожает науку.

  18. or creating 시알리스awareness of시알리스 floricultur시알리스e am

  19. The objective of Run 3 is to guide the character safely through each level by jumping, running, and maneuvering to avoid obstacles such as gaps, pits, and rotating platforms.

  20. PG SLOT เว็บตรง แตกง่ายหนัก 50รับ100 เราการันตีเลยว่าคุณจะได้รับประสบการณ์ที่ไม่เคยเจอที่ไหนมาก่อน

  21. When the Cou빅휠게임ncil of Scie빅휠게임ntific and I빅휠게임ndus

  22. I learn a few superb information right here. Seriously worth social bookmarking regarding returning to. Thanks you for giving me such a Nice information. Dear author, Please keep us informed like this. Thanks for sharing.

  23. acities from안전사설토토 11th Novemb안전사설토토er 1959 to 1안전사설토토5th

  24. Thanks to reading this article, I have gained new knowledge, thank you very much

  25. I love that you told me about this piece; I really enjoy reading it. I was really hoping to find that, and I really hope you keep posting such great information in the years to come.

  26. It was a pleasure to share. Your post has demonstrated your diligence and the breadth of your industry knowledge. You can play: fnaf security breach unblocked to relax, or pass the time!

  27. https://www.nyt-wordle.net/
    NYT Wordle is a word puzzle game that challenges players to guess a five-letter secret word within six attempts. Each guess provides feedback on the accuracy of the letters guessed, helping players narrow down the possibilities with each attempt.

  28. The information you share is great, please continue to write about this topic regularly

  29. The information you share is Tempat Wisata di Jepang great, please continue to write about this topic regularly

  30. The information you share is great, please continue to write about this topic regularly

  31. فروشگاه اینترنتی کالا و گجت هوشمند است که محصولاتی با کیفیت عالی و قیمت مناسب در اختیار شما قرار می دهد.

  32. After reading this amazing and informative post I want to request you to write a blog about sterling silver real jewelry as I am searching for the best post here but I can’t find the quality posts.

  33. I seriously love your site.. Very nice colors & theme. Did you create this site yourself? Please reply back as I’m trying to create my very own site and would like to learn where you got this from or exactly what the theme is named. Many thanks. 먹튀커뮤니티

  34. I must say, this is a great post, and I appreciate the details. Undoubtedly, education is a touchy subject. It continues to be one of the hottest subjects right now. I’m grateful for your content and want to read more. 토토사이트

  35. Excellent knowledge is provided by your article, which we appreciate you taking the time to share with us. It’s great to see a website that provides so much information about many artists. You have amazing insight into this.

  36. Oh, this was a really wonderful post. Making the time and genuine effort necessary to produce a quality essay, but what can I say… I put off things a lot and never seem to finish anything. 스포츠토토

  37. خدمات تخصصی عیب یابی و تعمیر تلویزیون پاناسونیک در مدل های ال ای دی(LED)، ال سی دی(LCD)، اولد(OLED) و پلاسما در مرکز الکترونیک طهران بعنوان نمایندگی تعمیرات تلویزیون پاناسونیک با بیش از 27 سال سابقه حرفه ای در عیب یابی و تعمیرات لوازم الکترونیکی صوتی و تصویری، با ضمانت در تهران ارائه می شود.

  38. This is a very nice and informative piece that tells you everything you need to know and has a big effect on new technology io games unblocked

  39. Hello, This subject very interesting. thanks for helpfull writing. this article very important and true.
    thanks for helpfull writing. this article very important and true.

  40. افضل برنامج محاسبة في السعودية Do you have a computer that is running slow? Andersen has the solution for you. We offer a service where we will update your computer to the latest operating system, and in doing so, your computer will run faster. The Andersen team wants you to have the best experience with your computer. Updating to the latest operating system not only makes your computer run faster, but also provides you with the latest security features. Contact Andersen today for a free consultation!

  41. It is a very helpful essay! The following essay contains a wealth of information regarding the five nights at freddy’s that can be of assistance to anyone who is interested in launching a successful social media campaign.

  42. SGK hizmetleri hakkında tüm detaylı bilgiler burada!

  43. jenniferlopez1868

    February 25, 2024 at 8:26 pm

    Slope Game‘s dynamic and responsive gameplay ensures that every move you make is crucial for success.

  44. You can order this Beth Dutton purse from Yellowstone JacketCo, bringing a piece of the show’s iconic style into your wardrobe

  45. Great stuff! I’ll tell my friends about it and ask them to check it out. Thank you for sharing! When you have more time, go to: word wipe

  46. The gaming hub located at 바카라추천 is essential for any gaming enthusiast! Regardless of your expertise level, whether you’re a seasoned expert or a casual gamer, the platform offers an inclusive and thrilling experience tailored to accommodate all.

  47. Викладено наче добре, і тема цікава, на мою думку, хоч я займаюся трохи іншим, комп’ютерними іграми.

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑