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++:
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.
if (bJoyPresent){if ((joyInfoEx.dwXpos < 28672) || (joyInfoEx.dwXpos > 36864)){if (joyInfoEx.dwXpos > 32767)m_DCMotor.IssueCommand(true, (joyInfoEx.dwXpos – 32768)/128);elsem_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.
February 5, 2016 at 5:12 am
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.
August 24, 2020 at 8:11 am
This is a good information blog.
June 14, 2018 at 12:38 am
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.
January 30, 2020 at 2:30 am
This Sawbot Update 2 was really helpful. Ones I stuck in the code but after studying best essay writing service uk get the wanted solution. This is something I have done on my recent project which provide online academic help services.
January 30, 2020 at 2:31 am
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.
August 14, 2020 at 4:54 am
Excellent article! We are linking to this particularly great article on our website. Keep up the great writing…
November 7, 2018 at 7:57 am
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 ✔
September 26, 2019 at 2:36 am
Excellent article! We are linking to this particularly great article on our website. Keep up the great writing.
Chemistry Homework Help
September 27, 2019 at 3:28 am
SGK işveren işlemler, bağkur primi, emeklilik hakkında güncel gelişmeler ve daha fazlası .sskisveren.com sitemizde.
October 9, 2019 at 4:33 am
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!
October 29, 2019 at 3:38 am
I really loved this update and you have done some major changes in this update which I liked very much.
November 1, 2019 at 5:24 am
I will say this update is one of the best updates which you have launched. Thanks a lot for this update.
November 4, 2019 at 10:59 pm
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.
November 5, 2019 at 2:58 am
Askeri bilgiler olarak thank you.
November 6, 2019 at 11:24 pm
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
November 6, 2019 at 11:25 pm
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/
November 6, 2019 at 11:26 pm
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
November 7, 2019 at 12:57 am
This is one of the greatest updates one can ask for and believe me everyone is going to love this update.
November 12, 2019 at 2:45 am
Great article Lot’s of information to Read…Great Man Keep Posting and update to People..Thanks
November 16, 2019 at 3:55 am
Very nice blog and articles. I am really very happy to visit your blog. Now I am found which I actually want.
November 16, 2019 at 3:55 am
I think you provide the better information to us you.
November 25, 2019 at 1:13 am
I like your website. No fluff, just helpful info. Great job.
November 26, 2019 at 8:05 am
türk Instagram Takipci Satın Al
November 30, 2019 at 4:21 am
taraftarium24
December 1, 2019 at 11:22 pm
Thanks for the post and great tips! I found your website perfect for my needs. It contains wonderful and helpful posts.
December 7, 2019 at 2:30 am
awesome code thanks for your effort.
December 7, 2019 at 2:32 am
I will say this update is one of the best updates thanks so much.
December 11, 2019 at 4:17 am
Great and wonderful update of sawbot just love it man thanks for sharing.
December 18, 2019 at 6:20 am
Thanks for the post and great tips! I found your website perfect for my needs. It contains wonderful and helpful posts.
January 26, 2020 at 7:22 am
It’s excellent . its unique
January 26, 2020 at 7:22 am
It’s excellent . its unique
سانجا موزیک
January 28, 2020 at 2:50 am
amazin post thanks for sharing that
January 28, 2020 at 2:59 am
The DCMotor class talks with the Arduino via the USB using RS232 communications.
January 29, 2020 at 10:50 am
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.
January 30, 2020 at 2:32 am
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.
January 31, 2020 at 12:47 am
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.
February 3, 2020 at 5:44 am
tank you I will save your blog in future reference
March 6, 2020 at 5:30 am
Thank you i like your blog
March 14, 2020 at 12:01 am
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
March 14, 2020 at 3:18 pm
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
March 14, 2020 at 3:19 pm
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
March 14, 2020 at 3:19 pm
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.
March 16, 2020 at 8:30 pm
Playing online games bring a lot of benefits to kids. Through geometry dash, players can enhance their flexibility and reaction while having fun.
April 6, 2020 at 9:52 am
uffak
#uffak
sosyal içerik platformu
#sosyal içerik platformu
https://uffak.com
April 28, 2020 at 5:02 am
Thanks for loving site!
April 28, 2020 at 1:02 pm
Thanks for post about Pharmaceuticals in our drinking water!
April 29, 2020 at 9:29 am
fullhdfilmizlesene
April 30, 2020 at 6:09 pm
It’s excellent . its unique
April 30, 2020 at 6:09 pm
It’s excellent . its unique ئئئ
May 6, 2020 at 10:30 am
I will bookmark your blog in future as reference
May 8, 2020 at 3:17 am
It’s excellent . its unique
May 8, 2020 at 1:36 pm
É um ótimo site. O Design parece muito bom. Continue trabalhando assim !. hot blue caps
May 10, 2020 at 7:09 am
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
May 10, 2020 at 7:10 am
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!