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.

54 Comments

  1. I hope I got a great chance to visit site like this. Best wishes and I will try to get this in future also because the work you have done here is excellent.

  2. I am really happy to read this informative post, I am learning here some new things and that should be very helpful for me in future. I am a huge video game lover and I like to play game always in the new way or new style. Well, thank you for updating us.

  3. Hızla büyüyen ve gün geçtikçe vazgeçilmez hale gelen, kullan at ürünler sektörüne yeni bir soluk getirmek amacıyla şirketimiz, Aycup ® 2012 yılında kurulmuştur. İstanbul Beykoz’da bulunan ofisi ile kurumsal firmalara yönelik özel çözümler sunarak, başta karton bardak, ahşap karıştırıcı, ofis sarf malzemeleri ve kullan- at ürünlerin satışını yapmaktayız.

    Kendi müşteri portföyüne kısa bir zamanda sahip olan Aycup® yaptığı yatırımlarla markasını sektöre kabul ettirerek ciddi bir yer edinmiştir. Aycup ® kağıt bardak, sektöründeki trendleri sürekli güncel tutarak, satış ve kalite farkını her geçen gün geliştirip büyümektedir.

    Kalitesi ile her geçen gün dikkat çeken Aycup ® markamız karton bardak, tahta karıştırıcı, plastik karıştırıcı, kullan at malzemeleri satışında sektörünün lokomotifi halindedir.

    Aycup ® insan sağlığına zararsız, doğada çözülen ham maddeden üretilen ve seçilen kullan at ürünlerinin, geri dönüşümü maksimum seviyeye çıkarmak için yoğun gayret göstermektedir. Firmamız müşterilerine kesintisiz hizmet vermektedir.

    Türkiye’de ambalaj denilince akla gelen lider Marka Aycup ® ‘tır. ”Koşulsuz Müşteri Memnuniyeti” öncelik verdiğimiz prensibimizdir.

    Aycup ® markası Aycup şirketinin tescilli markasıdır.

    Saygılarımızla ✔

  4. Excellent article! We are linking to this particularly great article on our website. Keep up the great writing.
    Chemistry Homework Help

  5. SGK işveren işlemler, bağkur primi, emeklilik hakkında güncel gelişmeler ve daha fazlası .sskisveren.com sitemizde.

  6. If you are looking for a professional company you can help you with your need for my assignment help services then, get yourself connected to IdealAssignmentHelp now. We have the most reliable and professional team in the business to help you with top-quality assignment writing services. Our experts are highly experienced and educated enough to deliver the goods for you as per your specific needs and requirements. Get Connected now for Assignment Help!

  7. I really loved this update and you have done some major changes in this update which I liked very much.

  8. I will say this update is one of the best updates which you have launched. Thanks a lot for this update.

  9. Matlab gives library abilities to different huge exercises, and various additional assignments may be drilled A Critical Study To Analyses Why The Students Need Dissertations by making m-records without any planning. Notwithstanding, there are certain endeavors that can’t be developed capably using the advantages open inside Matlab itself.

  10. Askeri bilgiler olarak thank you.

  11. we provide Norton Security services. Norton Security product is one of the best antivirus to be found currently and so, is the setup process. if you are facing any problem with your Norton setup then you can get any help from our website norton.com/setup

  12. we provide Norton Security services. Norton Security product is one of the best antivirus to be found currently and so, is the setup process. if you are facing any problem with your Norton setup then you can get any help from our website https://w-wnorton.com/

  13. we provide Norton Security services. Norton Security product is one of the best antivirus to be found currently and so, is the setup process. if you are facing any problem with your Norton setup then you can get any help from our website

  14. This is one of the greatest updates one can ask for and believe me everyone is going to love this update.

  15. Great article Lot’s of information to Read…Great Man Keep Posting and update to People..Thanks

  16. Very nice blog and articles. I am really very happy to visit your blog. Now I am found which I actually want.

  17. I think you provide the better information to us you.

  18. I like your website. No fluff, just helpful info. Great job.

  19. Thanks for the post and great tips! I found your website perfect for my needs. It contains wonderful and helpful posts.

  20. awesome code thanks for your effort.

  21. I will say this update is one of the best updates thanks so much.

  22. Great and wonderful update of sawbot just love it man thanks for sharing.

  23. Thanks for the post and great tips! I found your website perfect for my needs. It contains wonderful and helpful posts.

  24. It’s excellent . its unique
    سانجا موزیک

  25. amazin post thanks for sharing that

  26. The DCMotor class talks with the Arduino via the USB using RS232 communications.

  27. Microsoft Inc. Today started rolling out Windows 10 Mobile [Microsoft’s new mobile operating system] update to chose Windows Phone 8.1 devices, after numerous deferrals. As in keeping with Microsoft “Consistent with our method to the Windows 10 PC upgrade, we are centered on delivering a high first-class experience for our customers.Microsoft formerly briefs about the listing of Lumia phones so one can be updated to
    Windows 10.

  28. This Sawbot Update 2 was really helpful. Ones I stuck in the code but after studying get the wanted solution. This is something I have done on my recent project which provide online academic help services.

  29. The post is interesting. The content explores Sawbot Update 2. It mentions that ultimately there will be three modes of operation such as remote via RC transmitter, remote via PC, and autonomous. The DCMotor class discusses with the Arduino by means of the USB using RS232 communications.

  30. tank you I will save your blog in future reference

  31. Thank you i like your blog

  32. https://belllibrary.dash.umn.edu/community/profile/aso/
    ASO – SEARCH OPTIMIZATION OF MOBILE APPLICATIONS ON GOOGLE PLAY AND APP STORE

    The growth of Competition
    In 2008, the Apple App Store had around 5 000 different applications. Nowadays prediction that by 2020, the App Store will have 5 million app. Rivalry is growing very fast, and you need to take every opportunity to get user on you app

  33. Web Sitesinin Kazandırdığı Avantajlar
    Web site tasarımı sayesinde markanızın veya ürünlerinizin tanıtımını kısa sürede daha geniş kitlelere yayabilirsiniz. Günümüzün olmazsa olmazı haline gelen teknoloji sayesinde artık işler daha kolay. Bu kolaylık tabi ki web site kullanımını da etkilemektedir. Web siteler sayesinde kullanıcı firma ve müşteri arasında duvar olmayacak, mesafe kalmayacaktır. Satışını gerçekleştirmek istediğiniz bütün ürünleri doğrudan müşterilerinize sunabileceksiniz. Ne dükkan kirası, ne de ürün karmaşası yaşamayacaksınız. Her şey tek bir tuş ile gerçekleşecek.

    Günümüzde pek çok büyük markanın ve firmanın web sitesi üzerinden çalıştığını biliyorsunuz, neden sizler de bu konforla tanışmayasınız? Yapmanız gereken çok basit, firmamız ile iletişime geçerek pek çok kolaylıktan sizler de faydalanabilirsiniz. 24 saat açık tutabileceğiniz, milyonlara ulaşan ürün seçenekleriniz, hızlı ve toplu satış işlemleriniz ile sizler de yer aldığınız sektörde fark yaratabilirsiniz. Firmanız ile müşteriler arasında ki güven bağı da daha hızlı ve kuvvetli şekilde oluşacaktır. O halde sizler de web site tasarımı hizmetlerimizden faydalanın.

    Web site tasarımı için firmamızın internet sitesinde yer alan telefon numarasını kullanarak iletişime geçebilirsiniz. Profesyonel ekibimiz tarafından istekleriniz alınır ve web site tasarımı oluşturulmaya başlanır. Kısa süre zarfında sonlandırılan hizmetimizden memnun kalacağınıza eminiz. Kaliteli, kolay ve teknolojik hizmetler için firmamızı tercih ederek iletişime geçin.
    https://guzeltasarim.website/website-tasarimi.html

  34. Web Sitesinin Kazandırdığı Avantajlar
    Web site tasarımı sayesinde markanızın veya ürünlerinizin tanıtımını kısa sürede daha geniş kitlelere yayabilirsiniz. Günümüzün olmazsa olmazı haline gelen teknoloji sayesinde artık işler daha kolay. Bu kolaylık tabi ki web site kullanımını da etkilemektedir. Web siteler sayesinde kullanıcı firma ve müşteri arasında duvar olmayacak, mesafe kalmayacaktır. Satışını gerçekleştirmek istediğiniz bütün ürünleri doğrudan müşterilerinize sunabileceksiniz. Ne dükkan kirası, ne de ürün karmaşası yaşamayacaksınız. Her şey tek bir tuş ile gerçekleşecek.
    https://guzeltasarim.website/website-tasarimi.html

  35. Web Sitesinin Kazandırdığı Avantajlar
    Web site tasarımı sayesinde markanızın veya ürünlerinizin tanıtımını kısa sürede daha geniş kitlelere yayabilirsiniz. Günümüzün olmazsa olmazı haline gelen teknoloji sayesinde artık işler daha kolay. Bu kolaylık tabi ki web site kullanımını da etkilemektedir. Web siteler sayesinde kullanıcı firma ve müşteri arasında duvar olmayacak, mesafe kalmayacaktır. Satışını gerçekleştirmek istediğiniz bütün ürünleri doğrudan müşterilerinize sunabileceksiniz. Ne dükkan kirası, ne de ürün karmaşası yaşamayacaksınız. Her şey tek bir tuş ile gerçekleşecek.

  36. Playing online games bring a lot of benefits to kids. Through geometry dash, players can enhance their flexibility and reaction while having fun.

  37. uffak

    #uffak

    sosyal içerik platformu

    #sosyal içerik platformu

    https://uffak.com

  38. Thanks for post about Pharmaceuticals in our drinking water!

  39. It’s excellent . its unique

  40. It’s excellent . its unique ئئئ

  41. I will bookmark your blog in future as reference

  42. It’s excellent . its unique

  43. É um ótimo site. O Design parece muito bom. Continue trabalhando assim !. hot blue caps

  44. wow, with your article you really helped my son deal with a controller that he couldn’t use for about a year! Thank you very much for your help. By the way, I also help people and write cheap essays on order, please contact if necessary!essaycompany com

  45. wow, with your article you really helped my son deal with a controller that he couldn’t use for about a year! Thank you very much for your help. By the way, I also help people and write cheap essays on order, please contact if necessary!

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑