Multiple Winch Servos on same controller issues
Page 1 of 1

Author:  willishf [ Sat Jan 24, 2015 9:59 am ]
Post subject:  Multiple Winch Servos on same controller issues

Using two servo winch motors on a single servo controller to operate an arm. Running into a race condition that we think we have figured out based on the RobotC API for controlling servos and now looking for a work around that will require custom programming of I2C messages. Opened a support case with RobotC and basically they do not support program control of the PWM flag that would allow you turn on/off the servo. We need this feature as a kill switch if the arm gets stuck to avoid it breaking servos. Basically once you turn on a servo no way to put it in neutral. Got code back from support that gives the ability to do this. However, it appears you can then only have a single servo controller on a port where we need to be able to address multiple servo controllers on the same port. From the specs the address is 02/03, 04/05 etc but do not see that as an option in sendI2CMsg so this solution won't work.

What we have now discovered after being able to map how the robotc api works to the behavior of the robot is a race condition when setting the first servo position. When you set servo position 1 the PWM flag is enabled and all servos get turned on where because you only set the first value the other servos begin moving to their "default" value. If the home position of the other servo is not near the "default" value then you get initial movement until your code has time to set the second servo value. It appears the servo controller then steps through those positions from the "default" value to the home value you are sending.

What is needed is the ability to set all servo positions on the controller during initialization where you can control the PWM flag as being off. Then any subsequent code that moves a single servo will not have any movement effects on the other servos that are in their mechanical home position.

Would be great to have RobotC api control of the PWM flag to set it off, set servo values, set it on. This would also allow a kill switch option for a particular servo controller in case of mechanical failure. Considering the cost of the winch servos and the power this would be a big help.

Any example code on using sendI2CMsg to update a particular servo controller based on its address?

// nPort is the sensor port that the servo controller is connected to.
void disableServos(const tSensors nPort) {
char msg[] = { 0x03, 0x04, 0x48, 0xFF };
sendI2CMsg(nPort, &msg[0], 0);

// nPort is the sensor port that the servo controller is connected to.
// num is the servo port number on the controller
// posistion is the desired servo position (0-255)
void setServoPosition(const tSensors nPort, ubyte num, ubyte position) {
ubyte reg = 0x41 + num;
char msg[] = { 0x03, 0x04, reg, position };
sendI2CMsg(nPort, &msg[0], 0);

Author:  FTC_359 [ Sat Jan 24, 2015 12:58 pm ]
Post subject:  Re: Multiple Winch Servos on same controller issues

We have made a header to access the basic functions for motor and servo controllers. We have never needed to add more functionality to the header because it was really only needed for our HTC Tester. However, if you need to access the full functionality of the controllers, I can add the API in for them when I have time or teach you how to interact utilizing the I2C interface.

I think that the easiest way to do it now would first be to find a way to allow the API to interact; perhaps using SensorType[S1] = sensorI2CCustom. I have honestly not tried doing this before, but here is some example code that *might* work:

#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Motor,  mtr_S1_C1_1,     leftWheel,     tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     rightWheel,    tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     intake,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C3_2,     lift,          tmotorTetrix, openLoop, reversed)
#pragma config(Servo,  srvo_S1_C2_1,    dragger,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    scorer,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)

#include "HTC.h"

#define DRAGGER     servo_S1_C2_1
#define SCORER        servo_S1_C2_2

bool shutoff = false;
ubyte dragger_pos = DRAGGER_UP;
ubyte scorer_pos = SCORER_CLOSE;

task updateServos(){
     ubyte prevDragger_pos = 0;
     ubyte prevScorer_pos = 0;
                 if(prevDragger_pos != dragger_pos){
                      SensorType[S1] = sensorI2CCustom;
                      HTSCServo(S1, DRAGGER, dragger_pos, reset_timeout);
                      SensorType[S1] = Hubs; //IDK!
                 if(prevScorer_pos != scorer_pos){
                     SensorType[S1] = sensorI2CCustom;
                     HTSCServo(S1, SCORER, scorer_pos, reset_timeout);
                     SensorType[S1] = Hubs; //IDK!

task main()
     dragger_pos = 255;
     scorer_pos = 30;
          shutoff = true;
          HTSCServo(S1, DRAGGER, dragger_pos, force_timeout); //I think that if I ever update this, I'm going to make the timeout command separate -_-

Remember that you cannot even send ONE command to the servo controller through RobotC's API or else none of this will work.

All the best,

Author:  willishf [ Sat Jan 24, 2015 1:06 pm ]
Post subject:  Re: Multiple Winch Servos on same controller issues

Thanks for the code reference!

Author:  FTC_359 [ Sat Jan 24, 2015 1:19 pm ]
Post subject:  Re: Multiple Winch Servos on same controller issues

Do note that the PWM flag affects the entire servo controller, meaning that if you force the timeout, all servos attached to said controller will lose power.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group