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.
October 21, 2021 at 12:48 pm
http://hdtaraftartv4k.tk/
October 21, 2021 at 5:27 pm
https://hdtaraftartvgiris26.blogspot.com/
March 25, 2023 at 3:50 pm
Delightful topic it is.
March 25, 2023 at 3:52 pm
Delightful topic it is, but also get the most affordable plastic products, https://plasticproducts.pk/ of them which are so legit to get in best productivity reactively these days in all over the PAKISTAN.
October 22, 2021 at 1:26 am
I’m such a huge fan of yours! You have such great ideas for Vivid Seats code. Thank you so much!
March 25, 2023 at 3:53 pm
Delightful topic it is, but also get the most affordable plastic products, https://plasticproducts.pk/ of them which are so legit to get in best productivity reactively these days in all over the PAKISTAN.
October 26, 2021 at 7:30 am
hobitanit.com. The best website for free accounts, free premium account, promo codes and discount coupons.
October 26, 2021 at 7:32 am
hobitanit.com. Best website for promo codes, free accounts and discount codes.
October 31, 2021 at 10:57 pm
Dr.Y N Chaubey aims to provide the best of medical treatment and care to all his patients. We provide Asthma Allergy treatment,Lungs Specialist in lucknow,Best Chest Surgeon in Lucknow also provide a Lungs related problems.
November 14, 2022 at 5:21 am
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!
November 16, 2022 at 9:27 pm
I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information.
March 25, 2023 at 3:53 pm
Delightful topic it is, but also get the most affordable plastic products, https://plasticproducts.pk of them which are so legit to get in best productivity reactively these days in all over the PAKISTAN.
November 26, 2022 at 7:36 am
Hello, have a good day
Thank you for the article here, it was very useful and valuable for me. Thank you for the time and energy you give to us, the audience.
November 30, 2022 at 1:02 am
I am very impressed with the ideas you mentioned in this subway surfers article. I hope you keep this up and keep coming up with more unique articles.
December 8, 2022 at 4:00 am
Write For Us Digital Marketing is a digital marketing agency that specializes in SEO, PPC, Social Media Marketing and Content Marketing.
December 12, 2022 at 9:35 pm
This is no ordinary waffle. Waffle game is a highly entertaining game for all players who love word guessing games. You can play with any time. The game is unlimited so you can play multiple times a day without worry.
December 14, 2022 at 1:31 pm
When checking essay service reviews, you’ll notice that social proof is an important factor for students. This company managed to keep its reputation very high, ever since it was started working long ago. Contact us whenever you need help.
December 29, 2022 at 1:59 am
ufabet168 The most complete online gambling and is most popular in using the service UFABET direct website In Thailand and Asia, UFABET168 has been appointed by UFABET as the first place.Online football betting must apply for online football betting. only here football betting website entrance The best online football betting website, the most stable.
December 29, 2022 at 11:03 am
If you’ve ever wondered how to book airport parking in advance of your next trip, you’ve come to the right place. With the help of Parkobility, you can find and reserve parking near you in just a few clicks.Parkobility
December 29, 2022 at 11:03 am
If you’ve ever wondered how to book airport parking in advance of your next trip, you’ve come to the right place. With the help of Parkobility, you can find and reserve parking near you in just a few clicks.
January 18, 2023 at 4:23 am
Miami is a popular destination for cruise ship travelers, and there are many hotels near the cruise port that offer comfortable and convenient accommodations. Some popular options include the Travelodge by Wyndham Miami Bayside, Best Western Plus Atlantic Beach Resort, InterContinental Miami, and DoubleTree by Hilton Grand Hotel Biscayne Bay. These hotels offer amenities such as free WiFi, fitness centers, swimming pools, and breathtaking views of the city and ocean. Regardless of your budget or preferences, there’s a hotel in Miami that will suit your needs. With so many options to choose from, you’re sure to find the perfect hotel for your next cruise vacation.
January 18, 2023 at 4:25 am
Miami is a popular destination for cruise ship travelers, and there are many hotels near the cruise port that offer comfortable and convenient accommodations. Some popular options include the Travelodge by Wyndham Miami Bayside, Best Western Plus Atlantic Beach Resort, InterContinental Miami, and DoubleTree by Hilton Grand Hotel Biscayne Bay. These hotels offer amenities such as free WiFi, fitness centers, swimming pools, and breathtaking views of the city and ocean. Regardless of your budget or preferences, there’s a hotel in Miami that will suit your needs. With so many options to choose from, you’re sure to find the perfect hotel for your next cruise vacation.
January 18, 2023 at 5:55 am
Thanks for this great post. Waiting for the next post.
We would like to introduce to you something really great for you.
That is IT Support in Waltham Cross. Leading ICT Support company in London – Go Live UK.
Strategic IT Support ™ Team for the Construction and Financial Industries providing critical protection for computer networks and digital assets, Waltham Cross IT Support. IT Support and Services Waltham Cross, Cybersecurity services, IT Help desk, IT managed services, IT consultants.
Check out for more details.
https://it-company.goliveuk.com/it-support-in-waltham-cross/
January 18, 2023 at 5:57 am
Thanks for this great post. Waiting for the next post.
We would like to introduce to you something really great for you.
That is IT Support in Upminster. Leading ICT Support company in London – Go Live UK.
Strategic IT Support ™ Team for the Construction and Financial Industries providing critical protection for computer networks and digital assets, Upminster IT Support. IT Support and Services Upminster, Cybersecurity services, IT Help desk, IT managed services, IT consultants.
Check out for more details.
https://it-company.goliveuk.com/it-support-in-upminster/
January 18, 2023 at 5:59 am
Thanks for this great post. Waiting for the next post.
We would like to introduce to you something really great for you.
That is IT Support in Tilbury. Leading ICT Support company in London – Go Live UK.
Strategic IT Support ™ Team for the Construction and Financial Industries providing critical protection for computer networks and digital assets, Tilbury IT Support. IT Support and Services Tilbury, Cybersecurity services, IT Help desk, IT managed services, IT consultants.
Check out for more details.
https://it-company.goliveuk.com/it-support-in-tilbury/
January 18, 2023 at 6:01 am
Thanks for this great post. Waiting for the next post.
We would like to introduce to you something really great for you.
That is IT Support in Waltham Abbey. Leading ICT Support company in London – Go Live UK.
Strategic IT Support ™ Team for the Construction and Financial Industries providing critical protection for computer networks and digital assets, Waltham Abbey IT Support. IT Support and Services Waltham Abbey, Cybersecurity services, IT Help desk, IT managed services, IT consultants.
Check out for more details.
https://it-company.goliveuk.com/it-support-in-waltham-abbey/
January 18, 2023 at 6:03 am
Thanks for this great post. Waiting for the next post.
We would like to introduce to you something really great for you.
That is IT Support in Romford . Leading ICT Support company in London – Go Live UK.
Strategic IT Support ™ Team for the Construction and Financial Industries providing critical protection for computer networks and digital assets, Romford IT Support. IT Support and Services , Cybersecurity services, IT Help desk, IT managed services, IT consultants.
Check out for more details.
https://it-company.goliveuk.com/it-support-in-romford/
February 4, 2023 at 8:22 am
สล็อต818เกมออนไลน์มาแรง ได้เงินจริง 2023
February 5, 2023 at 11:25 am
SexyPG168 สล็อตเว็บตรง
February 14, 2023 at 9:48 pm
Thank you for your post. I have read through several similar topics! However, your article gave me a very special impression, unlike other articles. I hope you continue to have valuable articles like this or more to share with everyone!
February 19, 2023 at 2:17 pm
Prueba de pureza del arroz 2023 es un cuestionario basado en 100 preguntas de pureza diferentes relacionadas con la vida, ¡respóndelo con un simple Sí y No!
February 28, 2023 at 3:42 am
Thanks for sharing the knowledge and informative information.
March 8, 2023 at 3:28 am
I have read numerous articles on similar subjects! In contrast to other articles, yours left me with a distinct impression. I hope you will continue to share material of this caliber with the public.
March 13, 2023 at 1:23 am
Again, I appreciate the excellent article. Where else might anyone have such kind of information written in such an ideal way? My group and I are looking for this material for a presentation next week.
March 27, 2023 at 3:04 pm
All things are very great that you have introduced us in this blog but I think these are useful for my
https://arotano.onlc.fr/