Skip to content

This library is for the Encoder DC Servo Motor: RMCS220x.

Notifications You must be signed in to change notification settings

shashank3199/RhinoServo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version Tag

Introduction

This library is for the Encoder DC Servo Motor: RMCS220x (reference here).

Index

User guide

Downloading the library

It is suggested that you download the entire repository and then select this folder, so that you can enjoy the benifits of VCS like git. It makes it simpler to update the contents whenever patch fixes are done. You can simply open a terminal (or gitbash on windows), go to the folder where you want to save this repository and type the following command.

  git clone https://github.com/shashank3199/RhinoServo

Not recommended: You can download only this folder by clicking here

Using the library with Arduino

Move this folder into the arduino libraries folder on your PC. If you don't know where the libraries folder of your arduino is, you can click here.
Also, this Library makes use of the DebuggerSerial Library. For More Information on this, click here.

In order to use this library, you must do the following:

  • Include the header file RhinoServo.h (the RhinoServo library folder must be in your arduino libraries folder).
  • Create an object of class RhinoServo. You can pass the constructor parameters to initialize here itself, or leave it as a simple object declaration.
  • For SERIAL Mode: Initialize the Serial on which the Rhino is attached using the AttachRhino_Serial function.
  • For I2C Mode: Initialize the Rhino on I2C using the AttachRhino_Address function.

You may optionally initialize and attach a debugger serial as well (using debugger.Initialize function on the object). You can access the debugger using the debugger variable of the class.

Library Explanation

The Library uses the Rhino with the following Pin Out -

Image

Examples

Note: The Rhino Motors work on 9600 BaudRate.

RhinoSerial

This example show you to work with the Rhino using the RhinoServo library on Serial3.
File: ./examples/RhinoSerial/RhinoSerial.ino

We simply follow the following steps:

  1. Include library
  2. Create object
  3. Initialize Serials. RhinoServo on Serial3 and debugger on Serial. Keep in mind to match the baud rates.
  4. Initialize debugger. Name it Rhino.
  5. Then start a loop
    1. Use the Commands as described by the Comments.

    2. The Format for the Commands are -

      < Command Variable > < Parameter Value >
      Eg -
      "M450" : Moves the Motor to Encoder Value 450
      "m90" : Moves Relative to the Current Position by 90 Degrees.

    3. The Values will be printed by the Debugger Object.

  6. Re-run the loop
[0] > Debugger enabled
[1] > DebuggerSerial attached
[6827 DEBUG] $Rhino$ Encoder value Reset.
[13472 DEBUG] $Rhino$ Motor Moved to Position: 450
[18271 DEBUG] $Rhino$ Motor Moved Relative to the Old Position by: -45 Degrees.
[35073 DEBUG] $Rhino$ Motor Moved Relative to the Old Position by: 135 Degrees.
[42457 DEBUG] $Rhino$ Motor Moved to Position: 0
[53172 INFO] $Rhino$ Rhino I2C Address changed to: 31

RhinoI2C

This example show you to work with the Rhino using the RhinoServo library on I2C Communication.
File: ./examples/RhinoI2C/RhinoI2C.ino

We simply follow the following steps:

  1. Include library

  2. Create objects R1 and R2.

  3. Initialize Objects with their Respective Addresses (For finding I2C Addresses, connect via Serial mode First and Set the Addresses Or to check for the Existing Addresses use I2C Scanner). Debugger on Serial.

  4. Initialize debuggers. Name it Rhino 1 and Rhino 2.

  5. Then start a loop

    1. Use the Commands as described by the Comments.
    2. The Format for the Commands are -

    < Command > < motor_number > # < parameter_value >
    Eg -
    "M1#200" : Moves Motor 1 to Encoder Position 200.
    "m2#180" : Moves Motor 2 by 180 Deg Relative to Current Position. 3. The Values will be printed by the Debugger Object.

  6. Re-run the loop

[0] > Debugger enabled
[0] > DebuggerSerial attached
[1 INFO] $Rhino 1$ Rhino Attached on I2C Rhino Address: 31
[52] > Debugger enabled
[77] > DebuggerSerial attached
[111 INFO] $Rhino 2$ Rhino Attached on I2C Rhino Address: 32
[4111 DEBUG] $Rhino 1$ Encoder value Reset.
[10142 DEBUG] $Rhino 1$ Motor Moved to Position: 450
[17900 DEBUG] $Rhino 1$ Motor Moved Relative to the Old Position by: -90 Degrees.

RhinoSoftSerial

This example show you to work with the Rhino using the RhinoServo library on RhinoSerial on .
File: ./examples/RhinoSoftSerial/RhinoSoftSerial.ino

We simply follow the following steps:

  1. Include library
  2. Create object
  3. Create a Software Serial on Pins 10 and 11 named RhinoSerial. Set the RhinoServo object on RhinoSerial and debugger on Serial. Keep in mind to match the baud rates.
  4. Initialize debugger. Name it Rhino.
  5. Then start a loop
    1. Use the Commands as described by the Comments.

    2. The Format for the Commands are -

      < Command Variable > < Parameter Value >
      Eg -
      "M450" : Moves the Motor to Encoder Value 450
      "m90" : Moves Relative to the Current Position by 90 Degrees.

    3. The Values will be printed by the Debugger Object.

  6. Re-run the loop
[0] > Debugger enabled
[1] > DebuggerSerial attached
[6827 DEBUG] $Rhino$ Encoder value Reset.
[13472 DEBUG] $Rhino$ Motor Moved to Position: 450
[18271 DEBUG] $Rhino$ Motor Moved Relative to the Old Position by: -45 Degrees.
[35073 DEBUG] $Rhino$ Motor Moved Relative to the Old Position by: 135 Degrees.
[42457 DEBUG] $Rhino$ Motor Moved to Position: 0
[53172 INFO] $Rhino$ Rhino I2C Address changed to: 31

Developers guide

Library Details

Files in the Library

The files in the library are:

RhinoServo.h

This is the Header file and contains the Class Blueprint (Prototype).

RhinoServo.cpp

This file contains the Definition for the Class Member Functions Prototyped in the Header File.

README.md

The Description file containing details about the library. The file that you looking at right now.

Class Contents

Let's explore the contents of the class, but first, we also have literals defined for general purpose use (using #define). They are:

Name Value Purpose
MODE_SERIAL 0 Value passed to select Serial Mode of Operation.
MODE_I2C 1 Value passed to select I2C Mode of Operation.
Macro Name Purpose
DEGtoCOUNT(x) Converts Degrees Passed to Encoder Count Value

Let's explore the class now

Private members

Variables
  • int connection_mode: Mode for Rhino Operation.
  • Stream* Rhino_Serial: This is the Serial Line on which the Rhino operates.
  • uitn8_t Rhino_Address: This is the I2C Address for Communication to the Rhino.

Member functions

  • int read ( ) : To recieve values from the Rhino in the Respective Formats.
  • void toBytes (int val,int arr[] ) : Converts integer Values to corresponding Byte Format.

Public members

Members

Constructors

  • RhinoServo ( ) : Empty constructor for the class.
  • RhinoServo (int connection_mode ) : Constructor to set the Communication for the class.
  • RhinoServo (Stream* AttachedSerial ) : To attach a pre-initialized serial to the Rhino. This function calls the AttachRhino_Serial member function.
  • RhinoServo (uint8_t Rhino_Address ) : To attach the I2C Address for the Rhino. This function calls the AttachRhino_Address member function.

Member functions

  • void AttachRhino_Serial ( Stream* AttachedSerial ) : Attach Serial Line for the Rhino.
  • void AttachRhino_Address ( uint8_t Rhino_Address ) : Attach I2C Address to the Rhino.
  • void Set_Dir_Speed (int val ) : Set Direction and Speed for Constant Rotation (Values between -255 to +255).
  • void SetI2C_Address ( int val ) : Set I2C Address (Serial Mode Only).
  • void Set_P_Gain (int val ) : Set Proportional Gain term for PID Correction (Values between 0 to 32767).
  • void Set_I_Gain (int val ) : Set Integral Gain term for PID Correction (Values between 0 to 32767).
  • void Reset_Reference ( int val=0 ) : Set Encoder Value to a Specific Value (or Zero Value if not supplied with any Parameter).
  • void Reset ( ) : Resets the Rhino Motor to Factory Defaults.
  • void Moveto ( int val ) : Move to Encoder Position wrt Encoder Zero Position.
  • void MovetoRel ( int val ) : Move to Position Relative to Current Position.
  • int GetCurrent_Position( ) : Get Position Value from the Encoder.
  • int Get_P_Gain( ) : Get Proportional Gain value for the PID Correction.
  • int Get_I_Gain( ) : Get Integral Gain value for the PID Correction.
  • int GetI2C_Address( ) : Display Address of the Rhino (Serial Mode Only).

References

Developers Tag