Biorobotics Project / Motor_with_encoder

Dependencies:   HIDScope

Dependents:   Project_motor Project_motor Motor_poscontrol Conceptcontroller_v_1_0

Fork of Encoder by Biorobotics Project

Embed: (wiki syntax)

« Back to documentation index

Encoder Class Reference

Encoder Class Reference

Encoder class. More...

#include <encoder.h>

Public Member Functions

 Encoder (PinName int_a, PinName int_b, bool speed=false)
 Create Encoder instance.
int32_t getPosition ()
 Request position.
void setPosition (int32_t pos)
 Overwrite position.

Data Fields

float m_speed
 Request speed.

Detailed Description

Encoder class.

Used to read out incremental position encoder. Decodes position in X2 configuration.

Speed estimation is very crude and computationally intensive. Turned off by default

Example:

 #include "mbed.h"
 #include "Encoder.h"

   Encoder motor1(PTD0,PTC9,true);
   Serial pc(USBTX,USBRX);
   pc.baud(115200);
   while(1) {
       wait(0.2);
       pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
   }

Definition at line 25 of file encoder.h.


Constructor & Destructor Documentation

Encoder ( PinName  int_a,
PinName  int_b,
bool  speed = false 
)

Create Encoder instance.

Parameters:
int_aPin to be used as InterruptIn! Be careful, as not all pins on all platforms may be used as InterruptIn.
int_bsecond encoder pin, used as DigitalIn. Can be any DigitalIn pin, not necessarily on InterruptIn location
speedboolean value to determine whether speed calculation is done in interrupt routine. Default false (no speed calculation)

Definition at line 5 of file encoder.cpp.


Member Function Documentation

int32_t getPosition (  )

Request position.

Returns:
current position in encoder counts

Definition at line 38 of file encoder.h.

void setPosition ( int32_t  pos )

Overwrite position.

Parameters:
posposition to be written

Definition at line 45 of file encoder.h.


Field Documentation

float m_speed

Request speed.

Returns:
current speed

Definition at line 49 of file encoder.h.