peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
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 /*
27  Strings that set RS160D motor controllers to PWM mode
28 */
29 #define SETLEFTPWM "@0sm1\r"
30 #define SETRIGHTPWM "@1sm1\r"
31 
32 /*
33  Strings that set RS160D motor controllers to bo controlled over
34  serial. Need to be set for ANY computer control.
35 */
36 #define SETLEFTSERIAL "@0sj0\r"
37 #define SETRIGHTSERIAL "@1sj0\r"
38 
39 /*
40  Default BAUD rate for RS160D motor controllers.
41  This rate can be changed in RS160D registers.
42 */
43 #define BAUDRATE 38400
44 
45 struct RS160Ds {
46  int m_fdFront;
47  int m_fdRear;
48 };
49 
50 /*
51  Function opens serial comunication with set port.
52  (No actual communication with RS160D controllers in this function,
53  USB->Serial adapters must be attached for success)
54  Needs to be passed: Dev address (/dev/ttyUSB0 ....)
55  and a descriptor to modify/fill
56  Returns: 0 on success and -1 on failure (0 or -1)
57 */
58 int RS160DOpenConnection(const char *Dev, int *Descriptor);
59 
60 /*
61  Function sets RS160D controllers to be controlled via serial
62  Needs to be passed: File descriptors 1 at a time.
63  Returns: 0 on Success, -1 on Failure
64 */
65 int RS160DSetToSerial(int Descriptor);
66 
67 /*
68  Function updates the speed of a single wheel./
69 // TODO: get speed,
70 // TODO: encoder value
71 // TODO: ...
72 //
73  Needs to be passed: A speed (-250 < speed < 250), a file descriptor,
74  and a motor (0 = left, 1 = right)
75  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
76 */
77 int RS160DUpdateMotorSpeeds(int Speed, int Descriptor, int Side);
78 
79 
80 /*
81  Function changes how agressively each individual motor brakes.
82  Needs to be passed: A brake rate (0 < Braking < 31: 31 = full brake),
83  a file descriptor, and a motor)
84  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
85 */
86 int RS160DAlterBraking(int Braking, int Descriptor, int Side);
87 
88 
89 /*
90  Function changes how agressively each individual motor changes dirrection.
91  Needs to be passed: A slew rate (0 < slew < 90: 0 = immediate change),
92  a file descriptor, and a motor)
93  Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
94 */
95 int RS160DAlterSlew(int Slew, int Descriptor, int Side);
96 
97 
98 /*
99  E-Stop Function to lock up all wheels ICE
100  Needs to be passed: Both descriptors.
101 */
102 void RS160DEStop(int DescriptorFront, int DescriptorRear);
103 
104 /*
105  Closing function to release a connection to a device.
106 */
107 int RS160DClose(int Descriptor);
108 
109 #endif