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.

23 Comments

  1. Sebagai platform penyedia link slot gacor terpercaya, ALEXISTOGEL hadir untuk memenuhi permintaan para member setia dalam bermain game slot online gacor. Salah satu kelebihan ALEXISTOGEL adalah menyediakan informasi seputar situs permainan slot hoki terbaik yang sedang gacor hari ini. Dengan begitu, anda dapat dengan mudah menemukan dan bergabung dengan provider slot terkini yang sedang populer. Segera daftarkan diri anda di ALEXISTOGEL untuk mendapatkan akses ke berbagai permainan slot online uang asli yang jamin gacor dan terbukti terpercaya.

  2. Manisqq merupakan agen bandar judi online terbaik dan juga sebagai situs penyedia games taruhan bandar domino qq online terpercaya yang menyediakan semua games pkv online fair play hanya dengan bergabung di manisqq login daftar sekarang juga dapatkan pengalaman bermain judi taruhan kartu online yang seru dan membawa kemenangan.

  3. Manisqq merupakan agen bandar online terbaik dan juga sebagai situs penyedia games taruhan bandar domino qq online terpercaya yang menyediakan semua games pkv online fair play hanya dengan bergabung di manisqq login daftar sekarang juga dapatkan pengalaman bermain judi taruhan kartu online yang seru dan membawa kemenangan.

  4. Selamat datang di situs resmi bandar togel online pasaran singapore terpercaya, Alexistogel. Kami merupakan salah satu bandar togel online terbesar dan terpopuler di Indonesia yang menyediakan berbagai macam permainan togel online, seperti Togel Singapore. Dengan pengalaman yang luas dalam industri perjudian togel, Alexistogel berkomitmen untuk memberikan pengalaman bermain yang aman, nyaman, dan menyenangkan bagi seluruh member. Kami senantiasa memprioritaskan kepuasan pelanggan dan integritas dalam setiap layanan yang kami berikan.

  5. I appreciate you supplying this very helpful knowledge. As a writer by trade, I’ve seen that students nowadays are really interested in what they’re supposed to be writing. You should ask an expert to do my assignment as this is the most effective method. An assignment writer is a professional with experience in writing excellent, thoroughly researched academic papers on a range of topics.

  6. Saat ini, banyak pilihan situs bandar togel online yang tersedia di internet. Namun, tidak semua situs togel online yang beredar di pasaran merupakan situs yang resmi dan terpercaya. Saat ini, salah satu situs togel online yang banyak diminati oleh para pecinta judi togel online adalah Alexistogel. Situs ini menawarkan berbagai keunggulan, termasuk layanan yang cepat dan aman, serta pilihan permainan togel yang lengkap dan menarik. Dengan reputasi yang baik dan pengalaman yang luas dalam industri perjudian online, Alexistogel menjadi pilihan yang tepat bagi para pemain togel yang mencari situs terpercaya untuk bertaruh.

  7. Sebagai situs slot88 terpercaya, Alexistogel menawarkan pengalaman bermain slot online yang maksimal kepada para pemain di Indonesia. Dengan RTP slot gacor mencapai 99%, Alexistogel memastikan peluang kemenangan yang tinggi bagi seluruh pejudi slot entusiasme.

    Didukung dengan lebih dari 100 game slot berkualitas tinggi dari provider ternama seperti Pragmatic Play, Habanero, PG Soft, Spadegaming, CQ9, dan Joker Gaming, Alexistogel menawarkan ragam pilihan game slot yang menarik dan menghibur untuk setiap pecinta slot di Indonesia.

  8. To pay your bill, simply visit healow pay and log into your account. Navigate to the ‘Payments’ section where you can view outstanding charges.

  9. The website https://j4l.com/blog/ukrainian/ukrainian-brides offers a fascinating insight into the world of Ukrainian brides. With its comprehensive blog posts and articles, it serves as a valuable resource for anyone interested in learning more about Ukrainian brides and their unique cultural traditions. From dating tips to personal stories, this site covers a wide range of topics that are sure to captivate readers. Whether you’re considering marrying a Ukrainian bride or simply curious about their way of life, this website provides a wealth of information to satisfy your curiosity. Explore the enchanting world of Ukrainian brides through this engaging platform.

  10. Impressive DIY project! Controlling brushed DC motors with a Logitech gamepad and custom Arduino/VC++ software is a great achievement. Your protocol sedgwick claims for passing commands and handling gamepad input is well-explained. Looking forward to seeing the demo and future autonomous control developments!

  11. Selamat datang di Alexistogel situs bandar togel yang memiliki lisensi resmi dari 79 lebih pasaran toto online di berbagai negara termasuk Indonesia. Alexistogel menyediakan berbagai jenis permainan togel dengan pembayaran tinggi dan proses penarikan dana yang cepat. Anda dapat dengan mudah mendaftar dan bergabung bersama kami untuk menikmati pengalaman bermain togel yang aman dan terpercaya.

  12. Online diyet, internet üzerinden yürütülen ve genellikle kişiye özel beslenme planlarını içeren bir diyet programıdır. Bu tür diyetler, beslenme uzmanları veya diyetisyenler tarafından sunulan çevrimiçi platformlar aracılığıyla uygulanabilir.

  13. Thank you, Thank You, Thank you, I needed this article for a while and I am happy to stumble upon it.

  14. With 2024 around the corner, investors are evaluating different mutual fund options to optimize their portfolios. Two prominent investment avenues—Gold Mutual Funds and Manufacturing Mutual Funds—offer unique opportunities, but choosing between them requires a clear understanding of their characteristics and benefits. So, how do these funds stack up for 2024?
    Gold Mutual Funds
    Manufacturing Mutual funds

  15. El Wordle ha esdevingut un fenomen mundial, i la seva versió en català

  16. Indonesian news portal Post is an online media platform that provides news coverage with a focus on Indonesian and international topics. The site covers a wide range of subjects, including sports, culture, and politics. It aims to share timely news and information, with an emphasis on providing insight and updates on both domestic and global events.

    The website uses SSL encryption to secure data exchange, but some reports suggest that it operates with hidden ownership details, which could raise concerns about transparency. Additionally, it has a relatively low web traffic ranking, which could be attributed to its status as a smaller or emerging platform.

  17. Thank you for the update on the Sawbot project! If you’re ever in Guildford and need a reliable wheelchair taxi guildford, check out the services from Wizz Cars for safe and comfortable transportation options.

  18. Fryd Extracts is revolutionizing the world of disposable vapes with its commitment to providing an exceptional vaping experience. Fryd delivers premium products through a meticulous extraction process for those who demand convenience and quality, ensuring every puff is smooth, potent, and flavorful. Fryd’s commitment to quality is unmatched. They source the best cannabis oil and balance terpenes and cannabinoids carefully, ensuring maximum effect.

  19. Good article, keep it for future reference, thank you.

Leave a Reply

Your email address will not be published.

© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑