mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
Removes CANJaguar from wpilib (#300)
Now located at https://github.com/wpilibsuite/CANJaguar.
This commit is contained in:
committed by
Peter Johnson
parent
29f999e2b2
commit
247cef5ec2
@@ -1,415 +0,0 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// can_proto.h - Definitions for the CAN protocol used to communicate with the
|
||||
// BDC motor controller.
|
||||
//
|
||||
// Copyright (c) 2008 Texas Instruments Incorporated. All rights reserved.
|
||||
// TI Information - Selective Disclosure
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef __CAN_PROTO_H__
|
||||
#define __CAN_PROTO_H__
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The masks of the fields that are used in the message identifier.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_FULL_M 0x1fffffff
|
||||
#define CAN_MSGID_DEVNO_M 0x0000003f
|
||||
#define CAN_MSGID_API_M 0x0000ffc0
|
||||
#define CAN_MSGID_MFR_M 0x00ff0000
|
||||
#define CAN_MSGID_DTYPE_M 0x1f000000
|
||||
#define CAN_MSGID_DEVNO_S 0
|
||||
#define CAN_MSGID_API_S 6
|
||||
#define CAN_MSGID_MFR_S 16
|
||||
#define CAN_MSGID_DTYPE_S 24
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Reserved device number values in the Message Id.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_DEVNO_BCAST 0x00000000
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Reserved system control API numbers in the Message Id.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_API_SYSHALT 0x00000000
|
||||
#define CAN_MSGID_API_SYSRST 0x00000040
|
||||
#define CAN_MSGID_API_DEVASSIGN 0x00000080
|
||||
#define CAN_MSGID_API_DEVQUERY 0x000000c0
|
||||
#define CAN_MSGID_API_HEARTBEAT 0x00000140
|
||||
#define CAN_MSGID_API_SYNC 0x00000180
|
||||
#define CAN_MSGID_API_UPDATE 0x000001c0
|
||||
#define CAN_MSGID_API_FIRMVER 0x00000200
|
||||
#define CAN_MSGID_API_ENUMERATE 0x00000240
|
||||
#define CAN_MSGID_API_SYSRESUME 0x00000280
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The 32 bit values associated with the CAN_MSGID_API_STATUS request.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_STATUS_CODE_M 0x0000ffff
|
||||
#define CAN_STATUS_MFG_M 0x00ff0000
|
||||
#define CAN_STATUS_DTYPE_M 0x1f000000
|
||||
#define CAN_STATUS_CODE_S 0
|
||||
#define CAN_STATUS_MFG_S 16
|
||||
#define CAN_STATUS_DTYPE_S 24
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Reserved manufacturer identifiers in the Message Id.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_MFR_NI 0x00010000
|
||||
#define CAN_MSGID_MFR_LM 0x00020000
|
||||
#define CAN_MSGID_MFR_DEKA 0x00030000
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Reserved device type identifiers in the Message Id.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_DTYPE_BCAST 0x00000000
|
||||
#define CAN_MSGID_DTYPE_ROBOT 0x01000000
|
||||
#define CAN_MSGID_DTYPE_MOTOR 0x02000000
|
||||
#define CAN_MSGID_DTYPE_RELAY 0x03000000
|
||||
#define CAN_MSGID_DTYPE_GYRO 0x04000000
|
||||
#define CAN_MSGID_DTYPE_ACCEL 0x05000000
|
||||
#define CAN_MSGID_DTYPE_USONIC 0x06000000
|
||||
#define CAN_MSGID_DTYPE_GEART 0x07000000
|
||||
#define CAN_MSGID_DTYPE_UPDATE 0x1f000000
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// LM Motor Control API Classes API Class and ID masks.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_MSGID_API_CLASS_M 0x0000fc00
|
||||
#define CAN_MSGID_API_ID_M 0x000003c0
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// LM Motor Control API Classes in the Message Id for non-broadcast.
|
||||
// These are the upper 6 bits of the API field, the lower 4 bits determine
|
||||
// the APIId.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define CAN_API_MC_VOLTAGE 0x00000000
|
||||
#define CAN_API_MC_SPD 0x00000400
|
||||
#define CAN_API_MC_VCOMP 0x00000800
|
||||
#define CAN_API_MC_POS 0x00000c00
|
||||
#define CAN_API_MC_ICTRL 0x00001000
|
||||
#define CAN_API_MC_STATUS 0x00001400
|
||||
#define CAN_API_MC_PSTAT 0x00001800
|
||||
#define CAN_API_MC_CFG 0x00001c00
|
||||
#define CAN_API_MC_ACK 0x00002000
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Control Voltage API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_VOLT \
|
||||
(CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_VOLTAGE)
|
||||
#define LM_API_VOLT_EN (LM_API_VOLT | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_VOLT_DIS (LM_API_VOLT | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_VOLT_SET (LM_API_VOLT | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_VOLT_SET_RAMP (LM_API_VOLT | (3 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_VOLT_T_EN (LM_API_VOLT | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_VOLT_T_SET (LM_API_VOLT | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_VOLT_T_SET_NO_ACK (LM_API_VOLT | (7 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
#define LM_API_VOLT_SET_NO_ACK (LM_API_VOLT | (8 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Control API definitions for LM_API_VOLT_SET_RAMP.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_VOLT_RAMP_DIS 0
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Control API definitions for CAN_MSGID_API_SYNC.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_SYNC_PEND_NOW 0
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Speed Control API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_SPD (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_SPD)
|
||||
#define LM_API_SPD_EN (LM_API_SPD | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_DIS (LM_API_SPD | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_SET (LM_API_SPD | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_PC (LM_API_SPD | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_IC (LM_API_SPD | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_DC (LM_API_SPD | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_REF (LM_API_SPD | (6 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_SPD_T_EN (LM_API_SPD | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_T_SET (LM_API_SPD | (8 << CAN_MSGID_API_S))
|
||||
#define LM_API_SPD_T_SET_NO_ACK (LM_API_SPD | (10 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
#define LM_API_SPD_SET_NO_ACK (LM_API_SPD | (11 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Control Voltage Compensation Control API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_VCOMP \
|
||||
(CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_VCOMP)
|
||||
#define LM_API_VCOMP_EN (LM_API_VCOMP | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_DIS (LM_API_VCOMP | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_SET (LM_API_VCOMP | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_IN_RAMP (LM_API_VCOMP | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_COMP_RAMP (LM_API_VCOMP | (4 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_VCOMP_T_EN (LM_API_VCOMP | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_T_SET (LM_API_VCOMP | (6 << CAN_MSGID_API_S))
|
||||
#define LM_API_VCOMP_T_SET_NO_ACK (LM_API_VCOMP | (8 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
#define LM_API_VCOMP_SET_NO_ACK (LM_API_VCOMP | (9 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Position Control API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_POS (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_POS)
|
||||
#define LM_API_POS_EN (LM_API_POS | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_DIS (LM_API_POS | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_SET (LM_API_POS | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_PC (LM_API_POS | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_IC (LM_API_POS | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_DC (LM_API_POS | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_REF (LM_API_POS | (6 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_POS_T_EN (LM_API_POS | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_T_SET (LM_API_POS | (8 << CAN_MSGID_API_S))
|
||||
#define LM_API_POS_T_SET_NO_ACK (LM_API_POS | (10 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
#define LM_API_POS_SET_NO_ACK (LM_API_POS | (11 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Current Control API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_ICTRL \
|
||||
(CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_ICTRL)
|
||||
#define LM_API_ICTRL_EN (LM_API_ICTRL | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_DIS (LM_API_ICTRL | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_SET (LM_API_ICTRL | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_PC (LM_API_ICTRL | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_IC (LM_API_ICTRL | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_DC (LM_API_ICTRL | (5 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_ICTRL_T_EN (LM_API_ICTRL | (6 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_T_SET (LM_API_ICTRL | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_ICTRL_T_SET_NO_ACK (LM_API_ICTRL | (9 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
#define LM_API_ICTRL_SET_NO_ACK (LM_API_ICTRL | (10 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Firmware Update API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_UPD (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_UPDATE)
|
||||
#define LM_API_UPD_PING (LM_API_UPD | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_UPD_DOWNLOAD (LM_API_UPD | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_UPD_SEND_DATA (LM_API_UPD | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_UPD_RESET (LM_API_UPD | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_UPD_ACK (LM_API_UPD | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_HWVER (LM_API_UPD | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_UPD_REQUEST (LM_API_UPD | (6 << CAN_MSGID_API_S))
|
||||
//##### FIRST BEGIN #####
|
||||
#define LM_API_UNTRUST_EN (LM_API_UPD | (11 << CAN_MSGID_API_S))
|
||||
#define LM_API_TRUST_EN (LM_API_UPD | (12 << CAN_MSGID_API_S))
|
||||
#define LM_API_TRUST_HEARTBEAT (LM_API_UPD | (13 << CAN_MSGID_API_S))
|
||||
//##### FIRST END #####
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Status API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_STATUS \
|
||||
(CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_STATUS)
|
||||
#define LM_API_STATUS_VOLTOUT (LM_API_STATUS | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_VOLTBUS (LM_API_STATUS | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_CURRENT (LM_API_STATUS | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_TEMP (LM_API_STATUS | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_POS (LM_API_STATUS | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_SPD (LM_API_STATUS | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_LIMIT (LM_API_STATUS | (6 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_FAULT (LM_API_STATUS | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_POWER (LM_API_STATUS | (8 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_CMODE (LM_API_STATUS | (9 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_VOUT (LM_API_STATUS | (10 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_STKY_FLT (LM_API_STATUS | (11 << CAN_MSGID_API_S))
|
||||
#define LM_API_STATUS_FLT_COUNT (LM_API_STATUS | (12 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// These definitions are used with the byte that is returned from
|
||||
// the status request for LM_API_STATUS_LIMIT.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_STATUS_LIMIT_FWD 0x01
|
||||
#define LM_STATUS_LIMIT_REV 0x02
|
||||
#define LM_STATUS_LIMIT_SFWD 0x04
|
||||
#define LM_STATUS_LIMIT_SREV 0x08
|
||||
#define LM_STATUS_LIMIT_STKY_FWD 0x10
|
||||
#define LM_STATUS_LIMIT_STKY_REV 0x20
|
||||
#define LM_STATUS_LIMIT_STKY_SFWD 0x40
|
||||
#define LM_STATUS_LIMIT_STKY_SREV 0x80
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// LM Motor Control status codes returned due to the CAN_STATUS_CODE_M field.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_STATUS_FAULT_ILIMIT 0x01
|
||||
#define LM_STATUS_FAULT_TLIMIT 0x02
|
||||
#define LM_STATUS_FAULT_VLIMIT 0x04
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Configuration API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_CFG (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_CFG)
|
||||
#define LM_API_CFG_NUM_BRUSHES (LM_API_CFG | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_ENC_LINES (LM_API_CFG | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_POT_TURNS (LM_API_CFG | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_BRAKE_COAST (LM_API_CFG | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_LIMIT_MODE (LM_API_CFG | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_LIMIT_FWD (LM_API_CFG | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_LIMIT_REV (LM_API_CFG | (6 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_MAX_VOUT (LM_API_CFG | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_CFG_FAULT_TIME (LM_API_CFG | (8 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris ACK API definition.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_ACK (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_ACK)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The 8 bit values that can be returned by a call to LM_API_STATUS_HWVER.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_HWVER_UNKNOWN 0x00
|
||||
#define LM_HWVER_JAG_1_0 0x01
|
||||
#define LM_HWVER_JAG_2_0 0x02
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The 8 bit values that can be returned by a call to LM_API_STATUS_CMODE.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_STATUS_CMODE_VOLT 0x00
|
||||
#define LM_STATUS_CMODE_CURRENT 0x01
|
||||
#define LM_STATUS_CMODE_SPEED 0x02
|
||||
#define LM_STATUS_CMODE_POS 0x03
|
||||
#define LM_STATUS_CMODE_VCOMP 0x04
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The values that can specified as the position or speed reference. Not all
|
||||
// values are valid for each reference; if an invalid reference is set, then
|
||||
// none will be selected.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_REF_ENCODER 0x00
|
||||
#define LM_REF_POT 0x01
|
||||
#define LM_REF_INV_ENCODER 0x02
|
||||
#define LM_REF_QUAD_ENCODER 0x03
|
||||
#define LM_REF_NONE 0xff
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The flags that are used to indicate the currently active fault sources.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_FAULT_CURRENT 0x01
|
||||
#define LM_FAULT_TEMP 0x02
|
||||
#define LM_FAULT_VBUS 0x04
|
||||
#define LM_FAULT_GATE_DRIVE 0x08
|
||||
#define LM_FAULT_COMM 0x10
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The Stellaris Motor Class Periodic Status API definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_API_PSTAT \
|
||||
(CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | CAN_API_MC_PSTAT)
|
||||
#define LM_API_PSTAT_PER_EN_S0 (LM_API_PSTAT | (0 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_PER_EN_S1 (LM_API_PSTAT | (1 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_PER_EN_S2 (LM_API_PSTAT | (2 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_PER_EN_S3 (LM_API_PSTAT | (3 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_CFG_S0 (LM_API_PSTAT | (4 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_CFG_S1 (LM_API_PSTAT | (5 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_CFG_S2 (LM_API_PSTAT | (6 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_CFG_S3 (LM_API_PSTAT | (7 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_DATA_S0 (LM_API_PSTAT | (8 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_DATA_S1 (LM_API_PSTAT | (9 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_DATA_S2 (LM_API_PSTAT | (10 << CAN_MSGID_API_S))
|
||||
#define LM_API_PSTAT_DATA_S3 (LM_API_PSTAT | (11 << CAN_MSGID_API_S))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// The values that can be used to configure the data the Periodic Status
|
||||
// Message bytes. Bytes of a multi-byte data values are encoded as
|
||||
// little-endian, therefore B0 is the least significant byte.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define LM_PSTAT_END 0
|
||||
#define LM_PSTAT_VOLTOUT_B0 1
|
||||
#define LM_PSTAT_VOLTOUT_B1 2
|
||||
#define LM_PSTAT_VOLTBUS_B0 3
|
||||
#define LM_PSTAT_VOLTBUS_B1 4
|
||||
#define LM_PSTAT_CURRENT_B0 5
|
||||
#define LM_PSTAT_CURRENT_B1 6
|
||||
#define LM_PSTAT_TEMP_B0 7
|
||||
#define LM_PSTAT_TEMP_B1 8
|
||||
#define LM_PSTAT_POS_B0 9
|
||||
#define LM_PSTAT_POS_B1 10
|
||||
#define LM_PSTAT_POS_B2 11
|
||||
#define LM_PSTAT_POS_B3 12
|
||||
#define LM_PSTAT_SPD_B0 13
|
||||
#define LM_PSTAT_SPD_B1 14
|
||||
#define LM_PSTAT_SPD_B2 15
|
||||
#define LM_PSTAT_SPD_B3 16
|
||||
#define LM_PSTAT_LIMIT_NCLR 17
|
||||
#define LM_PSTAT_LIMIT_CLR 18
|
||||
#define LM_PSTAT_FAULT 19
|
||||
#define LM_PSTAT_STKY_FLT_NCLR 20
|
||||
#define LM_PSTAT_STKY_FLT_CLR 21
|
||||
#define LM_PSTAT_VOUT_B0 22
|
||||
#define LM_PSTAT_VOUT_B1 23
|
||||
#define LM_PSTAT_FLT_COUNT_CURRENT 24
|
||||
#define LM_PSTAT_FLT_COUNT_TEMP 25
|
||||
#define LM_PSTAT_FLT_COUNT_VOLTBUS 26
|
||||
#define LM_PSTAT_FLT_COUNT_GATE 27
|
||||
#define LM_PSTAT_FLT_COUNT_COMM 28
|
||||
#define LM_PSTAT_CANSTS 29
|
||||
#define LM_PSTAT_CANERR_B0 30
|
||||
#define LM_PSTAT_CANERR_B1 31
|
||||
|
||||
#endif // __CAN_PROTO_H__
|
||||
@@ -1,253 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2009-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "CAN/can_proto.h"
|
||||
#include "CANSpeedController.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "PIDOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
/**
|
||||
* Luminary Micro / Vex Robotics Jaguar Speed Control
|
||||
*/
|
||||
class CANJaguar : public MotorSafety,
|
||||
public CANSpeedController,
|
||||
public ErrorBase,
|
||||
public LiveWindowSendable,
|
||||
public ITableListener {
|
||||
public:
|
||||
// The internal PID control loop in the Jaguar runs at 1kHz.
|
||||
static const int kControllerRate = 1000;
|
||||
static constexpr double kApproxBusVoltage = 12.0;
|
||||
|
||||
// Control mode tags
|
||||
/** Sets an encoder as the speed reference only. <br> Passed as the "tag" when
|
||||
* setting the control mode.*/
|
||||
static const struct EncoderStruct {
|
||||
} Encoder;
|
||||
/** Sets a quadrature encoder as the position and speed reference. <br> Passed
|
||||
* as the "tag" when setting the control mode.*/
|
||||
static const struct QuadEncoderStruct {
|
||||
} QuadEncoder;
|
||||
/** Sets a potentiometer as the position reference only. <br> Passed as the
|
||||
* "tag" when setting the control mode. */
|
||||
static const struct PotentiometerStruct {
|
||||
} Potentiometer;
|
||||
|
||||
explicit CANJaguar(int deviceNumber);
|
||||
virtual ~CANJaguar();
|
||||
|
||||
int getDeviceNumber() const;
|
||||
int GetHardwareVersion() const;
|
||||
|
||||
// PIDOutput interface
|
||||
void PIDWrite(float output) override;
|
||||
|
||||
// Control mode methods
|
||||
void EnableControl(double encoderInitialPosition = 0.0);
|
||||
void DisableControl();
|
||||
|
||||
void SetPercentMode();
|
||||
void SetPercentMode(EncoderStruct, uint16_t codesPerRev);
|
||||
void SetPercentMode(QuadEncoderStruct, uint16_t codesPerRev);
|
||||
void SetPercentMode(PotentiometerStruct);
|
||||
|
||||
void SetCurrentMode(double p, double i, double d);
|
||||
void SetCurrentMode(EncoderStruct, uint16_t codesPerRev, double p, double i,
|
||||
double d);
|
||||
void SetCurrentMode(QuadEncoderStruct, uint16_t codesPerRev, double p,
|
||||
double i, double d);
|
||||
void SetCurrentMode(PotentiometerStruct, double p, double i, double d);
|
||||
|
||||
void SetSpeedMode(EncoderStruct, uint16_t codesPerRev, double p, double i,
|
||||
double d);
|
||||
void SetSpeedMode(QuadEncoderStruct, uint16_t codesPerRev, double p, double i,
|
||||
double d);
|
||||
|
||||
void SetPositionMode(QuadEncoderStruct, uint16_t codesPerRev, double p,
|
||||
double i, double d);
|
||||
void SetPositionMode(PotentiometerStruct, double p, double i, double d);
|
||||
|
||||
void SetVoltageMode();
|
||||
void SetVoltageMode(EncoderStruct, uint16_t codesPerRev);
|
||||
void SetVoltageMode(QuadEncoderStruct, uint16_t codesPerRev);
|
||||
void SetVoltageMode(PotentiometerStruct);
|
||||
|
||||
void Set(float value, int syncGroup);
|
||||
|
||||
// CANSpeedController interface
|
||||
float Get() const override;
|
||||
void Set(float value) override;
|
||||
void Disable() override;
|
||||
void SetP(double p) override;
|
||||
void SetI(double i) override;
|
||||
void SetD(double d) override;
|
||||
void SetPID(double p, double i, double d) override;
|
||||
double GetP() const override;
|
||||
double GetI() const override;
|
||||
double GetD() const override;
|
||||
bool IsModePID(CANSpeedController::ControlMode mode) const override;
|
||||
float GetBusVoltage() const override;
|
||||
float GetOutputVoltage() const override;
|
||||
float GetOutputCurrent() const override;
|
||||
float GetTemperature() const override;
|
||||
double GetPosition() const override;
|
||||
double GetSpeed() const override;
|
||||
bool GetForwardLimitOK() const override;
|
||||
bool GetReverseLimitOK() const override;
|
||||
uint16_t GetFaults() const override;
|
||||
void SetVoltageRampRate(double rampRate) override;
|
||||
int GetFirmwareVersion() const override;
|
||||
void ConfigNeutralMode(NeutralMode mode) override;
|
||||
void ConfigEncoderCodesPerRev(uint16_t codesPerRev) override;
|
||||
void ConfigPotentiometerTurns(uint16_t turns) override;
|
||||
void ConfigSoftPositionLimits(double forwardLimitPosition,
|
||||
double reverseLimitPosition) override;
|
||||
void DisableSoftPositionLimits() override;
|
||||
void ConfigLimitMode(LimitMode mode) override;
|
||||
void ConfigForwardLimit(double forwardLimitPosition) override;
|
||||
void ConfigReverseLimit(double reverseLimitPosition) override;
|
||||
void ConfigMaxOutputVoltage(double voltage) override;
|
||||
void ConfigFaultTime(float faultTime) override;
|
||||
virtual void SetControlMode(ControlMode mode);
|
||||
virtual ControlMode GetControlMode() const;
|
||||
|
||||
static void UpdateSyncGroup(uint8_t syncGroup);
|
||||
|
||||
void SetExpiration(float timeout) override;
|
||||
float GetExpiration() const override;
|
||||
bool IsAlive() const override;
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
int GetDeviceID() const;
|
||||
|
||||
// SpeedController overrides
|
||||
void SetInverted(bool isInverted) override;
|
||||
bool GetInverted() const override;
|
||||
|
||||
protected:
|
||||
// Control mode helpers
|
||||
void SetSpeedReference(int reference);
|
||||
int GetSpeedReference() const;
|
||||
|
||||
void SetPositionReference(int reference);
|
||||
int GetPositionReference() const;
|
||||
|
||||
int packPercentage(uint8_t* buffer, double value);
|
||||
int packFXP8_8(uint8_t* buffer, double value);
|
||||
int packFXP16_16(uint8_t* buffer, double value);
|
||||
int packInt16(uint8_t* buffer, int16_t value);
|
||||
int packInt32(uint8_t* buffer, int32_t value);
|
||||
double unpackPercentage(uint8_t* buffer) const;
|
||||
double unpackFXP8_8(uint8_t* buffer) const;
|
||||
double unpackFXP16_16(uint8_t* buffer) const;
|
||||
int16_t unpackInt16(uint8_t* buffer) const;
|
||||
int32_t unpackInt32(uint8_t* buffer) const;
|
||||
|
||||
void sendMessage(int messageID, const uint8_t* data, uint8_t dataSize,
|
||||
int period = CAN_SEND_PERIOD_NO_REPEAT);
|
||||
void requestMessage(int messageID, int period = CAN_SEND_PERIOD_NO_REPEAT);
|
||||
bool getMessage(int messageID, uint32_t mask, uint8_t* data,
|
||||
uint8_t* dataSize) const;
|
||||
|
||||
void setupPeriodicStatus();
|
||||
void updatePeriodicStatus() const;
|
||||
|
||||
mutable priority_recursive_mutex m_mutex;
|
||||
|
||||
int m_deviceNumber;
|
||||
float m_value = 0.0f;
|
||||
|
||||
// Parameters/configuration
|
||||
ControlMode m_controlMode = kPercentVbus;
|
||||
int m_speedReference = LM_REF_NONE;
|
||||
int m_positionReference = LM_REF_NONE;
|
||||
double m_p = 0.0;
|
||||
double m_i = 0.0;
|
||||
double m_d = 0.0;
|
||||
NeutralMode m_neutralMode = kNeutralMode_Jumper;
|
||||
uint16_t m_encoderCodesPerRev = 0;
|
||||
uint16_t m_potentiometerTurns = 0;
|
||||
LimitMode m_limitMode = kLimitMode_SwitchInputsOnly;
|
||||
double m_forwardLimit = 0.0;
|
||||
double m_reverseLimit = 0.0;
|
||||
double m_maxOutputVoltage = 30.0;
|
||||
double m_voltageRampRate = 0.0;
|
||||
float m_faultTime = 0.0f;
|
||||
|
||||
// Which parameters have been verified since they were last set?
|
||||
bool m_controlModeVerified =
|
||||
false; // Needs to be verified because it's set in the constructor
|
||||
bool m_speedRefVerified = true;
|
||||
bool m_posRefVerified = true;
|
||||
bool m_pVerified = true;
|
||||
bool m_iVerified = true;
|
||||
bool m_dVerified = true;
|
||||
bool m_neutralModeVerified = true;
|
||||
bool m_encoderCodesPerRevVerified = true;
|
||||
bool m_potentiometerTurnsVerified = true;
|
||||
bool m_forwardLimitVerified = true;
|
||||
bool m_reverseLimitVerified = true;
|
||||
bool m_limitModeVerified = true;
|
||||
bool m_maxOutputVoltageVerified = true;
|
||||
bool m_voltageRampRateVerified = true;
|
||||
bool m_faultTimeVerified = true;
|
||||
|
||||
// Status data
|
||||
mutable float m_busVoltage = 0.0f;
|
||||
mutable float m_outputVoltage = 0.0f;
|
||||
mutable float m_outputCurrent = 0.0f;
|
||||
mutable float m_temperature = 0.0f;
|
||||
mutable double m_position = 0.0;
|
||||
mutable double m_speed = 0.0;
|
||||
mutable int m_limits = 0x00;
|
||||
mutable uint16_t m_faults = 0x0000;
|
||||
int m_firmwareVersion = 0;
|
||||
int m_hardwareVersion = 0;
|
||||
|
||||
// Which periodic status messages have we received at least once?
|
||||
mutable std::atomic<bool> m_receivedStatusMessage0{false};
|
||||
mutable std::atomic<bool> m_receivedStatusMessage1{false};
|
||||
mutable std::atomic<bool> m_receivedStatusMessage2{false};
|
||||
|
||||
bool m_controlEnabled = false;
|
||||
bool m_stopped = false;
|
||||
|
||||
void verify();
|
||||
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
|
||||
private:
|
||||
void InitCANJaguar();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
/**
|
||||
* Interface for "smart" CAN-based speed controllers.
|
||||
* @see CANJaguar
|
||||
* @see CANTalon
|
||||
*/
|
||||
class CANSpeedController : public SpeedController {
|
||||
public:
|
||||
@@ -22,8 +20,8 @@ class CANSpeedController : public SpeedController {
|
||||
kSpeed = 2,
|
||||
kPosition = 3,
|
||||
kVoltage = 4,
|
||||
kFollower = 5, // Not supported in Jaguar.
|
||||
kMotionProfile = 6, // Not supported in Jaguar.
|
||||
kFollower = 5,
|
||||
kMotionProfile = 6,
|
||||
};
|
||||
|
||||
// Helper function for the ControlMode enum
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "Buttons/InternalButton.h"
|
||||
#include "Buttons/JoystickButton.h"
|
||||
#include "Buttons/NetworkButton.h"
|
||||
#include "CANJaguar.h"
|
||||
#include "CameraServer.h"
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/CommandGroup.h"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@ class TestBench {
|
||||
|
||||
/* Analog output channels */
|
||||
static const uint32_t kAnalogOutputChannel = 0;
|
||||
static const uint32_t kFakeJaguarPotentiometer = 1;
|
||||
|
||||
/* DIO channels */
|
||||
static const uint32_t kTalonEncoderChannelA = 0;
|
||||
@@ -45,15 +44,9 @@ class TestBench {
|
||||
static const uint32_t kFakeSolenoid2Channel = 13;
|
||||
static const uint32_t kFakeRelayForward = 18;
|
||||
static const uint32_t kFakeRelayReverse = 19;
|
||||
static const uint32_t kFakeJaguarForwardLimit = 20;
|
||||
static const uint32_t kFakeJaguarReverseLimit = 21;
|
||||
|
||||
/* Relay channels */
|
||||
static const uint32_t kRelayChannel = 0;
|
||||
static const uint32_t kCANJaguarRelayChannel = 1;
|
||||
|
||||
/* CAN IDs */
|
||||
static const uint32_t kCANJaguarID = 2;
|
||||
|
||||
/* PDP channels */
|
||||
static const uint32_t kJaguarPDPChannel = 6;
|
||||
|
||||
@@ -1,500 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "CANJaguar.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "AnalogOutput.h"
|
||||
#include "DigitalOutput.h"
|
||||
#include "Relay.h"
|
||||
#include "TestBench.h"
|
||||
#include "Timer.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
static constexpr double kSpikeTime = 0.5;
|
||||
|
||||
static constexpr double kExpectedBusVoltage = 14.0;
|
||||
static constexpr double kExpectedTemperature = 25.0;
|
||||
|
||||
static constexpr double kMotorTime = 0.5;
|
||||
|
||||
static constexpr double kEncoderSettlingTime = 1.0;
|
||||
static constexpr double kEncoderPositionTolerance = 0.1;
|
||||
static constexpr double kEncoderSpeedTolerance = 30.0;
|
||||
|
||||
static constexpr double kPotentiometerSettlingTime = 1.0;
|
||||
static constexpr double kPotentiometerPositionTolerance = 0.1;
|
||||
|
||||
static constexpr double kCurrentTolerance = 0.1;
|
||||
|
||||
static constexpr double kVoltageTolerance = 0.1;
|
||||
|
||||
static constexpr double kMotorVoltage = 5.0;
|
||||
|
||||
static constexpr double kMotorPercent = 0.5;
|
||||
|
||||
static constexpr double kMotorSpeed = 100;
|
||||
class CANJaguarTest : public testing::Test {
|
||||
protected:
|
||||
CANJaguar* m_jaguar;
|
||||
DigitalOutput *m_fakeForwardLimit, *m_fakeReverseLimit;
|
||||
AnalogOutput* m_fakePotentiometer;
|
||||
Relay* m_spike;
|
||||
|
||||
void SetUp() override {
|
||||
m_spike = new Relay(TestBench::kCANJaguarRelayChannel, Relay::kForwardOnly);
|
||||
m_spike->Set(Relay::kOn);
|
||||
Wait(kSpikeTime);
|
||||
|
||||
m_jaguar = new CANJaguar(TestBench::kCANJaguarID);
|
||||
|
||||
m_fakeForwardLimit = new DigitalOutput(TestBench::kFakeJaguarForwardLimit);
|
||||
m_fakeForwardLimit->Set(0);
|
||||
|
||||
m_fakeReverseLimit = new DigitalOutput(TestBench::kFakeJaguarReverseLimit);
|
||||
m_fakeReverseLimit->Set(0);
|
||||
|
||||
m_fakePotentiometer = new AnalogOutput(TestBench::kFakeJaguarPotentiometer);
|
||||
m_fakePotentiometer->SetVoltage(0.0f);
|
||||
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Wait(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete m_jaguar;
|
||||
delete m_fakeForwardLimit;
|
||||
delete m_fakeReverseLimit;
|
||||
delete m_fakePotentiometer;
|
||||
delete m_spike;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls CANJaguar::Set periodically 50 times to make sure everything is
|
||||
* verified. This mimics a real robot program, where Set is presumably
|
||||
* called in each iteration of the main loop.
|
||||
*/
|
||||
void SetJaguar(float totalTime, float value = 0.0f) {
|
||||
for (int32_t i = 0; i < 50; i++) {
|
||||
m_jaguar->Set(value);
|
||||
Wait(totalTime / 50.0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* returns the sign of the given number
|
||||
*/
|
||||
int32_t SignNum(double value) { return -(value < 0) + (value > 0); }
|
||||
void InversionTest(float motorValue, float delayTime = kMotorTime) {
|
||||
m_jaguar->EnableControl();
|
||||
m_jaguar->SetInverted(false);
|
||||
SetJaguar(delayTime, motorValue);
|
||||
double initialSpeed = m_jaguar->GetSpeed();
|
||||
m_jaguar->Set(0.0);
|
||||
m_jaguar->SetInverted(true);
|
||||
SetJaguar(delayTime, motorValue);
|
||||
double finalSpeed = m_jaguar->GetSpeed();
|
||||
// checks that the motor has changed direction
|
||||
EXPECT_FALSE(SignNum(initialSpeed) == SignNum(finalSpeed))
|
||||
<< "CAN Jaguar did not invert direction positive. Initial speed was: "
|
||||
<< initialSpeed << " Final displacement was: " << finalSpeed
|
||||
<< " Sign of initial displacement was: " << SignNum(initialSpeed)
|
||||
<< " Sign of final displacement was: " << SignNum(finalSpeed);
|
||||
SetJaguar(delayTime, -motorValue);
|
||||
initialSpeed = m_jaguar->GetSpeed();
|
||||
m_jaguar->Set(0.0);
|
||||
m_jaguar->SetInverted(false);
|
||||
SetJaguar(delayTime, -motorValue);
|
||||
finalSpeed = m_jaguar->GetSpeed();
|
||||
EXPECT_FALSE(SignNum(initialSpeed) == SignNum(finalSpeed))
|
||||
<< "CAN Jaguar did not invert direction negative. Initial displacement "
|
||||
"was: "
|
||||
<< initialSpeed << " Final displacement was: " << finalSpeed
|
||||
<< " Sign of initial displacement was: " << SignNum(initialSpeed)
|
||||
<< " Sign of final displacement was: " << SignNum(finalSpeed);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests that allocating the same CANJaguar port as an already allocated port
|
||||
* causes a ResourceAlreadyAllocated error.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, AlreadyAllocatedError) {
|
||||
std::cout << "The following errors are expected." << std::endl << std::endl;
|
||||
|
||||
CANJaguar jaguar(TestBench::kCANJaguarID);
|
||||
EXPECT_EQ(wpi_error_value_ResourceAlreadyAllocated,
|
||||
jaguar.GetError().GetCode())
|
||||
<< "An error should have been returned";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that allocating a CANJaguar with device number 64 causes an
|
||||
* out-of-range error.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, 64OutOfRangeError) {
|
||||
std::cout << "The following errors are expected." << std::endl << std::endl;
|
||||
|
||||
CANJaguar jaguar(64);
|
||||
EXPECT_EQ(wpi_error_value_ChannelIndexOutOfRange, jaguar.GetError().GetCode())
|
||||
<< "An error should have been returned";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that allocating a CANJaguar with device number 0 causes an out-of-range
|
||||
* error.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, 0OutOfRangeError) {
|
||||
std::cout << "The following errors are expected." << std::endl << std::endl;
|
||||
|
||||
CANJaguar jaguar(0);
|
||||
EXPECT_EQ(wpi_error_value_ChannelIndexOutOfRange, jaguar.GetError().GetCode())
|
||||
<< "An error should have been returned";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the default status data for reasonable values to confirm that we're
|
||||
* really getting status data from the Jaguar.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, InitialStatus) {
|
||||
m_jaguar->SetPercentMode();
|
||||
|
||||
EXPECT_NEAR(m_jaguar->GetBusVoltage(), kExpectedBusVoltage, 3.0)
|
||||
<< "Bus voltage is not a plausible value.";
|
||||
|
||||
EXPECT_FLOAT_EQ(m_jaguar->GetOutputVoltage(), 0.0)
|
||||
<< "Output voltage is non-zero.";
|
||||
|
||||
EXPECT_FLOAT_EQ(m_jaguar->GetOutputCurrent(), 0.0)
|
||||
<< "Output current is non-zero.";
|
||||
|
||||
EXPECT_NEAR(m_jaguar->GetTemperature(), kExpectedTemperature, 5.0)
|
||||
<< "Temperature is not a plausible value.";
|
||||
|
||||
EXPECT_EQ(m_jaguar->GetFaults(), 0) << "Jaguar has one or more fault set.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the jaguar doesn't move when it's disabled
|
||||
*/
|
||||
TEST_F(CANJaguarTest, Disable) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->EnableControl();
|
||||
m_jaguar->DisableControl();
|
||||
|
||||
Wait(kEncoderSettlingTime);
|
||||
|
||||
double initialPosition = m_jaguar->GetPosition();
|
||||
|
||||
SetJaguar(kMotorTime, 1.0f);
|
||||
m_jaguar->Set(0.0f);
|
||||
|
||||
double finalPosition = m_jaguar->GetPosition();
|
||||
|
||||
EXPECT_NEAR(initialPosition, finalPosition, kEncoderPositionTolerance)
|
||||
<< "Jaguar moved while disabled";
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the Jaguar keeps its state after a power cycle by setting a
|
||||
* control mode, turning the spike on and off, then checking if the Jaguar
|
||||
* behaves like it should in that control mode.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, BrownOut) {
|
||||
/* Set the jaguar to quad encoder position mode */
|
||||
m_jaguar->SetPositionMode(CANJaguar::QuadEncoder, 360, 20.0f, 0.01f, 0.0f);
|
||||
m_jaguar->EnableControl();
|
||||
SetJaguar(kMotorTime, 0.0);
|
||||
double setpoint = m_jaguar->GetPosition() + 1.0f;
|
||||
|
||||
/* Turn the spike off and on again */
|
||||
m_spike->Set(Relay::kOff);
|
||||
Wait(kSpikeTime);
|
||||
m_spike->Set(Relay::kOn);
|
||||
Wait(kSpikeTime);
|
||||
|
||||
/* The jaguar should automatically get set to quad encoder position mode,
|
||||
so it should be able to reach a setpoint in a couple seconds. */
|
||||
for (int32_t i = 0; i < 10; i++) {
|
||||
SetJaguar(1.0f, setpoint);
|
||||
|
||||
if (std::fabs(m_jaguar->GetPosition() - setpoint) <=
|
||||
kEncoderPositionTolerance) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_NEAR(setpoint, m_jaguar->GetPosition(), kEncoderPositionTolerance)
|
||||
<< "CAN Jaguar should have resumed PID control after power cycle";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set arbitrary setpoints and PID values each each applicable
|
||||
* mode and get the same values back.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, SetGet) {
|
||||
m_jaguar->DisableControl();
|
||||
|
||||
m_jaguar->SetSpeedMode(CANJaguar::QuadEncoder, 360, 1, 2, 3);
|
||||
m_jaguar->Set(4);
|
||||
|
||||
EXPECT_FLOAT_EQ(1, m_jaguar->GetP());
|
||||
EXPECT_FLOAT_EQ(2, m_jaguar->GetI());
|
||||
EXPECT_FLOAT_EQ(3, m_jaguar->GetD());
|
||||
EXPECT_FLOAT_EQ(4, m_jaguar->Get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor in percentage mode and get a position back
|
||||
*/
|
||||
TEST_F(CANJaguarTest, PercentModeForwardWorks) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
SetJaguar(kEncoderSettlingTime, 0.0f);
|
||||
|
||||
double initialPosition = m_jaguar->GetPosition();
|
||||
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
SetJaguar(kMotorTime, 1.0f);
|
||||
m_jaguar->Set(0.0f);
|
||||
|
||||
/* The position should have increased */
|
||||
EXPECT_GT(m_jaguar->GetPosition(), initialPosition)
|
||||
<< "CAN Jaguar position should have increased after the motor moved";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor backwards in percentage mode and get a
|
||||
* position back
|
||||
*/
|
||||
TEST_F(CANJaguarTest, PercentModeReverseWorks) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
SetJaguar(kEncoderSettlingTime, 0.0f);
|
||||
|
||||
double initialPosition = m_jaguar->GetPosition();
|
||||
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
SetJaguar(kMotorTime, -1.0f);
|
||||
m_jaguar->Set(0.0f);
|
||||
|
||||
float p = m_jaguar->GetPosition();
|
||||
/* The position should have decreased */
|
||||
EXPECT_LT(p, initialPosition)
|
||||
<< "CAN Jaguar position should have decreased after the motor moved";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set an absolute voltage and receive a matching output voltage
|
||||
* status.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, VoltageModeWorks) {
|
||||
m_jaguar->SetVoltageMode();
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
float setpoints[] = {M_PI, 8.0f, -10.0f};
|
||||
|
||||
for (auto setpoint : setpoints) {
|
||||
SetJaguar(kMotorTime, setpoint);
|
||||
EXPECT_NEAR(setpoint, m_jaguar->GetOutputVoltage(), kVoltageTolerance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a speed in speed control mode and receive a matching
|
||||
* speed status.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, SpeedModeWorks) {
|
||||
m_jaguar->SetSpeedMode(CANJaguar::QuadEncoder, 360, 0.1f, 0.003f, 0.01f);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
constexpr float speed = 50.0f;
|
||||
|
||||
SetJaguar(kMotorTime, speed);
|
||||
EXPECT_NEAR(speed, m_jaguar->GetSpeed(), kEncoderSpeedTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on
|
||||
* the Jaguar.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, PositionModeWorks) {
|
||||
m_jaguar->SetPositionMode(CANJaguar::QuadEncoder, 360, 15.0f, 0.02f, 0.0f);
|
||||
|
||||
double setpoint = m_jaguar->GetPosition() + 1.0f;
|
||||
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
for (int32_t i = 0; i < 10; i++) {
|
||||
SetJaguar(1.0f, setpoint);
|
||||
|
||||
if (std::fabs(m_jaguar->GetPosition() - setpoint) <=
|
||||
kEncoderPositionTolerance) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_NEAR(setpoint, m_jaguar->GetPosition(), kEncoderPositionTolerance)
|
||||
<< "CAN Jaguar should have reached setpoint with PID control";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a current setpoint with PID control on the Jaguar and get
|
||||
* a corresponding output current
|
||||
*/
|
||||
TEST_F(CANJaguarTest, DISABLED_CurrentModeWorks) {
|
||||
m_jaguar->SetCurrentMode(10.0, 4.0, 1.0);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
float setpoints[] = {1.6f, 2.0f, -1.6f};
|
||||
|
||||
for (auto& setpoints_i : setpoints) {
|
||||
float setpoint = setpoints_i;
|
||||
float expectedCurrent = std::fabs(setpoints_i);
|
||||
|
||||
/* It should get to each setpoint within 10 seconds */
|
||||
for (int32_t j = 0; j < 10; j++) {
|
||||
SetJaguar(1.0, setpoint);
|
||||
|
||||
if (std::fabs(m_jaguar->GetOutputCurrent() - expectedCurrent) <=
|
||||
kCurrentTolerance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_NEAR(expectedCurrent, m_jaguar->GetOutputCurrent(),
|
||||
kCurrentTolerance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can get a position in potentiometer mode, using an analog output
|
||||
* as a fake potentiometer.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, FakePotentiometerPosition) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::Potentiometer);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
// Set the analog output to 4 different voltages and check if the Jaguar
|
||||
// returns corresponding positions.
|
||||
for (int32_t i = 0; i <= 3; i++) {
|
||||
m_fakePotentiometer->SetVoltage(static_cast<float>(i));
|
||||
|
||||
SetJaguar(kPotentiometerSettlingTime);
|
||||
|
||||
EXPECT_NEAR(m_fakePotentiometer->GetVoltage() / 3.0f,
|
||||
m_jaguar->GetPosition(), kPotentiometerPositionTolerance)
|
||||
<< "CAN Jaguar should have returned the potentiometer position set by "
|
||||
"the analog output";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving in reverse with a fake
|
||||
* limit switch.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, FakeLimitSwitchForwards) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->ConfigLimitMode(CANJaguar::kLimitMode_SwitchInputsOnly);
|
||||
m_fakeForwardLimit->Set(1);
|
||||
m_fakeReverseLimit->Set(0);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
SetJaguar(kEncoderSettlingTime);
|
||||
|
||||
/* Make sure the limits are recognized by the Jaguar. */
|
||||
ASSERT_FALSE(m_jaguar->GetForwardLimitOK());
|
||||
ASSERT_TRUE(m_jaguar->GetReverseLimitOK());
|
||||
|
||||
double initialPosition = m_jaguar->GetPosition();
|
||||
|
||||
/* Drive the speed controller briefly to move the encoder. If the limit
|
||||
switch is recognized, it shouldn't actually move. */
|
||||
SetJaguar(kMotorTime, 1.0f);
|
||||
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
EXPECT_NEAR(initialPosition, m_jaguar->GetPosition(),
|
||||
kEncoderPositionTolerance)
|
||||
<< "CAN Jaguar should not have moved with the limit switch pressed";
|
||||
|
||||
/* Drive the speed controller in the other direction. It should actually
|
||||
move, since only the forward switch is activated.*/
|
||||
SetJaguar(kMotorTime, -1.0f);
|
||||
|
||||
/* The position should have decreased */
|
||||
EXPECT_LT(m_jaguar->GetPosition(), initialPosition)
|
||||
<< "CAN Jaguar should have moved in reverse while the forward limit was "
|
||||
"on";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit
|
||||
* switch.
|
||||
*/
|
||||
TEST_F(CANJaguarTest, FakeLimitSwitchReverse) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->ConfigLimitMode(CANJaguar::kLimitMode_SwitchInputsOnly);
|
||||
m_fakeForwardLimit->Set(0);
|
||||
m_fakeReverseLimit->Set(1);
|
||||
m_jaguar->EnableControl();
|
||||
|
||||
SetJaguar(kEncoderSettlingTime);
|
||||
|
||||
/* Make sure the limits are recognized by the Jaguar. */
|
||||
ASSERT_TRUE(m_jaguar->GetForwardLimitOK());
|
||||
ASSERT_FALSE(m_jaguar->GetReverseLimitOK());
|
||||
|
||||
double initialPosition = m_jaguar->GetPosition();
|
||||
|
||||
/* Drive the speed controller backwards briefly to move the encoder. If
|
||||
the limit switch is recognized, it shouldn't actually move. */
|
||||
SetJaguar(kMotorTime, -1.0f);
|
||||
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
EXPECT_NEAR(initialPosition, m_jaguar->GetPosition(),
|
||||
kEncoderPositionTolerance)
|
||||
<< "CAN Jaguar should not have moved with the limit switch pressed";
|
||||
|
||||
/* Drive the speed controller in the other direction. It should actually
|
||||
move, since only the reverse switch is activated.*/
|
||||
SetJaguar(kMotorTime, 1.0f);
|
||||
|
||||
/* The position should have increased */
|
||||
EXPECT_GT(m_jaguar->GetPosition(), initialPosition)
|
||||
<< "CAN Jaguar should have moved forwards while the reverse limit was on";
|
||||
}
|
||||
/**
|
||||
* Tests that inversion works in voltage mode
|
||||
*/
|
||||
TEST_F(CANJaguarTest, InvertingVoltageMode) {
|
||||
m_jaguar->SetVoltageMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->EnableControl();
|
||||
InversionTest(kMotorVoltage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that inversion works in percentMode
|
||||
*/
|
||||
TEST_F(CANJaguarTest, InvertingPercentMode) {
|
||||
m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
|
||||
m_jaguar->EnableControl();
|
||||
InversionTest(kMotorPercent);
|
||||
}
|
||||
/**
|
||||
* Tests that inversion works in SpeedMode
|
||||
*/
|
||||
TEST_F(CANJaguarTest, InvertingSpeedMode) {
|
||||
m_jaguar->SetSpeedMode(CANJaguar::QuadEncoder, 360, 0.1f, 0.005f, 0.00f);
|
||||
m_jaguar->EnableControl();
|
||||
InversionTest(kMotorSpeed, kMotorTime);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
public interface CANSpeedController extends SpeedController, PIDInterface, LiveWindowSendable {
|
||||
/**
|
||||
* Mode determines how the motor is controlled, used internally. This is meant to be subclassed by
|
||||
* enums (see {@link CANTalon.TalonControlMode CANTalon.TalonControlMode}).
|
||||
* enums
|
||||
*
|
||||
* <p>Note that the Jaguar does not support follower mode.
|
||||
*/
|
||||
@@ -146,11 +146,9 @@ public interface CANSpeedController extends SpeedController, PIDInterface, LiveW
|
||||
ITable table = getTable();
|
||||
if (table != null) {
|
||||
table.putString("~TYPE~", SMART_DASHBOARD_TYPE);
|
||||
table.putString("Type", getClass().getSimpleName()); // "CANTalon", "CANJaguar"
|
||||
table.putString("Type", getClass().getSimpleName());
|
||||
table.putNumber("Mode", getControlMode().getValue());
|
||||
if (getControlMode().isPID()) {
|
||||
// CANJaguar throws an exception if you try to get its PID constants
|
||||
// when it's not in a PID-compatible mode
|
||||
table.putNumber("p", getP());
|
||||
table.putNumber("i", getI());
|
||||
table.putNumber("d", getD());
|
||||
|
||||
@@ -13,8 +13,6 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
|
||||
/**
|
||||
* Texas Instruments / Vex Robotics Jaguar Speed Controller as a PWM device.
|
||||
*
|
||||
* @see CANJaguar CANJaguar for CAN control
|
||||
*/
|
||||
public class Jaguar extends PWMSpeedController {
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
/**
|
||||
* Exception indicating that the CAN driver layer has not been initialized. This happens when an
|
||||
* entry-point is called before a CAN driver plugin has been installed.
|
||||
*/
|
||||
public class CANJaguarVersionException extends RuntimeException {
|
||||
|
||||
public static final int kMinLegalFIRSTFirmwareVersion = 101;
|
||||
// 3330 was the first shipping RDK firmware version for the Jaguar
|
||||
public static final int kMinRDKFirmwareVersion = 3330;
|
||||
|
||||
public CANJaguarVersionException(int deviceNumber, int fwVersion) {
|
||||
super(getString(deviceNumber, fwVersion));
|
||||
System.out.println("fwVersion[" + deviceNumber + "]: " + fwVersion);
|
||||
}
|
||||
|
||||
static String getString(int deviceNumber, int fwVersion) {
|
||||
String msg;
|
||||
if (fwVersion < kMinRDKFirmwareVersion) {
|
||||
msg =
|
||||
"Jaguar " + deviceNumber
|
||||
+ " firmware is too old. It must be updated to at least version "
|
||||
+ Integer.toString(kMinLegalFIRSTFirmwareVersion)
|
||||
+ " of the FIRST approved firmware!";
|
||||
} else {
|
||||
msg =
|
||||
"Jaguar " + deviceNumber
|
||||
+ " firmware is not FIRST approved. It must be updated to at least version "
|
||||
+ Integer.toString(kMinLegalFIRSTFirmwareVersion)
|
||||
+ " of the FIRST approved firmware!";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -26,22 +26,6 @@ public class SimSpeedController {
|
||||
m_pub = MainNode.advertise(topic, Msgs.Float64());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
* <p>he PWM value is set using a range of -1.0 to 1.0, appropriately scaling the value for the
|
||||
* FPGA.
|
||||
*
|
||||
* @param speed The speed to set. Value should be between -1.0 and 1.0.
|
||||
* @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup(). If 0,
|
||||
* update immediately.
|
||||
* @deprecated For compatibility with CANJaguar
|
||||
*/
|
||||
@Deprecated
|
||||
public void set(double speed, byte syncGroup) {
|
||||
set(speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* Provides a base implementation for CAN Tests that forces a test of a particular mode to provide
|
||||
* tests of a certain type. This also allows for a standardized base setup for each test.
|
||||
*/
|
||||
public abstract class AbstractCANTest extends AbstractComsSetup {
|
||||
public static final double kMotorStopTime = 2;
|
||||
public static final double kMotorTime = 3;
|
||||
public static final double kMotorTimeSettling = 10;
|
||||
public static final double kPotentiometerSettlingTime = 10.0;
|
||||
public static final double kEncoderSettlingTime = 0.50;
|
||||
public static final double kEncoderSpeedTolerance = 20.0;
|
||||
public static final double kLimitSettlingTime = 20.0; // timeout in seconds
|
||||
public static final double kStartupTime = 0.50;
|
||||
public static final double kEncoderPositionTolerance = .75;
|
||||
public static final double kPotentiometerPositionTolerance = 10.0 / 360.0; // +/-10
|
||||
// degrees
|
||||
public static final double kCurrentTolerance = 0.1;
|
||||
|
||||
|
||||
/**
|
||||
* Stores the status value for the previous test. This is set immediately after a failure or
|
||||
* success and before the me is torn down.
|
||||
*/
|
||||
private String m_status = "";
|
||||
|
||||
/**
|
||||
* Extends the default test watcher in order to provide more information about a tests failure at
|
||||
* runtime.
|
||||
*/
|
||||
public class CANTestWatcher extends DefaultTestWatcher {
|
||||
@Override
|
||||
protected void failed(Throwable exception, Description description) {
|
||||
super.failed(exception, description, m_status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestWatcher getOverridenTestWatcher() {
|
||||
return new CANTestWatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Fixture under test.
|
||||
*/
|
||||
private CANMotorEncoderFixture m_me;
|
||||
|
||||
/**
|
||||
* Retrieves the CANMotorEncoderFixture.
|
||||
*
|
||||
* @return the CANMotorEncoderFixture for this test.
|
||||
*/
|
||||
public CANMotorEncoderFixture getME() {
|
||||
return m_me;
|
||||
}
|
||||
|
||||
/**
|
||||
* This runs BEFORE the setup of the inherited class.
|
||||
*/
|
||||
@Before
|
||||
public final void preSetup() {
|
||||
m_status = "";
|
||||
m_me = TestBench.getInstance().getCanJaguarPair();
|
||||
m_me.setup();
|
||||
m_me.getMotor().setSafetyEnabled(false);
|
||||
}
|
||||
|
||||
@After
|
||||
public final void tearDown() throws Exception {
|
||||
try {
|
||||
// Stores the status data before tearing it down.
|
||||
// If the test fails unexpectedly then this could cause an exception.
|
||||
m_status = m_me.printStatus();
|
||||
} finally {
|
||||
m_me.teardown();
|
||||
}
|
||||
m_me = null;
|
||||
}
|
||||
|
||||
protected void setCANJaguar(double seconds, double value) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
getME().getMotor().set(value);
|
||||
Timer.delay(seconds / 50.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the CAN Motor Controller in Current Quad Encoder mode.
|
||||
*/
|
||||
public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static Logger logger = Logger.getLogger(CANCurrentQuadEncoderModeTest.class.getName());
|
||||
private static final double kStoppedValue = 0;
|
||||
private static final double kRunningValue = 3.0;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
getME().getMotor().set(kRunningValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
getME().getMotor().set(-kRunningValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().setCurrentMode(CANJaguar.kQuadEncoder, 360, 10.0, 4.0, 1.0);
|
||||
getME().getMotor().enableControl();
|
||||
getME().getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDriveToCurrentPositive() {
|
||||
double setpoint = 1.6f;
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
for (int i = 0; i < 10; i++) {
|
||||
setCANJaguar(1.0, setpoint);
|
||||
|
||||
if (Math.abs(getME().getMotor().getOutputCurrent() - setpoint) <= kCurrentTolerance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("The desired output current was not reached", setpoint, getME().getMotor()
|
||||
.getOutputCurrent(), kCurrentTolerance);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDriveToCurrentNegative() {
|
||||
double setpoint = -1.6f;
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
for (int i = 0; i < 10; i++) {
|
||||
setCANJaguar(1.0, setpoint);
|
||||
|
||||
if (Math.abs(getME().getMotor().getOutputCurrent() - Math.abs(setpoint))
|
||||
<= kCurrentTolerance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("The desired output current was not reached", Math.abs(setpoint), getME()
|
||||
.getMotor().getOutputCurrent(), kCurrentTolerance);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* The default test set to run against the CAN Motor Controllers.
|
||||
*/
|
||||
public class CANDefaultTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANDefaultTest.class.getName());
|
||||
private final PollingWait m_wait = new PollingWait().timeoutAfter(65, TimeUnit.MILLISECONDS)
|
||||
.pollEvery(10, TimeUnit.MILLISECONDS);
|
||||
|
||||
private static final double kSpikeTime = .5;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().enableControl();
|
||||
getME().getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime / 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultGet() {
|
||||
m_wait.until(new RunnableAssert("Waiting for CAN Jaguar get to return 0") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not initialize stopped", 0.0, getME().getMotor().get(),
|
||||
.01f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBusVoltage() {
|
||||
m_wait.until(new RunnableAssert("Waiting for default bus voltage to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start at 14 volts", 14.0f, getME().getMotor()
|
||||
.getBusVoltage(), 2.0f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputVoltage() {
|
||||
m_wait.until(new RunnableAssert("Waiting for output voltage to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start with an output voltage of 0", 0.0f, getME()
|
||||
.getMotor().getOutputVoltage(), 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputCurrent() {
|
||||
m_wait.until(new RunnableAssert("Waiting for output current to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start with an output current of 0", 0.0f, getME()
|
||||
.getMotor().getOutputCurrent(), 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTemperature() {
|
||||
final double room_temp = 18.0f;
|
||||
m_wait.until(new RunnableAssert("Waiting for temperature to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(
|
||||
"CAN Jaguar did not start with an initial temperature greater than " + room_temp,
|
||||
getME().getMotor().getTemperature(), is(greaterThan(room_temp)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultForwardLimit() {
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
m_wait.until(new RunnableAssert("Waiting for forward limit to not be set") {
|
||||
@Override
|
||||
public void run() {
|
||||
getME().getMotor().set(0);
|
||||
assertTrue("CAN Jaguar did not start with the Forward Limit Switch Off", getME()
|
||||
.getMotor()
|
||||
.getForwardLimitOK());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultReverseLimit() {
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
m_wait.until(new RunnableAssert("Waiting for reverse limit to not be set") {
|
||||
@Override
|
||||
public void run() {
|
||||
getME().getMotor().set(0);
|
||||
assertTrue("CAN Jaguar did not start with the Reverse Limit Switch Off", getME()
|
||||
.getMotor()
|
||||
.getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNoFaults() {
|
||||
m_wait.until(new RunnableAssert("Waiting for no faults") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar initialized with Faults", 0, getME().getMotor().getFaults());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFakeLimitSwitchForwards() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
// When
|
||||
getME().getForwardLimit().set(true);
|
||||
|
||||
// Then
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("Setting the CANJAguar forward limit switch high") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertFalse(
|
||||
"Setting the forward limit switch high did not cause the forward limit switch to "
|
||||
+ "trigger",
|
||||
getME().getMotor().getForwardLimitOK());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFakeLimitSwitchReverse() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
// When
|
||||
getME().getReverseLimit().set(true);
|
||||
|
||||
// Then
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("Setting the CANJAguar reverse limit switch high") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertFalse(
|
||||
"Setting the reverse limit switch high did not cause the forward limit switch to "
|
||||
+ "trigger",
|
||||
getME().getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPositionModeVerifiesOnBrownOut() {
|
||||
final double setpoint = 1.0;
|
||||
|
||||
// Given
|
||||
getME().getMotor().setPositionMode(CANJaguar.kQuadEncoder, 360, 10.0, 0.1, 0.0);
|
||||
getME().getMotor().enableControl();
|
||||
setCANJaguar(kMotorTime, 0.0);
|
||||
|
||||
getME().powerOn();
|
||||
|
||||
// When
|
||||
/* Turn the spike off and on again */
|
||||
|
||||
getME().powerOff();
|
||||
Timer.delay(kSpikeTime);
|
||||
getME().powerOn();
|
||||
Timer.delay(kSpikeTime);
|
||||
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter(15, TimeUnit.SECONDS).pollEvery(1, TimeUnit.MILLISECONDS);
|
||||
/*
|
||||
* The jaguar should automatically get set to quad encoder position mode, so
|
||||
* it should be able to reach a setpoint in a couple seconds.
|
||||
*/
|
||||
|
||||
wait.until(new RunnableAssert("Waiting for CANJaguar to reach set-point") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(setpoint);
|
||||
assertEquals("CANJaguar should have resumed PID control after power cycle", setpoint,
|
||||
getME().getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the CAN Jaguar inverted.
|
||||
*
|
||||
* <p>Created by Patrick Murphy on 3/30/15.
|
||||
*/
|
||||
public class CANJaguarInversionTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANJaguarInversionTest.class.getName());
|
||||
private static final double m_motorVoltage = 2.0;
|
||||
private static final double m_motorPercent = 0.1;
|
||||
private static final double m_motorSpeed = 10;
|
||||
private static final double m_delayTime = 0.75;
|
||||
private static final double m_speedModeDelayTime = 2.0;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertingVoltageMode() {
|
||||
getME().getMotor().setVoltageMode(CANJaguar.kQuadEncoder, 360);
|
||||
inversionTest(m_motorVoltage, m_delayTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertingPercentMode() {
|
||||
getME().getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
inversionTest(m_motorPercent, m_delayTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertingSpeedMode() {
|
||||
getME().getMotor().setSpeedMode(CANJaguar.kQuadEncoder, 360, 0.1, 0.003, 0.01);
|
||||
inversionTest(m_motorSpeed, m_speedModeDelayTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an inversion test To use set the jaguar to the proper mode(PercentVbus, voltage, speed).
|
||||
*
|
||||
* @param setPoint the speed/voltage/percent to set the motor to
|
||||
* @param delayTime the amount of time to delay between starting a motor and checking the encoder
|
||||
*/
|
||||
private void inversionTest(double setPoint, double delayTime) {
|
||||
final CANJaguar jag = getME().getMotor();
|
||||
jag.enableControl();
|
||||
jag.setInverted(false);
|
||||
jag.set(setPoint);
|
||||
Timer.delay(delayTime);
|
||||
final double initialSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
jag.setInverted(true);
|
||||
jag.set(setPoint);
|
||||
Timer.delay(delayTime);
|
||||
jag.set(0.0);
|
||||
final double finalSpeed = jag.getSpeed();
|
||||
assertTrue("Inverting with Positive value does not invert direction",
|
||||
Math.signum(initialSpeed) != Math.signum(finalSpeed));
|
||||
jag.set(-setPoint);
|
||||
Timer.delay(delayTime);
|
||||
final double newInitialSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
jag.setInverted(false);
|
||||
jag.set(-setPoint);
|
||||
Timer.delay(delayTime);
|
||||
final double newFinalSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
assertTrue("Inverting with Negative value does not invert direction",
|
||||
Math.signum(newInitialSpeed) != Math.signum(newFinalSpeed));
|
||||
}
|
||||
}
|
||||
@@ -1,397 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the CAN motor in PercentQuadEncoderMode.
|
||||
*/
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPercentQuadEncoderModeTest.class
|
||||
.getName());
|
||||
private static final double kStoppedValue = 0;
|
||||
private static final double kRunningValue = 0.3;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
getME().getMotor().set(kRunningValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
getME().getMotor().set(-kRunningValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
getME().getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
getME().getMotor().enableControl();
|
||||
getME().getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableStopsTheMotor() {
|
||||
// given
|
||||
getME().getMotor().enableControl();
|
||||
setCANJaguar(kMotorTime / 2, 1);
|
||||
getME().getMotor().disableControl();
|
||||
// when
|
||||
simpleLog(Level.FINER, "The motor should stop running now");
|
||||
setCANJaguar(kMotorTime / 2, 1);
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
setCANJaguar(kMotorTime / 2, 1);
|
||||
|
||||
// then
|
||||
assertEquals("Speed did not go to zero when disabled in percent mode", 0, getME().getMotor()
|
||||
.getSpeed(), kEncoderSpeedTolerance);
|
||||
assertEquals(initialPosition, getME().getMotor().getPosition(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateForward() {
|
||||
// Given
|
||||
getME().getMotor().enableControl();
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
// When
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
runMotorForward();
|
||||
|
||||
// Then
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kMotorTimeSettling, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("CANJaguar position incrementing") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorForward();
|
||||
assertThat("CANJaguar position should have increased after the motor moved", getME()
|
||||
.getMotor().getPosition(), is(greaterThan(initialPosition)));
|
||||
}
|
||||
});
|
||||
|
||||
stopMotor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateReverse() {
|
||||
// Given
|
||||
getME().getMotor().enableControl();
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
// When
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
runMotorReverse();
|
||||
|
||||
// Then
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kMotorTimeSettling, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("CANJaguar position decrementing") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorReverse();
|
||||
assertThat("CANJaguar position should have decreased after the motor moved", getME()
|
||||
.getMotor().getPosition(), is(lessThan(initialPosition)));
|
||||
}
|
||||
});
|
||||
stopMotor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to not rotate forwards when the fake limit switch is tripped.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotRotateForwards_WhenFakeLimitSwitchForwardsIsTripped() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getForwardLimit().set(true);
|
||||
getME().getReverseLimit().set(false);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
stopMotor();
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
/* Wait until the limits are recognized by the CANJaguar. */
|
||||
wait.until(new RunnableAssert(
|
||||
"Waiting for the forward and reverse limit switches to be in the correct state") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
stopMotor();
|
||||
assertFalse("[TEST SETUP] The forward limit switch is not in the correct state", getME()
|
||||
.getMotor().getForwardLimitOK());
|
||||
assertTrue("[TEST SETUP]The reverse limit switch is not in the correct state", getME()
|
||||
.getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
|
||||
// When
|
||||
/*
|
||||
* Drive the speed controller briefly to move the encoder. If the limit
|
||||
* switch is recognized, it shouldn't actually move.
|
||||
*/
|
||||
setCANJaguar(kMotorTime, 1);
|
||||
stopMotor();
|
||||
|
||||
// Then
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
assertEquals("CAN Jaguar should not have moved with the forward limit switch pressed",
|
||||
initialPosition, getME().getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if we can rotate in reverse when the limit switch.
|
||||
*/
|
||||
@Test
|
||||
public void shouldRotateReverse_WhenFakeLimitSwitchForwardsIsTripped() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getForwardLimit().set(true);
|
||||
getME().getReverseLimit().set(false);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
stopMotor();
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
PollingWait limitWait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
/* Wait until the limits are recognized by the CANJaguar. */
|
||||
limitWait.until(new RunnableAssert(
|
||||
"Waiting for the forward and reverse limit switches to be in the correct state") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
stopMotor();
|
||||
assertFalse("[TEST SETUP] The forward limit switch is not in the correct state", getME()
|
||||
.getMotor().getForwardLimitOK());
|
||||
assertTrue("[TEST SETUP] The reverse limit switch is not in the correct state", getME()
|
||||
.getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
|
||||
// When
|
||||
/*
|
||||
* Drive the speed controller in the other direction. It should actually
|
||||
* move, since only the forward switch is activated.
|
||||
*/
|
||||
setCANJaguar(kMotorTime, -1);
|
||||
// Then
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kMotorTimeSettling, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("Waiting for the encoder to update") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorReverse();
|
||||
assertThat("CAN Jaguar should have moved in reverse while the forward limit was on",
|
||||
getME().getMotor().getPosition(), is(lessThan(initialPosition)));
|
||||
}
|
||||
|
||||
});
|
||||
stopMotor();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit switch.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotRotateReverse_WhenFakeLimitSwitchReversesIsTripped() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getForwardLimit().set(false);
|
||||
getME().getReverseLimit().set(true);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
stopMotor();
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
/* Wait until the limits are recognized by the CANJaguar. */
|
||||
wait.until(new RunnableAssert(
|
||||
"Waiting for the forward and reverse limit switches to be in the correct state") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
stopMotor();
|
||||
assertTrue("[TEST SETUP] The forward limit switch is not in the correct state", getME()
|
||||
.getMotor().getForwardLimitOK());
|
||||
assertFalse("[TEST SETUP] The reverse limit switch is not in the correct state", getME()
|
||||
.getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
|
||||
// When
|
||||
/*
|
||||
* Drive the speed controller backwards briefly to move the encoder. If the
|
||||
* limit switch is recognized, it shouldn't actually move.
|
||||
*/
|
||||
setCANJaguar(kMotorTime, -1);
|
||||
stopMotor();
|
||||
|
||||
// Then
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
assertEquals("CAN Jaguar should not have moved with the limit switch pressed", initialPosition,
|
||||
getME().getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit
|
||||
* switch.
|
||||
*/
|
||||
@Test
|
||||
public void shouldRotateForward_WhenFakeLimitSwitchReversesIsTripped() {
|
||||
// Given
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
getME().getForwardLimit().set(false);
|
||||
getME().getReverseLimit().set(true);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
PollingWait limitWait =
|
||||
new PollingWait().timeoutAfter((long) kLimitSettlingTime, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
/* Wait until the limits are recognized by the CANJaguar. */
|
||||
limitWait.until(new RunnableAssert(
|
||||
"Waiting for the forward and reverse limit switches to be in the correct state") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
stopMotor();
|
||||
assertTrue("[TEST SETUP] The forward limit switch is not in the correct state", getME()
|
||||
.getMotor().getForwardLimitOK());
|
||||
assertFalse("[TEST SETUP] The reverse limit switch is not in the correct state", getME()
|
||||
.getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
|
||||
final double initialPosition = getME().getMotor().getPosition();
|
||||
|
||||
// When
|
||||
/*
|
||||
* Drive the speed controller in the other direction. It should actually
|
||||
* move, since only the reverse switch is activated.
|
||||
*/
|
||||
setCANJaguar(kMotorTime, 1);
|
||||
// Then
|
||||
/* The position should have increased */
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kMotorTimeSettling, TimeUnit.SECONDS).pollEvery(1,
|
||||
TimeUnit.MILLISECONDS);
|
||||
wait.until(new RunnableAssert("Waiting for the encoder to update") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorForward();
|
||||
assertThat("CAN Jaguar should have moved forwards while the reverse limit was on", getME()
|
||||
.getMotor().getPosition(), is(greaterThan(initialPosition)));
|
||||
}
|
||||
|
||||
});
|
||||
stopMotor();
|
||||
}
|
||||
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateForwardEncoderToFPGA() {
|
||||
getME().getMotor().enableControl();
|
||||
final double jagInitialPosition = getME().getMotor().getPosition();
|
||||
final double encoderInitialPosition = getME().getEncoder().get();
|
||||
getME().getMotor().set(1);
|
||||
Timer.delay(kMotorStopTime);
|
||||
getME().getMotor().set(0);
|
||||
|
||||
delayTillInCorrectStateWithMessage(Level.FINE, kEncoderSettlingTime,
|
||||
"Forward Encodeder settling", new BooleanCheck() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return Math.abs((getME().getMotor().getPosition() - jagInitialPosition)
|
||||
- (getME().getEncoder().get() - encoderInitialPosition))
|
||||
< kEncoderPositionTolerance;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(getME().getMotor().getPosition() - jagInitialPosition, getME().getEncoder().get()
|
||||
- encoderInitialPosition, kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateReverseEncoderToFPGA() {
|
||||
getME().getMotor().enableControl();
|
||||
final double jagInitialPosition = getME().getMotor().getPosition();
|
||||
final double encoderInitialPosition = getME().getEncoder().get();
|
||||
getME().getMotor().set(-1);
|
||||
Timer.delay(kMotorStopTime);
|
||||
getME().getMotor().set(0);
|
||||
|
||||
delayTillInCorrectStateWithMessage(Level.FINE, kEncoderSettlingTime,
|
||||
"Forward Encodeder settling", new BooleanCheck() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return Math.abs((getME().getMotor().getPosition() - jagInitialPosition)
|
||||
- (getME().getEncoder().get() - encoderInitialPosition))
|
||||
< kEncoderPositionTolerance;
|
||||
}
|
||||
});
|
||||
assertEquals(getME().getMotor().getPosition() - jagInitialPosition, getME().getEncoder().get()
|
||||
- encoderInitialPosition, kEncoderPositionTolerance);
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the CAN Motor controller in Potentiometer Mode.
|
||||
*/
|
||||
public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPositionPotentiometerModeTest.class
|
||||
.getName());
|
||||
|
||||
private static final double kStoppedValue = 0;
|
||||
|
||||
private static final int defaultPotAngle = 180;
|
||||
private static final double maxPotVoltage = 3.0;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
getME().getMotor().set(.5);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
getME().getMotor().set(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
getME().getMotor().set(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().setPositionMode(CANJaguar.kPotentiometer, 5.0, 0.1, 2.0);
|
||||
// getME().getMotor().configPotentiometerTurns(rotationRange);
|
||||
getME().getFakePot().setMaxVoltage(maxPotVoltage);
|
||||
getME().getFakePot().setVoltage(1.5);
|
||||
stopMotor();
|
||||
getME().getMotor().enableControl();
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead of the one built
|
||||
* into the CAN Jaguar.
|
||||
*/
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateForward() {
|
||||
final int initialPosition = getME().getEncoder().get();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
Timer.delay(kMotorTimeSettling);
|
||||
getME().getMotor().set(defaultPotAngle);
|
||||
|
||||
/* The position should have increased */
|
||||
assertThat("CAN Jaguar position should have increased after the motor moved", getME()
|
||||
.getEncoder().get(), is(greaterThan(initialPosition)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead of the one built
|
||||
* into the CAN Jaguar.
|
||||
*/
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateReverse() {
|
||||
final int initialPosition = getME().getEncoder().get();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
Timer.delay(kMotorTimeSettling);
|
||||
getME().getMotor().set(defaultPotAngle);
|
||||
|
||||
/* The position should have increased */
|
||||
assertThat("CAN Jaguar position should have increased after the motor moved", getME()
|
||||
.getEncoder().get(), is(greaterThan(initialPosition)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can get a position in potentiometer mode, using an analog output as a fake
|
||||
* potentiometer.
|
||||
*/
|
||||
@Test
|
||||
public void testFakePotentiometerPosition() {
|
||||
// TODO When https://github.com/Pragmatists/JUnitParams/issues/5 is resolved
|
||||
// make this test parameterized
|
||||
|
||||
// Given
|
||||
PollingWait wait =
|
||||
new PollingWait().timeoutAfter((long) kPotentiometerSettlingTime, TimeUnit.SECONDS)
|
||||
.pollEvery(1, TimeUnit.MILLISECONDS);
|
||||
RunnableAssert assertion =
|
||||
new RunnableAssert("Waiting for potentiometer position to be correct") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertEquals(
|
||||
"CAN Jaguar should have returned the potentiometer position set by the analog "
|
||||
+ "output",
|
||||
getME().getFakePot().getVoltage(), getME().getMotor().getPosition() * 3,
|
||||
kPotentiometerPositionTolerance * 3);
|
||||
}
|
||||
};
|
||||
|
||||
// When
|
||||
getME().getFakePot().setVoltage(0.0);
|
||||
// Then
|
||||
wait.until(assertion);
|
||||
|
||||
// When
|
||||
getME().getFakePot().setVoltage(1.0);
|
||||
// Then
|
||||
wait.until(assertion);
|
||||
|
||||
// When
|
||||
getME().getFakePot().setVoltage(2.0);
|
||||
// Then
|
||||
wait.until(assertion);
|
||||
|
||||
// When
|
||||
getME().getFakePot().setVoltage(3.0);
|
||||
// Then
|
||||
wait.until(assertion);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the CAN Motor Encoders in QuadEncoder mode.
|
||||
*/
|
||||
public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPositionQuadEncoderModeTest.class
|
||||
.getName());
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
double postion = getME().getMotor().getPosition();
|
||||
getME().getMotor().set(postion + 100);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
double postion = getME().getMotor().getPosition();
|
||||
getME().getMotor().set(postion - 100);
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().setPositionMode(CANJaguar.kQuadEncoder, 360, 10.0f, 0.01f, 0.0f);
|
||||
getME().getMotor().enableControl(0);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
@Ignore("The encoder initial position is not validated so is sometimes not set properly")
|
||||
@Test
|
||||
public void testSetEncoderInitialPositionWithEnable() {
|
||||
// given
|
||||
final double encoderValue = 4823;
|
||||
// when
|
||||
getME().getMotor().enableControl(encoderValue);
|
||||
getME().getMotor().disableControl();
|
||||
delayTillInCorrectStateWithMessage(Level.FINE, kEncoderSettlingTime, "Encoder value settling",
|
||||
new BooleanCheck() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
getME().getMotor().set(getME().getMotor().getPosition());
|
||||
return Math.abs(getME().getMotor().getPosition() - encoderValue) < 40;
|
||||
}
|
||||
});
|
||||
// then
|
||||
assertEquals(encoderValue, getME().getMotor().getPosition(), 40);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on the Jaguar.
|
||||
*/
|
||||
@Test
|
||||
public void testEncoderPositionPIDForward() {
|
||||
|
||||
double setpoint = getME().getMotor().getPosition() + 1.0f;
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
getME().getMotor().set(setpoint);
|
||||
setCANJaguar(kMotorTimeSettling, setpoint);
|
||||
|
||||
assertEquals("CAN Jaguar should have reached setpoint with PID control", setpoint, getME()
|
||||
.getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on the Jaguar.
|
||||
*/
|
||||
@Test
|
||||
public void testEncoderPositionPIDReverse() {
|
||||
|
||||
double setpoint = getME().getMotor().getPosition() - 1.0f;
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
getME().getMotor().set(setpoint);
|
||||
setCANJaguar(kMotorTimeSettling, setpoint);
|
||||
|
||||
assertEquals("CAN Jaguar should have reached setpoint with PID control", setpoint, getME()
|
||||
.getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the CAN Speed controllers in quad mode.
|
||||
*/
|
||||
public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPercentQuadEncoderModeTest.class
|
||||
.getName());
|
||||
/**
|
||||
* The stopped value in rev/min.
|
||||
*/
|
||||
private static final double kStoppedValue = 0;
|
||||
/**
|
||||
* The running value in rev/min.
|
||||
*/
|
||||
private static final double kRunningValue = 50;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().setSpeedMode(CANJaguar.kQuadEncoder, 360, 0.1f, 0.003f, 0.01f);
|
||||
getME().getMotor().enableControl();
|
||||
getME().getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSpeed() {
|
||||
assertEquals("CAN Jaguar did not start with an initial speed of zero", 0.0f, getME()
|
||||
.getMotor()
|
||||
.getSpeed(), 0.3f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor forward in Speed mode and get a position back.
|
||||
*/
|
||||
@Test
|
||||
public void testRotateForwardSpeed() {
|
||||
double speed = 50.0f;
|
||||
double initialPosition = getME().getMotor().getPosition();
|
||||
setCANJaguar(2 * kMotorTime, speed);
|
||||
assertEquals("The motor did not reach the required speed in speed mode", speed, getME()
|
||||
.getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
assertThat("The motor did not move forward in speed mode", getME().getMotor().getPosition(),
|
||||
is(greaterThan(initialPosition)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor backwards in Speed mode and get a position back.
|
||||
*/
|
||||
@Test
|
||||
public void testRotateReverseSpeed() {
|
||||
double speed = -50.0f;
|
||||
double initialPosition = getME().getMotor().getPosition();
|
||||
setCANJaguar(2 * kMotorTime, speed);
|
||||
assertEquals("The motor did not reach the required speed in speed mode", speed, getME()
|
||||
.getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
assertThat("The motor did not move in reverse in speed mode", getME().getMotor()
|
||||
.getPosition(),
|
||||
is(lessThan(initialPosition)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractTestSuite;
|
||||
|
||||
/**
|
||||
* All of the tests to cover the CAN Motor Controllers.
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({CANCurrentQuadEncoderModeTest.class, CANDefaultTest.class,
|
||||
CANJaguarInversionTest.class, CANPercentQuadEncoderModeTest.class,
|
||||
CANPositionPotentiometerModeTest.class, CANPositionQuadEncoderModeTest.class,
|
||||
CANSpeedQuadEncoderModeTest.class, CANVoltageQuadEncoderModeTest.class})
|
||||
public class CANTestSuite extends AbstractTestSuite {
|
||||
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the CAN motor controllers in voltage mode work correctly.
|
||||
*/
|
||||
public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANVoltageQuadEncoderModeTest.class
|
||||
.getName());
|
||||
/**
|
||||
* The stopped value in volts.
|
||||
*/
|
||||
private static final double kStoppedValue = 0;
|
||||
/**
|
||||
* The running value in volts.
|
||||
*/
|
||||
private static final double kRunningValue = 4;
|
||||
|
||||
private static final double kVoltageTolerance = .25;
|
||||
|
||||
private static final PollingWait kWait = new PollingWait().timeoutAfter(
|
||||
(long) kMotorTimeSettling, TimeUnit.SECONDS).pollEvery(1, TimeUnit.MILLISECONDS);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
getME().getMotor().set(kRunningValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
getME().getMotor().set(-kRunningValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
getME().getMotor().setVoltageMode(CANJaguar.kQuadEncoder, 360);
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kStartupTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateForwardToVoltage() {
|
||||
setCANJaguar(kMotorTime, Math.PI);
|
||||
assertEquals("The output voltage did not match the desired voltage set-point", Math.PI, getME()
|
||||
.getMotor().getOutputVoltage(), kVoltageTolerance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateReverseToVoltage() {
|
||||
setCANJaguar(kMotorTime, -Math.PI);
|
||||
assertEquals("The output voltage did not match the desired voltage set-point", -Math.PI,
|
||||
getME().getMotor().getOutputVoltage(), kVoltageTolerance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the test to have the CANJaguar running at the target voltage.
|
||||
*
|
||||
* @param targetValue the target voltage
|
||||
* @param wait the PollingWait to to use to wait for the setup to complete with
|
||||
*/
|
||||
private void setupMotorVoltageForTest(final double targetValue, PollingWait wait) {
|
||||
getME().getMotor().enableControl();
|
||||
setCANJaguar(1, targetValue);
|
||||
wait.until(new RunnableAssert(
|
||||
"[SETUP] Waiting for the output voltage to match the set output value") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(targetValue);
|
||||
assertEquals("[TEST SETUP] The output voltage should have matched the set value",
|
||||
targetValue, getME().getMotor().getOutputVoltage(), 0.5);
|
||||
assertEquals("[TEST SETUP] The set value did not match the get value", targetValue, getME()
|
||||
.getMotor().get(), 0.5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMaxOutputVoltagePositive() {
|
||||
// given
|
||||
double maxVoltage = 3;
|
||||
|
||||
setupMotorVoltageForTest(kRunningValue, kWait);
|
||||
|
||||
final double fastSpeed = getME().getMotor().getSpeed();
|
||||
|
||||
// when
|
||||
getME().getMotor().configMaxOutputVoltage(maxVoltage);
|
||||
|
||||
setCANJaguar(1, kRunningValue);
|
||||
// Then
|
||||
kWait.until(new RunnableAssert("Waiting for the speed to reduce using max output voltage") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorForward();
|
||||
assertThat("Speed did not reduce when the max output voltage was set", fastSpeed,
|
||||
is(greaterThan(getME().getMotor().getSpeed())));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxOutputVoltagePositiveSetToZeroStopsMotor() {
|
||||
// given
|
||||
final double maxVoltage = 0;
|
||||
|
||||
setupMotorVoltageForTest(kRunningValue, kWait);
|
||||
// when
|
||||
getME().getMotor().configMaxOutputVoltage(maxVoltage);
|
||||
|
||||
setCANJaguar(1, kRunningValue);
|
||||
// then
|
||||
kWait.until(new RunnableAssert(
|
||||
"Waiting for the speed to reduce to zero using max output voltage") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorForward();
|
||||
assertEquals("Speed did not go to zero when the max output voltage was set to "
|
||||
+ maxVoltage, 0, getME().getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMaxOutputVoltageNegative() {
|
||||
// given
|
||||
double maxVoltage = 3;
|
||||
|
||||
setupMotorVoltageForTest(-kRunningValue, kWait);
|
||||
final double fastSpeed = getME().getMotor().getSpeed();
|
||||
|
||||
// when
|
||||
getME().getMotor().configMaxOutputVoltage(maxVoltage);
|
||||
setCANJaguar(1, -kRunningValue);
|
||||
|
||||
// then
|
||||
kWait.until(new RunnableAssert("Waiting for the speed to reduce using max output voltage") {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorReverse();
|
||||
assertThat("Speed did not reduce when the max output voltage was set", fastSpeed,
|
||||
is(lessThan(getME().getMotor().getSpeed())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxOutputVoltageNegativeSetToZeroStopsMotor() {
|
||||
// given
|
||||
final double maxVoltage = 0;
|
||||
setupMotorVoltageForTest(-kRunningValue, kWait);
|
||||
|
||||
// when
|
||||
getME().getMotor().configMaxOutputVoltage(maxVoltage);
|
||||
setCANJaguar(1, -kRunningValue);
|
||||
|
||||
// Then
|
||||
kWait.until(new RunnableAssert(
|
||||
"Waiting for the speed to reduce to zero using max output voltage") {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
runMotorReverse();
|
||||
assertEquals("Speed did not go to zero when the max output voltage was set to "
|
||||
+ maxVoltage, 0, getME().getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Provides a suite of tests to cover CANJaguar fully in all different control modes and with each
|
||||
* supported positional input. Different setup parameters are provided in each Test class. All test
|
||||
* classes that want to take advantage of the default test setup frameworks in place should extend
|
||||
* {@link edu.wpi.first.wpilibj.can.AbstractCANTest AbstractCANTest}.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
@@ -1,199 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.fixtures;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Relay;
|
||||
import edu.wpi.first.wpilibj.Relay.Direction;
|
||||
import edu.wpi.first.wpilibj.Relay.Value;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.mockhardware.FakePotentiometerSource;
|
||||
|
||||
/**
|
||||
* A fixture that wraps a {@link CANJaguar}.
|
||||
*/
|
||||
public abstract class CANMotorEncoderFixture extends MotorEncoderFixture<CANJaguar> implements
|
||||
ITestFixture {
|
||||
private static final Logger logger = Logger.getLogger(CANMotorEncoderFixture.class.getName());
|
||||
public static final double RELAY_POWER_UP_TIME = .75;
|
||||
private FakePotentiometerSource m_potSource;
|
||||
private DigitalOutput m_forwardLimit;
|
||||
private DigitalOutput m_reverseLimit;
|
||||
private Relay m_powerCycler;
|
||||
private boolean m_initialized = false;
|
||||
|
||||
protected abstract FakePotentiometerSource giveFakePotentiometerSource();
|
||||
|
||||
protected abstract DigitalOutput giveFakeForwardLimit();
|
||||
|
||||
protected abstract DigitalOutput giveFakeReverseLimit();
|
||||
|
||||
protected abstract Relay givePowerCycleRelay();
|
||||
|
||||
public CANMotorEncoderFixture() {
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
synchronized (this) {
|
||||
if (!m_initialized) {
|
||||
m_initialized = true;// This ensures it is only initialized once
|
||||
|
||||
m_powerCycler = givePowerCycleRelay();
|
||||
m_powerCycler.setDirection(Direction.kForward);
|
||||
logger.fine("Turning on the power!");
|
||||
m_powerCycler.set(Value.kForward);
|
||||
m_forwardLimit = giveFakeForwardLimit();
|
||||
m_reverseLimit = giveFakeReverseLimit();
|
||||
m_forwardLimit.set(false);
|
||||
m_reverseLimit.set(false);
|
||||
m_potSource = giveFakePotentiometerSource();
|
||||
Timer.delay(RELAY_POWER_UP_TIME); // Delay so the relay has time to boot
|
||||
// up
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setup() {
|
||||
initialize(); // This initializes the Relay first
|
||||
return super.setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reset() {
|
||||
initialize();
|
||||
m_potSource.reset();
|
||||
m_forwardLimit.set(false);
|
||||
m_reverseLimit.set(false);
|
||||
getMotor().setPercentMode(); // Get the Jaguar into a mode where setting the
|
||||
// speed means stop
|
||||
return super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
boolean wasNull = false;
|
||||
if (m_potSource != null) {
|
||||
m_potSource.free();
|
||||
m_potSource = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_forwardLimit != null) {
|
||||
m_forwardLimit.set(false);
|
||||
m_forwardLimit.free();
|
||||
m_forwardLimit = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_reverseLimit != null) {
|
||||
m_reverseLimit.set(false);
|
||||
m_reverseLimit.free();
|
||||
m_reverseLimit = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
boolean superTornDown = false;
|
||||
try {
|
||||
superTornDown = super.teardown();
|
||||
} finally {
|
||||
try {
|
||||
if (getMotor() != null) {
|
||||
getMotor().disableControl();
|
||||
getMotor().free();
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
} finally {
|
||||
if (m_powerCycler != null) {
|
||||
m_powerCycler.free();
|
||||
m_powerCycler = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wasNull) {
|
||||
throw new RuntimeException("CANMotorEncoderFixture had a null value at teardown");
|
||||
}
|
||||
|
||||
return superTornDown;
|
||||
}
|
||||
|
||||
public FakePotentiometerSource getFakePot() {
|
||||
initialize();
|
||||
return m_potSource;
|
||||
}
|
||||
|
||||
public DigitalOutput getForwardLimit() {
|
||||
initialize();
|
||||
return m_forwardLimit;
|
||||
}
|
||||
|
||||
public DigitalOutput getReverseLimit() {
|
||||
initialize();
|
||||
return m_reverseLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the current status of the fixture.
|
||||
*/
|
||||
public String printStatus() {
|
||||
StringBuilder status = new StringBuilder("CAN Motor Encoder Status: ");
|
||||
if (getMotor() != null) {
|
||||
status.append("\t" + getMotor().getDescription() + "\n");
|
||||
status.append("\tFault = " + getMotor().getFaults() + "\n");
|
||||
status.append("\tValue = " + getMotor().get() + "\n");
|
||||
status.append("\tOutputVoltage = " + getMotor().getOutputVoltage() + "\n");
|
||||
status.append("\tPosition = " + getMotor().getPosition() + "\n");
|
||||
status.append("\tForward Limit Ok = " + getMotor().getForwardLimitOK() + "\n");
|
||||
status.append("\tReverse Limit Ok = " + getMotor().getReverseLimitOK() + "\n");
|
||||
} else {
|
||||
status.append("\t" + "CANJaguar Motor = null" + "\n");
|
||||
}
|
||||
if (m_forwardLimit != null) {
|
||||
status.append("\tForward Limit Output = " + m_forwardLimit.get() + "\n");
|
||||
} else {
|
||||
status.append("\tForward Limit Output = null" + "\n");
|
||||
}
|
||||
if (m_reverseLimit != null) {
|
||||
status.append("\tReverse Limit Output = " + m_reverseLimit.get() + "\n");
|
||||
} else {
|
||||
status.append("\tReverse Limit Output = null" + "\n");
|
||||
}
|
||||
|
||||
return status.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browns out the fixture for a specific ammount of time.
|
||||
*
|
||||
* @param seconds The number of seconds to brown out for.
|
||||
*/
|
||||
public void brownOut(double seconds) {
|
||||
initialize();
|
||||
powerOff();
|
||||
Timer.delay(seconds);
|
||||
powerOn();
|
||||
}
|
||||
|
||||
public void powerOff() {
|
||||
initialize();
|
||||
m_powerCycler.set(Value.kOff);
|
||||
}
|
||||
|
||||
public void powerOn() {
|
||||
initialize();
|
||||
m_powerCycler.set(Value.kForward);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,8 +83,7 @@ public abstract class MotorEncoderFixture<T extends SpeedController> implements
|
||||
m_counters[0] = new Counter(m_alphaSource);
|
||||
m_counters[1] = new Counter(m_betaSource);
|
||||
logger.fine("Creating the speed controller!");
|
||||
m_motor = giveSpeedController(); // CANJaguar throws an exception if it
|
||||
// doesn't get the message
|
||||
m_motor = giveSpeedController();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
@@ -27,7 +26,6 @@ import edu.wpi.first.wpilibj.Talon;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
import edu.wpi.first.wpilibj.filters.LinearDigitalFilter;
|
||||
import edu.wpi.first.wpilibj.fixtures.AnalogCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.DIOCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.FilterNoiseFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.FilterOutputFixture;
|
||||
@@ -63,14 +61,6 @@ public final class TestBench {
|
||||
public static final int kJaguarPDPChannel = 6;
|
||||
public static final int kVictorPDPChannel = 8;
|
||||
public static final int kTalonPDPChannel = 10;
|
||||
public static final int kCANJaguarPDPChannel = 5;
|
||||
|
||||
/* CAN ASSOICATED CHANNELS */
|
||||
public static final int kCANRelayPowerCycler = 1;
|
||||
public static final int kFakeJaguarPotentiometer = 1;
|
||||
public static final int kFakeJaguarForwardLimit = 20;
|
||||
public static final int kFakeJaguarReverseLimit = 21;
|
||||
public static final int kCANJaguarID = 2;
|
||||
|
||||
// THESE MUST BE IN INCREMENTING ORDER
|
||||
public static final int DIOCrossConnectB2 = 9;
|
||||
@@ -196,67 +186,6 @@ public final class TestBench {
|
||||
return jagPair;
|
||||
}
|
||||
|
||||
public class BaseCANMotorEncoderFixture extends CANMotorEncoderFixture {
|
||||
@Override
|
||||
protected CANJaguar giveSpeedController() {
|
||||
return new CANJaguar(kCANJaguarID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputA() {
|
||||
return new DigitalInput(18);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputB() {
|
||||
return new DigitalInput(19);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FakePotentiometerSource giveFakePotentiometerSource() {
|
||||
return new FakePotentiometerSource(kFakeJaguarPotentiometer, 360);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DigitalOutput giveFakeForwardLimit() {
|
||||
return new DigitalOutput(kFakeJaguarForwardLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DigitalOutput giveFakeReverseLimit() {
|
||||
return new DigitalOutput(kFakeJaguarReverseLimit);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture#givePowerCycleRelay
|
||||
* ()
|
||||
*/
|
||||
@Override
|
||||
protected Relay givePowerCycleRelay() {
|
||||
return new Relay(kCANRelayPowerCycler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPDPChannel() {
|
||||
return kCANJaguarPDPChannel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new set of objects representing a connected set of CANJaguar controlled Motors and
|
||||
* an encoder<br> Note: The CANJaguar is not freshly allocated because the CANJaguar lacks a
|
||||
* free() method.
|
||||
*
|
||||
* @return an existing CANJaguar and a freshly allocated Encoder
|
||||
*/
|
||||
public CANMotorEncoderFixture getCanJaguarPair() {
|
||||
CANMotorEncoderFixture canPair = new BaseCANMotorEncoderFixture();
|
||||
return canPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new set of two Servo's and a Gyroscope.
|
||||
*
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import edu.wpi.first.wpilibj.WpiLibJTestSuite;
|
||||
import edu.wpi.first.wpilibj.can.CANTestSuite;
|
||||
import edu.wpi.first.wpilibj.command.CommandTestSuite;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboardTestSuite;
|
||||
|
||||
@@ -38,8 +37,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboardTestSuite;
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
// These are listed on separate lines to prevent merge conflicts
|
||||
@SuiteClasses({WpiLibJTestSuite.class, CANTestSuite.class, CommandTestSuite.class,
|
||||
SmartDashboardTestSuite.class})
|
||||
@SuiteClasses({WpiLibJTestSuite.class, CommandTestSuite.class, SmartDashboardTestSuite.class})
|
||||
public class TestSuite extends AbstractTestSuite {
|
||||
static {
|
||||
// Sets up the logging output
|
||||
|
||||
Reference in New Issue
Block a user