Skip to content
Gopi Suresh edited this page Feb 7, 2018 · 1 revision

Building a 2 Wheeled Car

An easy way to familiarize yourself with RoCo and it's interface is through building a car. If you haven't already, check out the docs on RoCo's Electrical and Code Interface to learn about how the interface works.

Design

  1. Our 2 wheeled car only has 2 wheels.
  2. To control each of those wheels, we will be using a Servo motor.
  3. In order to add Servo Motors to our robot, we will be using the DrivenServo Component from the library.
  4. Since the servo motors need to be controlled by code, we will need a microprocessor to execute the code and relay instructions to the servos.
    • For this example, we will be using a Node MCU but the process using any other microcontroller is identical.
  5. The Driven Servo components need to be told how fast to drive, and which pin on the servo they will get this information from.
  6. In order to tell the Driven Servo component how fast to turn, we will use a Constant Component
    • The constant component always outputs a specified constant.
  7. Since in the car, the servos will be facing different directions, in order to make the car move in a straight line, both servos will need to turn in opposite directions at the same speed.

Implementation

  1. To make a Car, we will be using only the Composite Component interface.
  2. Name the component.
  3. Drag in 2 Driven Servo Blocks from the Electrical category and name them. Make sure that the names are different.
  4. Drag in 2 Constant blocks from the Code category, name them, and set the num parameter to the speed that you want the car to travel at.
    • The speed is an integer between -90 and 90, where 90 is the fastest it will go in the forward direction, 0 is rest, and -90 is the fastest it will go in reverse.
    • Make sure that the num parameters in both constant blocks are opposites e. g. 30 and -30, or 40 and -40.
    • This would have created a new category "Blocks" in the sidebar. In this category, there will be a subcategory with the name of the Constant components.
  5. These menus contain stubs which represent the output of the Constant blocks, a constant number. Drag these stubs into the "inInt" input in the Driven Servos.
  6. Drag in a Node MCU and name it.
    • In the "Blocks" category in the sidebar, there will be a subcategory with the name of the NodeMCU component.
    • Within this menu will be a number of blocks representing the pins which can be used as outputs from the microprocessor.
  7. Choose 2 arbitrary pins from this list and drag them to the PWM inputs in the Driven Servo Components. This assigns an input pin for the servo motors.
  8. You have successfully created a car!!! Click the export button in the bottom right corner to generate the Arduino code that will drive the car.
  9. Open the file in the Arduino IDE, compile it, and export to the car.

Clone this wiki locally