-
Notifications
You must be signed in to change notification settings - Fork 2
Car
Gopi Suresh edited this page Feb 7, 2018
·
1 revision
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.
- Our 2 wheeled car only has 2 wheels.
- To control each of those wheels, we will be using a Servo motor.
- In order to add Servo Motors to our robot, we will be using the DrivenServo Component from the library.
- 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.
- The Driven Servo components need to be told how fast to drive, and which pin on the servo they will get this information from.
- 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.
- 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.
- To make a Car, we will be using only the Composite Component interface.
- Name the component.
- Drag in 2 Driven Servo Blocks from the Electrical category and name them. Make sure that the names are different.
- 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.
- 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.
- 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.
- 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.
- 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.
- Open the file in the Arduino IDE, compile it, and export to the car.