I post some of my code. Commands continue to be delivered at fixed intervals.
When the green LED is blinking, the motor operates normally.
But, the greenLED stays on, the motor does not run. (command continue)
Again I say, I would like to know the difference between the blinking state and steady state of the greenLED.
If the motor is temporarily not running for 10-30 seconds while the greenLED stays on, the greenLED will return to blinking, then motor start running.
So I think the It is problem that greenLED stays on. I wonder If it result from timing or high load.
Also, When controlling the motor through the maestro center, there is a situation where the force is released to the motor if it is applied a weak force.
Please answer this too.
Answer whether there is a situation where the motion is released when the motor is moved to a position. This situation can be thought of as a different situation, but this also remains greenLED on. Check it.
// Main Source
setInterval(function(){
console.log('one');
exec('servo speed all 20 40 50 20 20 10 20 40 50 20');
exec('servo accelerate all 10 10 10 10 10 10 10 10 10 10');
exec('servo multitarget 0 0 0 0 0 0 0 0 0 0');
setTimout(function(){
console.log('two');
exec('servo speed all 20 40 50 20 20 10 20 40 50 20');
exec('servo accelerate all 10 10 10 10 10 10 10 10 10 10');
exec('servo multitarget 50 0 200 100 200 100 50 0 200 100');
}, 200);
}, 400);
//servo.c
int SetMultiTarget(int fd, int* pTarget)
{
int idx = 0;
int length = (3 + (20)) * sizeof(unsigned char);
unsigned char* command = (unsigned char*) malloc(length);
memset(command, 0, length);
command[idx++] = 0x9F;
command[idx++] = 10;
command[idx++] = 0;
for (int ch = 0;ch < 10;ch++)
{
unsigned short max = (1500 + motor_range[ch]) * 4;
unsigned short min = (1500 - motor_range[ch]) * 4;
unsigned short target = (unsigned short)((motor_pos[ch] + motor_offset[ch] + 1500)* 4);
if(target > max){
target = max;
printf("Warn > Target value change to [%d]:%d\n", ch, motor_range[ch]);
}
if(target < min){
target = min;
printf("Warn > Target value change to [%d]:%d\n", ch, 0 - motor_range[ch]);
}
command[idx++] = target & 0x7F;
command[idx++] = target >> 7 & 0x7F;
}
if (write(fd, command, length) == -1)
{
printf("error writing");
return -1;
}
free(command);
command = NULL;
return 0;
}
int SetSpeed(int fd, unsigned char channel, unsigned short speed)
{
unsigned char command[] = {0x87, channel, (unsigned char)(speed & 0x7F), (unsigned char)(speed >> 7 & 0x7F)};
if (write(fd, command, sizeof(command)) == -1)
{
printf("error writing");
return -1;
}
return 0;
}
int SetAcceleration(int fd, unsigned char channel, unsigned short value)
{
unsigned char command[] = {0x89, channel, (unsigned char)(value & 0x7F), (unsigned char)(value >> 7 & 0x7F)};
if (write(fd, command, sizeof(command)) == -1)
{
printf("error writing");
return -1;
}
return 0;
}
...
int main(){
int` `fd = open(device, O_RDWR | O_NOCTTY);
...
switch(argv[1][0])
{
case 'm':
{
int* pPos = (int *) malloc(sizeof(int)*10);
memset(pPos, 0, sizeof(int)*10);
for(i = 0; i < 10;i++)
{
pos = atoi(argv[i+2]);
pPos[i] = pos;
}
SetMultiTarget(fd, pPos);
free(pPos);
pPos = NULL;
break;
}
case 'a': // acceleration
{
if(!strncmp(argv[2], "a", 1)) // all
{
for (i = 0; i < 10; i++)
SetAcceleration(fd, i, atoi(argv[i+3]));
}
else
{
channel = atoi(argv[2]);
SetAcceleration(fd, channel, atoi(argv[3]));
usleep(5000);
}
break;
}
case 's': // speed
{
if(!strncmp(argv[2], "a", 1)) // all
{
for (i = 0; i < 10; i++)
SetSpeed(fd, i, atoi(argv[i+3]));
}
else
{
channel = atoi(argv[2]);
SetSpeed(fd, channel, atoi(argv[3]));
usleep(5000);
}
break;
}
...
}