A-Star 32U4 Robot Controller, DC Motors and a Servo

Hello everyone!

So this is gonna be a long one. As my personal project I’m trying to build a 4WD Robot roughly the size of a A4 paper. I’ve successfuly setup the A-Star 32U4 Robot Controller SV with Raspberry Pi 3 (running Raspbian) and I was able to run 4x 6V 20D motors (also from pololu) via the control panel that comes with it. I’m using external LiPo battery, everything mounted on DIY robot chassis. Everything is updated to v1.0.1, so is the RPi.

Since I want to add other functionalities to the robot and by that I mean 2 additional servos for cameras mounted on top, I’ve tried to analyse the original code. By taking baby steps, I’ve first added another checkbox, which when pressed, activates LED on pin13 through digitalWrite(13, HIGH), instead of just using AStar32U4 Arduino library. It worked.

Now, I’ve tried running a small Tower Pro Micro Servo 9g that usually comes with Arduino starter packs. Again, to the original control panel I’ve added a checkbox (why not a button? It was easier to just take existing lines of code from LEDs and modify them) which when pressed, activates the Servo.h Sweep example sequence and repeats it until I uncheck the radio button.

I’ve used pin11 (PWM), GND and for the power I’ve used an Arduino UNO’s 5V power pin. Also, please note, you have to modify the ServoTimer.h file from Servo.h library (details here).


1.) Needless to say, it worked, but not the way I’ve imagined. It’s impossible to run a servo simultaneously with the DC motors. To move the servo, the robot has to be still. Maybe to someone more adept, this was obvious from the start. Now to my question, is there an option or a workaround to be able to drive the robot and move the camera’s servo at the same time?

2.) Everytime I’ve tried to move on, to controling two servos instead of just one, meaning, I’ve tried to incorporate two checkboxes instead of one (one for each direction of rotation of the one servo), I’ve got a blank and unresponsive control panel - no values displayed. I’m pretty sure I’m doing something wrong in the coresponding a star.py or script.js code.
In trial and error I’ve found out, that everytime I tried to add another, let’s say, def servo_motor() inside a_star.py class, everything went haywire: the analog monitor displayed 5 digit values, so did the battery monitor, LED checkboxes lighted up wrong colors compared to original code, joystick when pressed, just ran a random forward/backward sequence on random—so, everything was mixed up. It was either that or the blank control panel.
To my second question: how can I safely add more functions to the a_star.py, script.js, server.py etc. ? In regard of the attached code, how would I add another checkbox and control steering the servo left and right? The problematic part is inside script.js, a_star.py and server.py. The HTML and Arduino code I think I could manage.

3.) Is the A-Star 32u4 capable of runing this servo. I’d use only PWM outputs. The power would be sourced from elsewhere.

4.) If I use a button instead of checkbox, how do I check if the button is pressed with JQuery? I’ve tried this, but the control panel was simply blank, so no results.

It was a real pain in the a**, because I had no prior knowledge of Javascript, I2C, HTML, however I am familiar with C and Python. So basically I’ve started here from scratch and please excuse any amateur mistakes in the code.
The code that runs the servo’s back and forth sequence through a checkbox is added below. Also, I’ve attached the code where I tried to have two checkboxes, one for steering the servo left, and the other for right.


Hopefully someone can help me, since I’d really like to finish this project. It’s getting frustrating, but it motivates me even more.

Thanks in advance,

ziga004

Servo_sequence_code_working.rar (4.9 KB)
Left_right_control_not_working.rar (4.9 KB)

Hello,

Thanks for sharing your code on the forum; this is a better place to help you with debugging, since it’s easier to share code and for others to see what you are doing. I recommend getting set up with GitHub if you aren’t already, since it will make it possible to link directly to your code and the changes that made things stop working. Git is also great for syncing changes between your Raspberry Pi and the computer running the Arduino environment. As an example, I unpacked your working/non-working RAR files and put them into GitHub as a sequence of commits:

Looking at your questions, it sounds like you are trying to do a lot of different things at the same time, and I would recommend just focusing on 1 and 2 for now.

For question 1, I am sorry that it’s a pain to get servos working on the A-Star Robot Controller! As we say in the page that you linked to, if you make the library changes you should be able to run servos and motors at the same time. Can you prepare the simplest possible example demonstrating the problem and paste the actual code here or into GitHub? It should be a single Arduino file, maybe 10 or 15 lines long. Please also say what happens with and without the library change that you made - if there’s no difference maybe your changes were not applied successfully.

For question 2, from looking at the changes in GitHub it seems like you changed a whole bunch of things at the same time, so it’s impossible to see what caused the problem. I don’t see any obvious mistakes, but the problem could be anything from a Javascript browser-specific bug, to a power problem, to simply not having the right code loaded at the right time. I recommend starting with the working code and changing no more than one or two lines at a time to figure out what is going on. For example: first add a new servo variable to the end of the array in AStarRPiSlaveDemo.ino, and try it out without changing your Python code or using that variable anywhere. Then move the variable into the position where you want it and verify that when you try to use it the Python code for motors, etc. stops working. Then fix the addresses of those things in Python and verify that they start working again. Then try writing to the new variable to see if that breaks anything, and so on. If you eventually run into trouble, you can tell us exactly which change caused the problems.

It will also be a lot easier to debug if you make small demo programs like blink.py and beep.py and don’t try to do anything with the web interface until you have those working.

-Paul