test_encoders.cpp
Go to the documentation of this file.
1 /* Encoder Library - TwoKnobs Example
2  * http://www.pjrc.com/teensy/td_libs_Encoder.html
3  *
4  * This test code can be used to manually check the encoders.
5  * Turn the wheels by hand and check the output in the serial monitor.
6  */
7 
8 // Include unity library
9 // For details see https://docs.platformio.org/en/latest/plus/unit-testing.html#api
10 #include <unity.h>
11 
12 #include <ros.h>
13 #include "diffbot_base_config.h"
14 #include "encoder_diffbot.h"
15 
16 
17 // ROS node handle
19 
20 // Encoder setup
21 // Change these pin numbers to the pins connected to your encoder.
22 // Best Performance: both pins have interrupt capability
23 // Good Performance: only the first pin has interrupt capability
24 // Low Performance: neither pin has interrupt capability
27 // avoid using pins with LEDs attached
28 
29 void setup() {
30  Serial.begin(115200);
31  Serial.println("DiffBot Wheel Encoders:");
32  Serial.println("Trun wheels by hand to check for correct encoder output.");
33 }
34 
35 long positionLeft = -999;
36 long positionRight = -999;
37 
38 int test_start_time = millis();
39 int test_max_time = 8000;
40 
41 void loop() {
42  UNITY_BEGIN();
43  long newLeft, newRight;
44  newLeft = encoderLeft.read();
45  newRight = encoderRight.read();
46  if (newLeft != positionLeft || newRight != positionRight) {
47  Serial.print("Left = ");
48  Serial.print(newLeft);
49  Serial.print(", Right = ");
50  Serial.print(newRight);
51  Serial.println();
52  positionLeft = newLeft;
53  positionRight = newRight;
54  }
55  // if a character is sent from the serial monitor,
56  // reset both back to zero.
57  if (Serial.available()) {
58  Serial.read();
59  Serial.println("Reset both wheel encoders to zero");
60  encoderLeft.write(0);
62  UNITY_END();
63  }
64 
65  if (millis() - test_start_time > test_max_time)
66  {
67  UNITY_END();
68  }
69 }
70 
71 
diffbot_base_config.h
loop
void loop()
Definition: test_encoders.cpp:41
ENCODER_RIGHT_H1
#define ENCODER_RIGHT_H1
Definition: diffbot_base_config.h:10
positionLeft
long positionLeft
Definition: test_encoders.cpp:35
ENCODER_RESOLUTION
#define ENCODER_RESOLUTION
Definition: diffbot_base_config.h:8
ros.h
test_start_time
int test_start_time
Definition: test_encoders.cpp:38
ENCODER_LEFT_H2
#define ENCODER_LEFT_H2
Definition: diffbot_base_config.h:5
ENCODER_LEFT_H1
#define ENCODER_LEFT_H1
Encoder pins.
Definition: diffbot_base_config.h:4
ENCODER_RIGHT_H2
#define ENCODER_RIGHT_H2
Definition: diffbot_base_config.h:11
encoderRight
diffbot::Encoder encoderRight(nh, ENCODER_RIGHT_H1, ENCODER_RIGHT_H2, ENCODER_RESOLUTION)
diffbot::Encoder::read
int32_t read()
Read the current encoder tick count.
Definition: encoder_diffbot.h:89
positionRight
long positionRight
Definition: test_encoders.cpp:36
test_max_time
int test_max_time
Definition: test_encoders.cpp:39
setup
void setup()
Definition: test_encoders.cpp:29
diffbot::Encoder::write
void write(int32_t p)
Set the encoder tick count.
Definition: encoder_diffbot.h:97
diffbot::Encoder
Decorates the Teensy Encoder Library to read the angular wheel velocity from quadrature wheel encoder...
Definition: encoder_diffbot.h:35
nh
ros::NodeHandle nh
Definition: test_encoders.cpp:18
encoderLeft
diffbot::Encoder encoderLeft(nh, ENCODER_LEFT_H1, ENCODER_LEFT_H2, ENCODER_RESOLUTION)
encoder_diffbot.h
ros::NodeHandle


diffbot_base
Author(s):
autogenerated on Thu Sep 7 2023 02:35:23