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.

50 Comments

  1. Thank you for letting me know about this event moto x3m unblocked

  2. I recently tried my hand at online casino gaming and sports betting in India, and I must say, my experience with Parimatchs https://parimatchs.in/ was fantastic. The website is incredibly user-friendly, offering a diverse range of games and sports to bet on. The bonuses are quite generous, and I appreciated how detailed the information provided on the site was. Moreover, there’s a noticeable absence of intrusive advertisements, and the withdrawals are processed swiftly. Overall, I found Parimatchs to be a reliable platform with up-to-date information, making it a great choice for anyone looking to dive into online betting.

  3. Great post! It’s fascinating to see the advancements in robotics and automation, especially in the context of construction. Speaking of efficiency, have you ever considered how technology is revolutionizing other industries, like travel? For instance, when it comes to airport parking, services like EzyBook Compare Parking make finding affordable and convenient Airport Parking Stansted a breeze. It’s impressive to see how innovation is streamlining processes across various sectors!

  4. I love this content, thanks for uploading it.

  5. Wonderful article. This blog is impressive, and I’ve been checking it frequently. Very helpful knowledge, especially the end section where the wheel spinner forced me absorb a lot of information. This knowledge has been on my wish list for a while. Greetings and best of luck!https://motox3m.co/

  6. Spelandet har utvecklats till en mångsidig och inflytelserik industri som erbjuder olika underhållningsupplevelser på olika plattformar. Från engagerande konsol- och datorspel till mobilspel på smartphones och surfplattor fortsätter spelbranschen att växa och locka miljoner spelare över hela världen. Det som gör spelandet så attraktivt är förmågan att erbjuda fängslande berättelser, interaktiva utmaningar och sociala interaktioner genom online-multiplayermiljöer. Spelutvecklare strävar ständigt efter att utmana gränserna med innovativa teknologier som virtuell verklighet (VR) och förstärkt verklighet (AR), vilket skapar mer immersiva och realistiska spelupplevelser. Esport, eller tävlingsspelande, har också blivit alltmer populärt, med professionella spelare som tävlar i organiserade turneringar för stora priser och global erkännelse. Spelandet inte bara underhåller utan påverkar också kultur, teknik och vårt sätt att kommunicera med andra i den digitala eran.

  7. Thank you for sharing such an insightful post! I thoroughly enjoyed reading it and found your perspective quite engaging.feel free to visit Inforinn. It’s a dedicated platform for global readers

  8. Thank you so much for giving everyone an exceptionally brilliant
    possiblity to read articles and blog posts from this web site.

  9. Your article has great depth, I will summarize the main ideas

  10. Drift Hunters is truly a great racing game.

  11. Purwadi Sirait

    May 18, 2024 at 3:47 am

    Great job! This was a pleasure to read. bandar toto macau

  12. Please provide me with essential information on this resource, as I was previously unaware of it. Right now, I am awake.

  13. Thank you for posting that it could be just the thing to give inspiration to someone who needs it! Keep up the great work!

  14. This article is very very great thanks for sharing this info.

  15. This article is very very great thanks for sharing this info. https://www.receiptify.net

  16. Thanks for sharing this info it’s very helpful for us.

  17. Enjoyed reading the article above, really explains everything in detail, and the article is very interesting and effective. https://www.receiptify.net

  18. This is truly a great article. Thanks for your sharing.

  19. Anonimlik: Kullanıcılar, gerçek kimliklerini ifşa etmeden sohbet edebilir, bu da daha özgürce ve rahat bir iletişim ortamı yaratır.

  20. Thanks for this information. https://www.mylabcorp.us/

  21. Thanks for sharing this type of info it’s great to us. https://www-mypascoconnect.com

  22. Hope you update soon io games

  23. Depending on how I decide to control this thing, the RC transmitter/receiver will be pretty much plug-n-play connections game.

  24. I am happy to find this article content very helpful and valuable for everyone, as it contains lot of topic information.

  25. This is truly a great article. Thanks for your sharingg.

  26. Wonderful! I’ll let my friends know about it and ask them to check it out. Thanks for telling connections game me!

  27. A really good post, very thankful and hopeful that you will write many more posts like this one.

  28. mysedgwick walmart

    June 17, 2024 at 4:39 am

    A really good post, very thankful and hopeful that you will write many more posts like this one. mysedgwick walmart

  29. A really good post, very thankful and hopeful that you will write many more posts like this one. https://www.my-sedgwick.com

  30. Your article is valuable for me and for others. Thanks for sharing your information! OneBloodRewards

  31. Thanks to the article i can learn more. Expand my knowledge and abilities.

  32. Thanks to the article I can learn more. Expand my knowledge and abilities. https://www.ny-stateofhealth.com

  33. Excellent article. I really like this. Thank you for sharing. Cintas Partner Connect

  34. This update is very nice grade calculator

  35. Thanks for this wonderful information here. I want to know some more about it. ky kynect

  36. Your encouragement has meant the world to me, and I will always be grateful.

  37. Your encouragement has meant the world to me, and I will always be grateful

  38. This information is really helpful for who really needs this. I hope you will many more write post like this. This article is really amazing i hope we will see again this type of article in future. Jetnet American Airlines

  39. SimonWhitehead

    July 30, 2024 at 12:10 am

    Thanks For sharing this Superb article.I use this Article to show my assignment in college.it is useful For me Great Work. bandar toto macau

  40. CredibleBH streamlines behavioral health workflows, improves patient care, and enhances data management for optimal outcomes. https://www.crediblebh.ltd/

  41. Sawbot 2 update improved a lot of things, as I expected Sawbot 2 really made me satisfied.

  42. Thank you very much for this very useful article. I hope the author will continue to produce inspiring works. For those who want to play online gambling with a fair system, papahoki888 is the right choice.

  43. Jenis permainan paling banyak diperbincangkan sekarang ini, tidak lain adalah slot online tergacor. Judi slot online merupakan permainan single player yang mulanya dimainkan di kasino dan kini mudah dan simpel hanya menggunakan Android atau perangkat sejenisnya. Cara main yang mudah dan simpel ini pun menawarkan tingkat fleksibilitas sangat tinggi dimana bettor mudah bermain dimana saja dan kapan saja.

    bandar slot

    Para penggemar judi slot bisa dapatkan layanan bermain taruhan game slot terbak dan terpercaya dengan bisa bergabung di situs bandar slot yang memang bisa diandalkan untuk jangka Panjang. Untuk itu, bettor dapat memasang taruhannya dengan bermain di situs judi terpercaya yang sudah resmi dan berlisensi sehingga mampu berikan pelayanan terlengkap secara maksimal dan optimal segalanya dengan tujuan memberi kepuasan semua member.

  44. I believe your brilliant and original idea will be duplicated and used to stimulate the production of many other ideas. moto x3m

  45. تفصيل الكنب هو عملية تصميم وصناعة قطع الأثاث وفقًا لرغبات واحتياجات العميل. يتم اختيار المواد المستخدمة بعناية، سواء كان ذلك في اختيار نوع الخشب للإطار أو نوع الأقمشة للتنجيد. يمكن للعميل تحديد الألوان، الأنماط، والأبعاد التي تتناسب مع مساحة الغرفة وأسلوب الديكور العام. التفصيل يسمح بالحصول على قطعة كنب فريدة تعكس الذوق الشخصي وتضيف لمسة خاصة إلى المكان. يمكن أن يتضمن التفصيل أيضاً إضافة ميزات خاصة مثل التخزين الداخلي أو مقاعد قابلة للتمدد لزيادة الراحة والوظائف.
    تفصيل كنب

  46. Bagi para pecinta Salah satu situs slot slot online di Indonesiaterpercaya yang menyediakan pengalaman, mencari situs permainan slot online yang dapat diandalkan dan menjamin kemenangan tinggi adalah hal yang sangat penting. Salah satu situs slot terpercaya yang menyediakan pengalaman bermain slot dengan RTP slot88 tertinggi adalah Alexistogel. Dengan banyak nya bonus untuk member setia dan berbagai jenis permainan slot dari provider terbaik, Alexistogel menjadi pilihan tepat bagi siapa saja yang mencari situs slot online yang dapat diandalkan dan menjanjikan kemenangan tinggi.

    situs slot online

  47. Alexistogel merupakan bandar toto macau resmi terpercaya yang menyediakan link alternatif login dan daftar akun secara cepat tanpa terkendala.

    alexistogel

  48. Alexistogel adalah platform permainan togel online terutama pasaran toto macau. Alexistogel juga dikenal sebagai bandar toto macau terpercaya karena reputasinya sebagai agen togel resmi yang memiliki lisensi resmi dan terbukti terpercaya. Banyak keuntungan yang didapatkan jika bermain tebak angka di Alexistogel, seperti contoh layanan yang sering digunakan para member setia kami adalah Bocoran Prediksi Togel yang selalu update dan dikenal sebagai bocoran yang paling akurat jika dibandingkan dengan sumber lainnya. Maka dari itu, bergabung sekarang juga dengan Alexistogel dijamin mendapatkan berbagai promosi menarik serta pastinya keamanan dalam bertransaksi juga terjamin.

  49. ALEXISTOGEL – Siapa tidak mengenal megahnya patung Merlion merupakan salah satu Trademark dari negara Singapore yang didalamnya terdapat permainan lotto atau biasa kita sebut togel yang memiliki hadiah kemenangan paling besar. Dengan persaingan ketat tentunya anda sebagai penggemar togel sejati tentunya menginginkan kemenangan terbesar di pasaran togel Singapore ini, karena itulah Prediksi Togel Alexistogel ini

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑