I have bought a Low-Voltage Dual Serial Motor Controller
I have tried to control this controller with C++ program, but the motor runs discontinuously.
How should I modify my program in order to make the motor runs continuously and also control the motor duration?
#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitionss
#include <time.h> // time calls
void sleep(unsigned int mseconds)
clock_t goal = mseconds + clock();
while (goal > clock());
int fd; //File descriptor for the port
struct termios termios_p; /*termios structure*/
fd = open("/dev/ser2", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
// Could not open the port
perror("open_port: Unable to open /dev/ser1 - ");
printf ("port opened\n");
/*set the baud rate, parity etc for the port */
tcgetattr(fd, &termios_p); /*read in the current settings*/
termios_p.c_cflag &= ~PARENB;
termios_p.c_cflag &= ~CSTOPB;
termios_p.c_cflag &= ~CSIZE;
termios_p.c_cflag |= CS8;
termios_p.c_cflag &=~ IHFLOW ;
termios_p.c_cflag &= ~OHFLOW ;
tcsetattr(fd, TCSANOW, &termios_p);
int ssc_move(int fd) // send data to SSC
unsigned char dcmotorconfig;
unsigned char dcmotor1;
dcmotor1 = 128;
dcmotor1 = 0;
dcmotor1 = 2;
dcmotor1 = 127;
int fd = open_port();
Please help me…
You are sending two commands:
128, 2, 1 will reconfigure the motor to respond to motor numbers 0 and 1. The documentation says very clearly that your motors should be disconnected when you do this because otherwise they will run briefly - and it is certainly a bad idea to configure it every time you run the program! Also, all dual serial motor controllers respond to numbers 0 and 1, so this configuration is not particularly useful.
128, 0, 2, 127 is a command to send motor 1 in reverse at full speed. Is that what happened?
If this does not clear up the problem for you, please describe exactly what you thought would happen and what did happen.
I know the program is sending two commands, and the second one is mainly controlling the speed and direction of the motor. What I wanna do is let the motor run continuously, because now the motor is running on and off.
what I want is running
but now it is running
＿ ＿ ＿ ＿
＿｜ ｜＿｜ ｜＿｜ ｜＿｜ ｜＿
Sorry - I said the thing about configuration incorrectly. The motors will not pulse briefly - as explained in the User’s Guide, they will continue to pulse until the board is reset so that the new configuration options can take effect. You did not say why you need to configure it at all, so please just remove the configuration section from your code, and it should work much better for you.
Thanks Paul. I can make my motor run smoothly now
but I have another problem that, I can use Motor 1 only but not motor 0
Do you have any sample code that I can control 2 motors please?
Okay, good. Try modifying the line “dcmotor1 = 2;” by changing the 2 to a 0. That will drive motor 0 in reverse. It sounds like you need to read the User’s Guide again and ask questions if there is something you do not understand. Page 8 in particular describes exactly how to send a speed command. Have you read that part?