Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 Hanson Robokind LLC.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.robokind.impl.motion.dynamixel;
 
 import java.util.Map;
Represents a Dynamixel servo in a Dynamixel chain.

Author(s):
Matthew Stevenson <www.robokind.org>
 
 public class DynamixelServo extends AbstractServo<
         DynamixelServo.Id,
         ServoConfig<DynamixelServo.Id>,
         DynamixelController> {
 	private final Map<RegisterIntegermyCache;
 	private Boolean myIsChanged;
     private DynamixelServo.Id myPhysicalId;
     private int myMinPosition;
     private int myMaxPosition;
     private int myPreviousPosition;
     private String myName;
     private FeedbackUpdateValues myFeedbackUpdateVals;

    
Creates a new DynamixelServo from the given JointConfig and DynamixelController.

Parameters:
params JointConfig for the new Joint
controller DynamixelController for the new Joint
 
     public DynamixelServo(ServoConfig<DynamixelServo.IdparamsDynamixelController controller){
         super(paramscontroller);
          = params.getServoId();
         
          = false;
          = new HashMap();
          =
                 new FeedbackUpdateValues(
                         vals, TimeUtils.now());
          = vals[0];
          = params.getMinPosition();
          = params.getMaxPosition();
         double defInt = params.getDefaultPosition() - ;
         double range =  - ;
         double val = defInt/range;
         if(!NormalizedDouble.isValid(val)){
             throw new IllegalArgumentException("Default Position invalid: " + 
                     params.getDefaultPosition());
         }
          = new NormalizedDouble(val);
          = params.getName();
 	}
     
     public final DynamixelServo.Id getPhysicalId(){
         return ;
     }
     
     @Override
     public void setEnabled(Boolean enabled){
         Boolean old = getEnabled();
         setTorqueEnabled(enabled);
         firePropertyChange(oldenabled);
     }
 
     @Override
     public Boolean getEnabled(){
         return getTorqueEnable();
     }
 
     @Override
    public String getName() {
        return ;
    }
    @Override
    public int getMinPosition() {
        return ;
    }
    @Override
    public int getMaxPosition() {
        return ;
    }
    
    protected int getPreviousPosition(){
        return ;
    }
    
    protected void setPreviousPosition(int pos){
         = pos;
    }
    @Override
        return ;
    }

    
Returns the value at the given register.

Parameters:
reg register to read
Returns:
value at the given register
    public Integer get(Register reg){
			return -1;
		return .get(reg);
	}
    
Sets the value of a given register.

Parameters:
reg register to set
value value to set
    protected void put(Register regInteger value){
        .put(regvalue);
    }
    @Override
    public void setGoalPosition(NormalizedDouble value){
        super.setGoalPosition(value);
        Integer goal = getAbsoluteGoalPosition();
        if(goal == null){
            return;
        }
        SetRegisterValue(.goal);
    }

    
Returns the moving speed as a value 1(slow) - 1023(fast), with 0 being full speed.

Returns:
moving speed as a value 1(slow) - 1023(fast), with 0 being full speed
    public Integer getMovingSpeed(){
	}
    
Sets the moving speed with a value 1(slow) - 1023(fast), and 0 being full speed.

Parameters:
value moving speed value; 1(slow) - 1023(fast), and 0 being full speed
    public void setMovingSpeed(Integer value){
	}
    //TODO support multiple Alarm LED ErrorStatuses
    
Returns the ErrorStatus which triggers the Alarm LED.

Returns:
ErrorStatus which triggers the Alarm LED
    public ErrorStatus getAlarmLed(){
	}
    
Sets the ErrorStatus which triggers the Alarm LED.

Parameters:
value ErrorStatus to triggers the Alarm LED
    public void setAlarmLed(ErrorStatus value){
	}
    //TODO support multiple Alarm Shutdown ErrorStatuses
    
Returns the ErrorStatus which triggers a servo shutdown.

Returns:
ErrorStatus which triggers a servo shutdown
    public ErrorStatus getAlarmShutdown(){
	}
    
Sets the ErrorStatus which triggers a servo shutdown.

Parameters:
value ErrorStatus to triggers a servo shutdown
    public void setAlarmShutdown(ErrorStatus value){
	}

    
Returns the BaudRate expected by the DynamixelServo.

Returns:
BaudRate expected by the DynamixelServo
    public DynamixelBaudRate getBaudRate(){
		return DynamixelBaudRate.get((byte)GetRegisterValue(.).intValue());
	}
    
Sets the BaudRate expected by the DynamixelServo

Parameters:
value BaudRate to be expected by the DynamixelServo
    public void setBaudRate(DynamixelBaudRate value){
	}

    

Returns:
    public Integer getCcwAngleLimit() {
	}

    

Parameters:
value
    public void setCcwAngleLimit(Integer value) {
	}

    

Returns:
    public Integer getCwAngleLimit() {
	}

    

Parameters:
value
    public void setCwAngleLimit(Integer value) {
	}

    

Returns:
    public Integer getCcwComplianceMargin() {
	}

    

Parameters:
value
    public void setCcwComplianceMargin(Integer value) {
	}

    

Returns:
    public Integer getCwComplianceMargin() {
	}

    

Parameters:
value
    public void setCwComplianceMargin(Integer value) {
	}

    

Returns:
    public Integer getCcwComplianceSlope() {
	}

    

Parameters:
value
    public void setCcwComplianceSlope(Integer value) {
	}

    

Returns:
    public Integer getCwComplianceSlope() {
	}

    

Parameters:
value
    public void setCwComplianceSlope(Integer value) {
	}

    

Returns:
    public Integer getCurrentLoad() {
	}

    

Returns:
        double min = .getMinPosition();
        double max = .getMaxPosition();
        Double range = max - min;
        Double abs = getCurrentPositionAbs() - min;
        Double pos = Utils.bound(abs/range, 0.0, 1.0);
        return new NormalizedDouble(pos);
	}
    
Returns the absolute position of the Dynamixel between 0-1023

Returns:
absolute position of the Dynamixel between 0-1023
    public Integer getCurrentPositionAbs() {
	}

    

Returns:
    public Integer getCurrentSpeed() {
	}

    

Returns:
    public Integer getCurrentTemperature() {
	}

    

Returns:
    public Integer getCurrentVoltage() {
	}

    

Returns:
    public Boolean getTorqueEnable() {
	}

    

Parameters:
value
    public void setTorqueEnabled(Boolean value) {
	}

    

Returns:
    public Integer getFirmwareVersion() {
	}
     /*public void setPhysicalId(Integer value) throws Throwable {
		if ( ( value < 0 || value >= DynamixelController.BROADCAST_ID ) ) {
			throw new Exception("Value must be in the range 0 to 253");
		}
		if ( value.equals(getPhysicalId()) ) {
			return;
		}
		myController.writeRegister(getPhysicalId(), Register.Id, value, false);
	}*/

    

Returns:
    public Boolean getLed() {
		return GetRegisterValue(.) != 0;
	}

    

Parameters:
value
    public void setLed(Boolean value) {
		SetRegisterValue(.value ? 1 : 0);
	}

    

Returns:
    public Boolean getLock() {
	}

    

Returns:
    public Integer getTemperatureLimit() {
	}

    

Parameters:
value
    public void setTemperatureLimit(Integer value) {
	}

    

Returns:
    public Integer getMaxTorque() {
	}

    

Parameters:
value
    public void setMaxTorque(Integer value) {
	}

    

Returns:
    public float getHighVoltageLimit() {
		return (float) (GetRegisterValue(.)/10.0);
	}

    

Parameters:
value
    public void setHighVoltageLimit(float value) {
	}

    

Returns:
    public float getLowVoltageLimit() {
		return (float) (GetRegisterValue(.)/10.0);
	}

    

Parameters:
value
    public void setLowVoltageLimit(float value) {
	}

    

Returns:
    public Integer getModelNumber() {
	}

    

Returns:
    public Boolean getMoving() {
	}

    

Returns:
    public Integer getPunch() {
	}

    

Parameters:
value
    public void setPunch(Integer value) {
	}

    

Returns:
    public Boolean getRegisteredInstruction() {
	}

    

Parameters:
value
    public void setRegisteredInstruction(Boolean value) {
	}

    

Returns:
    public Integer getReturnDelay() {
	}

    

Parameters:
value
    public void setReturnDelay(Integer value) {
	}

    

Returns:
    public Integer getStatusReturnLevel() {
	}

    

Parameters:
value
    public void setStatusReturnLevel(Integer value) {
	}

    

Returns:
    public Integer getTorqueLimit() {
	}

    

Parameters:
value
    public void setTorqueLimit(Integer value) {
	}

    
Resets the DynamixelServo to the default factory settings. WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! USE THIS METHOD WITH CAUTION. THIS WILL CAUSE THE JOINT'S PHYSICAL ID AND BAUD RATE TO CHANGE. This method should not be used with robots from HansonRobokind as it will cause the Joint to stop functioning properly. This is included only to provide complete Dynamixel functionality for use in other applications.

Returns:
true if successful
    protected synchronized boolean reset(){
//		myController.writeInstruction(getPhysicalId(), Instruction.Reset, null);
//		return !myController.readPacket((byte)0).hasError();
        return false;
	}

    

Parameters:
reg
Returns:
    protected Integer GetRegisterValue(Register reg){
		switch (reg){
				return get(reg);
		}
		if (!reg.isCached()){
        }
		Integer v = get(reg);
		if (v == -1){
			v = get(reg);
		}
		return v;
	}

    
Sets the value for the given Register.

Parameters:
reg Register to set
value value to set
    protected synchronized void SetRegisterValue(Register regInteger value){
		if(reg.isSynchronized()){
            put(regvalue);
             = true;
            return;
		}else if (!reg.isCached()){
			.writeRegister(getPhysicalId(), regvaluefalse);
			return;
		}
		Integer v = get(reg);
		if (v == value)
			return;
		.writeRegister(getPhysicalId(), regvaluefalse);
		put(regvalue);
	}

    
Reads all Registers for the DynamixelServo and updates the cache.
    public synchronized void cacheValues(){
		Register[] regs = Register.values();
		for (Integer i = 0; i < regs.lengthi++){
			put(regs[i], values[i]);
		}
	}
    
    //TODO fix Dynamixel register caching updates.
    
Returns true if Register values have been changed.

Returns:
true if Register values have been changed
    public boolean changed(){
        return ;
    }
    
    public final static class Id implements LocalIdentifier{
        private final static int theIdCount = 254;
        private int myPhysicalJointId;        
        
        
Creates the Broadcast Id
        Id(){
             = ;
        }
        
Creates a JointId from the given integer id.

Parameters:
id the jointId
        public Id(int id){
            if(!isValidId(id)){
                throw new IllegalArgumentException("PhysicalId out of range.");
            }
             = id;
        }
        
        
Returns the integer value of the Id.

Returns:
the integer value of the Id
        final public int getIntValue(){
            return ;
        }
        
        @Override
        public boolean equals(Object obj){
            if(obj == null || obj.getClass() != this.getClass()){
                return false;
            }
            return  == 
                    ((Id)obj).;
        }
        
        
Returns true is the id would make a valid Id.

Parameters:
id value to check
Returns:
true is the id would make a valid Id.
        public static boolean isValidId(int id){
            return id >= 0 && id < ;
        }
        
        @Override
        public int hashCode() {
            return HashCodeUtil.hash(.);
        }
        @Override
        public String toString() {
            return "" + ;
        }
    }
    
    public void setFeedbackVals(FeedbackUpdateValues vals){
        if(vals == null){
            return;
        }
         = vals;
    }
New to GrepCode? Check out our FAQ X