Skip to content

Latest commit

 

History

History
187 lines (107 loc) · 9.2 KB

SERIAL-CONTROL.md

File metadata and controls

187 lines (107 loc) · 9.2 KB

P2-BLDC-Motor-Control - Via Serial from RPi, Arduino, or...

Serial control of our Single and Two-motor driver objects P2 Spin2/Pasm2 for our 6.5" Hub Motors with Universal Motor Driver Board

Project Maintenance

License

The Project

Instead of using the FlySky for remote control this document describes how to use a 2-wire serial interface to control your P2 hardware on your robot platform.

The code for this project implements an active serial receiver running on the P2 and a top-level application which listens for drive/status commands arriving via serial and then forwards the requests to the 2-wheel steering system and sends responses back over serial to the host.

Current status

Latest Changes:

04 May 2022 v2.0.0
- Initial Public Release of Serial support

Table of Contents

On this Page:

Additional pages:


System Diagram

The following diagram shows the top-level serial object which hands off commands to the drive subsystem as they are received. It also shows the nested motor control and sense subsystem comprised of the two objects: steering and motor control.

Motor Control System Diagram

In this diagram there are five rectangular objects depicting files (yellow background) of code. There are three methods within the motor files (white and green backgrounds) that are run in separate cogs and there is one method (white background) within the serial files that runs in a separate cog. The arrows attempt to show which objects interact with each other and also show with which object the user application can interact. The gear icon indicates which are running in their own Cog. You can see that the users' top-level control application runs in its own Cog as well.

Video of author running the system: Control our 2-wheel BLDC robot platform from an RPi @ youtube

Download the project files

Head to the BLDC Motor repository releases page and download the serial-control-archive-set.zip file from the Assets section of the latest release. (only present in v2.0.0 and later releases)

Create a working directory and unpack this .zip there. In this .zip file you'll find an archive (.zip) of the P2 project files you need and a pythonSrc.zip of RPi side files you need. We'll use all of these files in later steps. Meanwhile, let's setup your RPi.

Configuring your RPi

Set up for your RPi is nearly the same as we did for setting up the RPi for P2 IoT Gateway use.

But, first, if you are configuring a bare new RPi then do: Setting up your 1st Raspberry Pi

If you have a well setup RPi and just need to configure it for use in this contect then do the following...

First install extra packages the script needs:

Packages for Ubuntu, Raspberry pi OS, and the like

sudo apt-get install git python3 python3-pip python3-tzlocal python3-sdnotify python3-colorama python3-unidecode python3-paho-mqtt python3-watchdog

Finish the project install on the RPi

You need to select a location to install your platform-drive python script.

If you were installing in say your home directory/projects/ it might look something like this:

cd<return>  # insure you are in home directory

mkdir -p ~/projects/platform-drive    # make new directory (inclu. ~/projects/ if it doesn't exist)

cd ~/projects/platform-drive

Head back to the folder where you unpacked the serial-control-archive-set.zip file. Let's unpack the pythonSrc.zip file found within. Now copy the files from the newly created ./pythnSrc folder into this new directory on your RPi. One if the files should be a requirements.txt file and the other should be the demo script P2-BLDC-Motor-Control-Demo.py. Finish up your system prep by ensuring the files needed for you drive script are installed with the following commands:

cd ~/projects/platform-drive            # make sure we are where the new files arrived
sudo pip3 install -r requirements.txt   # install supporting files

Wiring the Serial Connection

The P2-BLDC-Motor-Control-Demo.py script is built to use the main serial I/O channel at the RPi GPIO Interface. These are GPIO pins 14 & 15 (header pins 8 & 10).

NOTE: FYI a good reference is: pinout diagram for RPi GPIO Pins

RPi Wiring for Daemon use:

RPi Hdr Pin# RPi GPIO Name RPi Purpose P2 Purpose P2 Pin #
6 GND Signal ground Signal ground GND near Tx/Rx Pins
8 GPIO 14 Uart Tx Serial Rx (from RPi) 57
10 GPIO 15 Uart Rx Serial Tx (to RPi) 56

Pick two pins on your P2 dev board to be used for RPi serial communications. The top-level file provided by this project defines these two pins as 56, 57. This was due to the two motor control boards occupying most of the remaining pins on the Mini Edge Breakout board. Feel free to choose different pins. Just remember to adjust the constants in your code to use your pin choices.

Flashing your P2 Edge

The code for this project is setup for the P2 Mini Edge Breakout board with the two BLDC motor controllers installed at each of the dual-header locations. This leave one single header where you just connected the serial wires from the RPi.

Head back to the folder where you unpacked the serial-control-archive-set.zip file. Let's unpack the *archive.zip file found within.

In the subfolder just created locate the isp_steering_serial.spin2 file. Using Propeller tool select this file as our top-level file then compile and download to FLASH.

NOTE: this top-level file isp_steering_serial.spin2 contains all pin-mappings. If you are not set up as the demo specified then make your pinout changes here before you flash the code.

This should be all you need to test your new installation. The demo file will drive the motors as if the platform is driving in a square (drive straight, turn right, drive strait, turn right, etc.)

You can test by running the following command on your RPi:

cd ~/projects/platform-drive            # make sure we are your project files are
./P2-BLDC-Motor-Control-Demo.py -d -v   # run with debug and verbose messaging enabled

If this is working for you, congratulations, you are all set up and ready to do your own drive code!

Developing your own drive code

On your RPi copy the P2-BLDC-Motor-Control-Demo.py file to your own name:

cd ~/projects/platform-drive                        # make sure we are your project files are
cp /P2-BLDC-Motor-Control-Demo.py {newName}.py      # create new copy

Do all your development in this new file. Start by replacing the sqaure-pattern drive code with your own.

Have fun!

...


If you like my work and/or this has helped you in some way then feel free to help me out for a couple of ☕'s or 🍕 slices!

coffee    -OR-    PatreonPatreon.com/IronSheep


Disclaimer and Legal

Parallax, Propeller Spin, and the Parallax and Propeller Hat logos are trademarks of Parallax Inc., dba Parallax Semiconductor


License

Licensed under the MIT License.

Follow these links for more information: