Kuon  1.1.3
RoadNarrows Robotics Large Outdoor Mobile Robot Project
RS160DControl.h
1 /*
2  Title: Header file for serial control of RS160D motor controller
3  Author: Rob Shiely & Robin Knight
4  Date: 10/12/2011
5  TODOs: Need functions to get speed, encoder values,.. etc from controllers
6 */
7 #ifndef _RS160DControl_H
8 #define _RS160DControl_H
9 
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <sys/ioctl.h>
13 #include <limits.h>
14 #include <fcntl.h>
15 #include <termios.h>
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdarg.h>
20 #include <time.h>
21 #include <errno.h>
22 #include <string.h>
23 #include "rnr/serdev.h"
24 #include "rnr/log.h"
25 
26 C_DECLS_BEGIN
27 
28 //
29 // Limits and Ids
30 //
31 #define RS160D_MOTOR_LEFT_ID 0 ///< left motor id
32 #define RS160D_MOTOR_RIGHT_ID 1 ///< right motor id
33 #define RS160D_MOTOR_AUX_ID 2 ///< auxilliary id
34 
35 #define RS160D_MOTOR_SPEED_MIN (-249) ///< min speed value = max reverse speed
36 #define RS160D_MOTOR_SPEED_MAX 249 ///< max speed value = max forward speed
37 #define RS160D_MOTOR_BRAKE_MIN 0 ///< min brake value = coasting
38 #define RS160D_MOTOR_BRAKE_MAX 31 ///< max brake value = max braking
39 #define RS160D_MOTOR_SLEW_MIN 0 ///< min pwr slew value = quickest ramp up
40 #define RS160D_MOTOR_SLEW_MAX 90 ///< max pwr slew value = slowest ramp up
41 
42 /*
43  Strings that set RS160D motor controllers to PWM mode
44 */
45 #define SETLEFTPWM "@0sm1\r"
46 #define SETRIGHTPWM "@1sm1\r"
47 
48 /*
49  Strings that set RS160D motor controllers to bo controlled over
50  serial. Need to be set for ANY computer control.
51 */
52 #define SETLEFTSERIAL "@0sj0\r"
53 #define SETRIGHTSERIAL "@1sj0\r"
54 
55 /*
56  Default BAUD rate for RS160D motor controllers.
57  This rate can be changed in RS160D registers.
58 */
59 #define BAUDRATE 38400
60 
61 struct RS160Ds {
62  int m_fdFront;
63  int m_fdRear;
64 };
65 
66 /*
67  Function opens serial comunication with set port.
68  (No actual communication with RS160D controllers in this function,
69  USB->Serial adapters must be attached for success)
70  Needs to be passed: Dev address (/dev/ttyUSB0 ....)
71  and a descriptor to modify/fill
72  Returns: 0 on success and -1 on failure (0 or -1)
73 */
74 int RS160DOpenConnection(const char *Dev, int *Descriptor);
75 
76 /*
77  Function sets RS160D controllers to be controlled via serial
78  Needs to be passed: File descriptors 1 at a time.
79  Returns: 0 on Success, -1 on Failure
80 */
81 int RS160DSetToSerial(int Descriptor);
82 
83 /*
84  Function updates the speed of a single wheel.
85  Needs to be passed: A speed (-250 < speed < 250), a file descriptor,
86  and a motor (0 = left, 1 = right)
87  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
88 */
89 int RS160DUpdateMotorSpeeds(int Speed, int Descriptor, int Side);
90 
91 
92 /*
93  Function changes how agressively each individual motor brakes.
94  Needs to be passed: A brake rate (0 < Braking < 31: 31 = full brake),
95  a file descriptor, and a motor)
96  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
97 */
98 int RS160DAlterBraking(int Braking, int Descriptor, int Side);
99 
100 
101 /*
102  Function changes how agressively each individual motor changes dirrection.
103  Needs to be passed: A slew rate (0 < slew < 90: 0 = immediate change),
104  a file descriptor, and a motor)
105  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
106 */
107 int RS160DAlterSlew(int Slew, int Descriptor, int Side);
108 
109 
110 /*
111  E-Stop Function to lock up all wheels ICE
112  Needs to be passed: Both descriptors.
113 */
114 void RS160DEStop(int DescriptorFront, int DescriptorRear);
115 
116 /*
117  Closing function to release a connection to a device.
118 */
119 int RS160DClose(int Descriptor);
120 C_DECLS_END
121 #endif