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.
May 10, 2020 at 9:15 am
E vizite uygulama girişi ve SGK vizite girişi hakkında detaylar ssksor.com sayfamızda.
May 14, 2020 at 6:45 pm
Thank you for sharing this article with such good content. Good luck in the following article.
May 15, 2020 at 2:46 pm
Sawbot Update 2 – Snow Day Predictor – Today Updates For School Holiday
March 22, 2024 at 12:02 pm
You have a good blog. Can you do anything about all the spam comments? scrap car removal vancouver
May 28, 2020 at 1:39 am
Nice to see you readers! My name is Cameron Lake and I work as an essay author for learners at online writing service. One study tip that really helped with planning and accountability was to have pupils schedule study hours into their month, just like any other activity in their life. If you had a test one or two weeks, you would block three of four hours of studying time on your calendar each day leading up to the test. We also created schedules for a few months before finals and designated which subjects would be studied on which days based on the order of your final examinations. So, I recommend you to click on and discover here our beautiful service’s website and to buy essays online.
June 4, 2020 at 7:06 am
به جون تو که نباشی میخوام این دنیا نباشه
بدون تو بدون که زندگیم آخراشه
به جون تو که دلم طاقت دوریتو نداره
بدون تو میرسه به ته خط دلم دوباره
نمیشه که بری خاطره هاتو فقط بذاری نمیشه که به این راحتی بگی منو نداری
دانلود آهنگ جدید ماکان بند به جون تو
June 8, 2020 at 5:09 am
Skyrim Script Extender (SKSE) – SKSE 64 Install, Update With Vortex
June 9, 2020 at 5:45 am
How to Get Free Hulu Premium Accounts in 2020? (Working Accounts & Methods)
June 12, 2020 at 7:17 am
I think that it can be a good idea to read some HempWorx gummies reviews. It doesn’t take hours to look through. However, you can find something really noteworthy.
June 16, 2020 at 1:42 am
DC Motors are very simple to build. It generates more than 5v that’s why u kept 5v voltage regulator is it anyway it’s super cool.
June 21, 2020 at 7:03 am
Thank you for sharing this article with such good content. Good luck in the following article.
June 24, 2020 at 6:21 am
Thank you for your post. I think you can use C and Arduino IDE on linux. It’s eassy to code. No need to use C++ for programming Arduino.
June 25, 2020 at 2:49 pm
Your site is exactly what I have looking for it such a nice content. Thank you for sharing valuable information.
June 28, 2020 at 9:25 am
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);
this code is not working…kindly help
July 4, 2020 at 3:39 am
Find live NFL scores, pro football player & team news, NFL videos, rumors, stats, standings, team schedules & fantasy football games on FOX Sports.
July 20, 2020 at 10:38 pm
nice technology super valuable information thank you sir
July 21, 2020 at 3:32 am
To seek the best Life Science Writing Services for those studying biology coursework writing services, it is important to hire an award winning science paper writing service company.
July 21, 2020 at 3:32 am
To seek the best Life Science Writing Services for those studying biology coursework writing services, it is important to hire an award winning science paper writing service company.
July 24, 2020 at 3:32 am
Philosophy coursework writing service seekers have been on the rise lately since most learners need Philosophy Essay Writing Services, philosophy assignment writing services and philosophy research paper writing services.
July 25, 2020 at 8:36 am
I cannot thank you enough for helping me.
https://musictor.ir/new-song/
July 29, 2020 at 1:14 am
All things are very great that you have introduced us in this blog but I think these are useful for my
July 29, 2020 at 2:47 pm
It’s excellent . its unique
July 29, 2020 at 2:48 pm
thanks for sharing with us download
August 10, 2020 at 3:04 am
This is a good information blog. I am pretty much pleased with your good work.
August 17, 2020 at 3:41 pm
Thanks for sharing this method. I’m searching for it, and now I’m landing on the right page.
This is a beneficial method.
I have a tip for you. I’m searching for the solution of my homework, and I find Textsheet Alternative which help me to solve my homework so if you are facing any issue in your homework you should also visit Textsheet Alternative.
August 20, 2020 at 12:30 am
Click on any coupon of Beulah London on the promothecode website and enjoy shopping!
August 20, 2020 at 12:48 am
You can lie but I know that you’re not fine (oh yeah) Every time you talk You talk ’bout me but you swear I’m not on your mind You can pretend you don’t miss me (me) You can pretend you don’t care. tetris
August 20, 2020 at 12:54 am
skribbl io Everybody knows You and I are suicidal stolen art (oh yeah) Pretty moments sews Stitches into all your bitches broken hearts.
August 22, 2020 at 8:47 am
روشهای نوین و قانونی ماخذ اقامت اروپا از طریق تمکن مالی و ثبت شرکت بدون سرمایگذاری تحصیل رایگان فرزندان
EGHAMAT EUROPA
Nice Post! I am really thank you for sharing these sites here, GREAT JOB.
August 22, 2020 at 8:47 am
روشهای نوین و قانونی ماخذ اقامت اروپا از طریق تمکن مالی و ثبت شرکت بدون سرمایگذاری تحصیل رایگان فرزندان
EGHAMAT EUROPA
Nice Post! I am really thank you for sharing these sites here, GREAT JOB1.
August 31, 2020 at 2:47 am
یونیت هیتر یا واحد گرمایشی، دستگاهی تک فصل (گرمایشی) است. قطعات اصلی دستگاه یونیت هیتر شامل موتور و پروانه، کویل یا کوره حرارتی و بدنه دستگاه است.
September 4, 2020 at 2:55 am
What I read from the forum is very good. I am looking for your content. That helps me improve my website.geometry dash
September 18, 2020 at 2:37 am
I think that thanks for the valuabe information and insights you have so provided here. Play animal crossing with me!
September 25, 2020 at 12:40 am
With every breath
And all the choices that we make run 3
September 30, 2020 at 7:41 am
good Forumdan okuduklarım çok güzel
October 8, 2020 at 5:20 am
tanx for post
http://webcity.ir/
October 23, 2020 at 6:32 am
We offer the best of relationship advice, tips, and Updates
October 23, 2020 at 9:04 am
Chinese Evergreen Plant
The Chinese evergreen is the common name used for a collection of plants from the Aglaonema genus – which tend to tolerate low light conditions very well.
Aglaonemas will produce flowers (these are not very showy), but they’re grown primarily for the attractive leathery leaves.
Description
Picture of the Chinese evergreen
There are many hybrid varieties of the Chinese evergreen available which have been cultivated over the last century. This is because of their increasing popularity for indoor growers to use them as ornamental plants for room decoration.
These slow growing plant varieties includes, plain green, speckled, blotched and variegated types. One of the most popular and sought after is the silver queen which has leaves covered in silver mainly with some small green patches.
November 7, 2020 at 5:52 pm
Stages Of Relationship You should know Today
November 7, 2020 at 5:55 pm
Top 8 Relationship Rules For Partners
November 15, 2020 at 10:12 pm
good job!
December 5, 2020 at 5:41 am
7 days detox hakında bilmedikleriniz.
December 5, 2020 at 5:41 am
7 days detox hakında bilmedikleriniz. neler neler
December 5, 2020 at 6:34 am
7 days detox nedir, 7 days detoksu
December 19, 2020 at 4:49 am
قیمت حوله خشک کن ها براساس تعداد لوله های رادیاتور حوله ای محاسبه می شوند و به طور کلی قیمت حوله خشک کن در مدل های آلومینیومی کمتر از مدل های فولادی و استیل موجود در بازار می باشد.
December 22, 2020 at 12:37 pm
I would like to recommend you to contact edubirdie review if you need a written work. Here you will write a work of any complexity, any volume. I myself have ordered in total about ten works in the past year. I received all of them in time and at best.
December 27, 2020 at 7:08 pm
Eğitim ve sağlık hakkında tamamen özgün ve güncel bilgiler sunuyoruz. Maaşları, ne iyi gelir.
#maaşları #neiyigelir
https://saglik-sozlugu.com
December 27, 2020 at 7:09 pm
Eğitim ve sağlık hakkında tamamen özgün ve güncel bilgiler sunuyoruz. Maaşları, ne iyi gelir.
#maaşları #neiyigelir
https://saglik-sozlugu.com
December 29, 2020 at 8:06 am
Thanks for this great post, I really loved reading your blog. I find it very interesting and very well thought out and put together. I just hope that you keep it going on later on as well. Cheers!
December 29, 2020 at 8:07 am
Thank you for another informative blog. Where else could I get that type of info written in such a perfect approach? I have an undertaking that I’m simply now working on, and I’ve been on the lookout for such information.
January 3, 2021 at 10:06 am
hank you for another informative blog. Where else could I get that type of info written in such a perfect approac
ทางเข้า slotxo