Example: Simple Joystick-Drive Robot: Difference between revisions

From RoboPad Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 37: Line 37:


The nodegraph for this example can be downloaded [https://yelllowcube.sharepoint.com/:u:/s/BlayzeTechLimited/EctL76vbaS5HupqStJggtA8BuB2ThmnzbZDuQlYE2ZUg0g?e=57FshM here]. The IO Configuration can be found [https://yelllowcube.sharepoint.com/:u:/s/BlayzeTechLimited/EdDMS4fiFFNBk0XiUJGwuLEB8vUZF1rG9RE07kyvFVDZIw?e=jLDhIO here].
The nodegraph for this example can be downloaded [https://yelllowcube.sharepoint.com/:u:/s/BlayzeTechLimited/EctL76vbaS5HupqStJggtA8BuB2ThmnzbZDuQlYE2ZUg0g?e=57FshM here]. The IO Configuration can be found [https://yelllowcube.sharepoint.com/:u:/s/BlayzeTechLimited/EdDMS4fiFFNBk0XiUJGwuLEB8vUZF1rG9RE07kyvFVDZIw?e=jLDhIO here].
Using a joystick node opens up a lot of real estate on your screen and (since it's a single-finger input), gives you the chance to add additional controlls on the screen. It's the perfect input mode to use alongside a [[Slider Node]] to drive a [[IO Config Editor#Servo Motor|Servo]] as a lifter for your robot.

Revision as of 02:44, 21 August 2024

NOTICE: This page consists of information on a feature currently in Beta. Information is liable to change or be incomplete.

While a tank-drive robot is the most simple type of robot that you can make with a RoboPad, many people want to control both drive motors of a simple two-motor robot with a single Joystick. This page aims to give you a walk-through of building a robot that can be driven in this manner.

The nodegraph from this example can be found here.

The IO Configuration can be found here.

Hardware

Tank drive robots have only two actuators: A left drive motor and a right drive motor, both attached to a wheel. After attaching your power supply to the "+" and "-" pins, it simply requires that two motors be soldered - one each to the M1 and M2 pin pairs on the RoboPad.

IO Configuration

In order to tell the RoboPad that there are two motors attached, you will need to configure the IO Units on the device. The RoboPad has special IO Units available for drive motors called "Built-in H-Bridge Motor" units. These use the internal H-bridges to drive the motors forwards and backwards:

With two "Built-in H-Bridge Motor" IO Units added, you can control up to two motors attached to the RoboPad on the "M1" and "M2" pins.


They allow you tot set a "Forward Scale" and a "Reverse Scale" for each, which lets you change how fast the attached motors spin when told to go all the way forward or backward, which is useful for tuning a robot if it's not driving straight when you tell it to go forward or backward, or just to slow it down if forward or backwards is too fast. They should be there by default, and if not you can add them with the "Add" menu at the top of the IO Configuration page.

Nodegraph Configuration

By adding the H-Bridge Motor IO Units, the Chip Node in the Nodegraph Editor gains 2 new inputs and 2 new outputs:

The Chip Node gets a pair of "<motor name> armed" output and "<motor name>" inputs, allowing you to drive the motors and get their status.

The two input ports - here named "M1" and "M2" (because that's the name of each motor in the IO Configuration) - drive each motor. They expect values between 0 and 1, with 0 being "full reverse" and 1 being "full forward". The two outputs - here named "M1 armed" and "M2 armed" - indicate whether the motors are armed. The concept of actuator arming can feel a little complex, but it is important because without it the chance of accidentally driving a motor is much higher: any actuator is considered "armed" once the actuator has recieved a drive signal corresponding to it's "safe state" (see the Tank Drive example for more information on this - in this example, we assume knowledge of arming mechanics, and include armed status indicators).

In order to drive the motors M1 and M2, we will employ the use of a Joystick Node and a Joystick Mixer Node. By default the Joystick Node outputs two values: The position of the "stick" within the joystick in terms of it's X and Y position, between 0 and 1. We could hook this directly up to the M1 and M2 inputs if we wanted to:

A badly-connected joystick nodegraph that will cause incorrect motor drive.

However, this would result in moving the joystick left and right driving one wheel (if M1 is connected to it as in this example, the left wheel) only of the robot, and moving it vertically drives the other (here, the right):

A very difficult to drive robot.

In this case, driving the robot is very difficult. In the example above, moving the stick to the top right results in the robot moving forward, and the top left has it just spinning counter-clockwise in-place. We need some kind of mixing so that moving the stick up makes the robot move forwards, down backwards and left and right makes it turn left and right variably. Fortunately, that's what the Joystick Mixer Node is for:

A properly mixed joystick node.

Now the robot should drive something more like this:

When a joystick mixer node is used, the robot will drive forward when the joystick is moved upwards, and turn left and right as the joystick is moved left and right.

While this is still a relatively simple control scheme, it can still be a little confusing, especially if you decide to make any changes to the output of the Joystick Node before they go into the mixer node. In this case Indicator Nodes can be very useful as they can be configured to display a value directly which can help you debug your nodegraph. In the final version of this example configuration, we use two to indicate whether the motors have been armed:

Here we have connected two indicators to tell us if and when the drive motors are armed.


The nodegraph for this example can be downloaded here. The IO Configuration can be found here.

Using a joystick node opens up a lot of real estate on your screen and (since it's a single-finger input), gives you the chance to add additional controlls on the screen. It's the perfect input mode to use alongside a Slider Node to drive a Servo as a lifter for your robot.